r339803 - clang-format: Change Google style wrt. the formatting of empty messages.

2018-08-15 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Aug 15 12:07:55 2018
New Revision: 339803

URL: http://llvm.org/viewvc/llvm-project?rev=339803=rev
Log:
clang-format: Change Google style wrt. the formatting of empty messages.

Before:
  message Empty {
  }

After:
  message Empty {}

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=339803=339802=339803=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Aug 15 12:07:55 2018
@@ -819,7 +819,7 @@ FormatStyle getGoogleStyle(FormatStyle::
 GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single;
 GoogleStyle.JavaScriptWrapImports = false;
   } else if (Language == FormatStyle::LK_Proto) {
-GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=339803=339802=339803=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Wed Aug 15 12:07:55 2018
@@ -397,29 +397,25 @@ TEST_F(FormatTestProto, FormatsService)
 }
 
 TEST_F(FormatTestProto, ExtendingMessage) {
-  verifyFormat("extend .foo.Bar {\n"
-   "}");
+  verifyFormat("extend .foo.Bar {}");
 }
 
 TEST_F(FormatTestProto, FormatsImports) {
   verifyFormat("import \"a.proto\";\n"
"import \"b.proto\";\n"
"// comment\n"
-   "message A {\n"
-   "}");
+   "message A {}");
 
   verifyFormat("import public \"a.proto\";\n"
"import \"b.proto\";\n"
"// comment\n"
-   "message A {\n"
-   "}");
+   "message A {}");
 
   // Missing semicolons should not confuse clang-format.
   verifyFormat("import \"a.proto\"\n"
"import \"b.proto\"\n"
"// comment\n"
-   "message A {\n"
-   "}");
+   "message A {}");
 }
 
 TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {


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


r328201 - clang-format: Narrow down raw string literal line break exception.

2018-03-22 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Mar 22 07:43:54 2018
New Revision: 328201

URL: http://llvm.org/viewvc/llvm-project?rev=328201=rev
Log:
clang-format: Narrow down raw string literal line break exception.

For multiline raw string literals, we generally want to respect the
author's choice of linebreak before the 'R"(' as the rest of the raw
string might be aligned to it and we cannot (commonly) modify the
content.

For single-line raw string literals, this doesn't make any sense and so
we should just treat them as regular string literals in this regard.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=328201=328200=328201=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Mar 22 07:43:54 2018
@@ -2830,10 +2830,10 @@ bool TokenAnnotator::mustBreakBefore(con
   if (Style.BreakBeforeInheritanceComma && Right.is(TT_InheritanceComma))
 return true;
   if (Right.is(tok::string_literal) && Right.TokenText.startswith("R\""))
-// Raw string literals are special wrt. line breaks. The author has made a
-// deliberate choice and might have aligned the contents of the string
-// literal accordingly. Thus, we try keep existing line breaks.
-return Right.NewlinesBefore > 0;
+// Multiline raw string literals are special wrt. line breaks. The author
+// has made a deliberate choice and might have aligned the contents of the
+// string literal accordingly. Thus, we try keep existing line breaks.
+return Right.IsMultiline && Right.NewlinesBefore > 0;
   if ((Right.Previous->is(tok::l_brace) ||
(Right.Previous->is(tok::less) && Right.Previous->Previous &&
 Right.Previous->Previous->is(tok::equal))) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=328201=328200=328201=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 22 07:43:54 2018
@@ -8106,6 +8106,9 @@ TEST_F(FormatTest, CountsCharactersInMul
"multiline raw string literal xx\n"
")x\" + bb);",
getGoogleStyleWithColumns(20)));
+  EXPECT_EQ("fff(R\"(single line raw string)\" + bb);",
+format("fff(\n"
+   " R\"(single line raw string)\" + bb);"));
 }
 
 TEST_F(FormatTest, SkipsUnknownStringLiterals) {


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


r328200 - clang-format: Fix SpacesInParentheses with fully qualified names.

2018-03-22 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Mar 22 07:30:28 2018
New Revision: 328200

URL: http://llvm.org/viewvc/llvm-project?rev=328200=rev
Log:
clang-format: Fix SpacesInParentheses with fully qualified names.

When SpacesInParentheses is set to true clang-format does not add a
space before fully qualified names. For example:

  do_something(::globalVar );

Fix by Darby Payne. Thank you!

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=328200=328199=328200=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Mar 22 07:30:28 2018
@@ -2692,7 +2692,8 @@ bool TokenAnnotator::spaceRequiredBefore
 Style.Standard == FormatStyle::LS_Cpp03) ||
!(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
   tok::kw___super, TT_TemplateCloser,
-  TT_TemplateOpener));
+  TT_TemplateOpener)) ||
+   (Left.is(tok ::l_paren) && Style.SpacesInParentheses);
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
 return Style.SpacesInAngles;
   // Space before TT_StructuredBindingLSquare.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=328200=328199=328200=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 22 07:30:28 2018
@@ -8827,6 +8827,7 @@ TEST_F(FormatTest, ConfigurableSpacesInP
   FormatStyle Spaces = getLLVMStyle();
 
   Spaces.SpacesInParentheses = true;
+  verifyFormat("do_something( ::globalVar );", Spaces);
   verifyFormat("call( x, y, z );", Spaces);
   verifyFormat("call();", Spaces);
   verifyFormat("std::function callback;", Spaces);


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


r327255 - clang-format: Properly handle implicit string concatenation in text protos

2018-03-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Mar 12 03:32:18 2018
New Revision: 327255

URL: http://llvm.org/viewvc/llvm-project?rev=327255=rev
Log:
clang-format: Properly handle implicit string concatenation in text protos

Three issues to fix:
- char_constants weren't properly treated as string literals
- Prevening the break after "label: " does not make sense in concunction
  with AlwaysBreakBeforeMultilineStrings. It leads to situations where
  clang-format just cannot find a viable format (it must break and yet
  it must not break).
- AlwaysBreakBeforeMultilineStrings should not be on for LK_TextProto in
  Google style.

Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp
cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=327255=327254=327255=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Mar 12 03:32:18 2018
@@ -766,6 +766,7 @@ FormatStyle getGoogleStyle(FormatStyle::
 GoogleStyle.JavaScriptWrapImports = false;
   } else if (Language == FormatStyle::LK_Proto) {
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
+GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
 // This affects protocol buffer options specifications and text protos.

Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=327255=327254=327255=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Mon Mar 12 03:32:18 2018
@@ -691,7 +691,9 @@ void FormatTokenLexer::readRawToken(Form
 }
   }
 
-  if (Style.Language == FormatStyle::LK_JavaScript &&
+  if ((Style.Language == FormatStyle::LK_JavaScript ||
+   Style.Language == FormatStyle::LK_Proto ||
+   Style.Language == FormatStyle::LK_TextProto) &&
   Tok.is(tok::char_constant)) {
 Tok.Tok.setKind(tok::string_literal);
   }

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=327255=327254=327255=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Mar 12 03:32:18 2018
@@ -2912,7 +2912,7 @@ bool TokenAnnotator::canBreakBefore(cons
   if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
 if ((Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) &&
-Right.isStringLiteral())
+!Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral())
   return false;
 return true;
   }

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=327255=327254=327255=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Mon Mar 12 03:32:18 2018
@@ -158,9 +158,8 @@ TEST_F(FormatTestProto, MessageFieldAttr
"key: 'a'  //\n"
"  }\n"
"];");
-  verifyFormat("optional string test = 1 [default =\n"
-   "  \"test\"\n"
-   "  \"test\"];");
+  verifyFormat("optional string test = 1 [default = \"test\"\n"
+   "\"test\"];");
   verifyFormat("optional Aaaa  = 12 [\n"
"  (aaa) = ,\n"
"  (bb) = {\n"

Modified: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestTextProto.cpp?rev=327255=327254=327255=diff
==
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp Mon Mar 12 03:32:18 2018
@@ -143,6 +143,23 @@ TEST_F(FormatTestTextProto, AddsNewlines
"}");
 }
 
+TEST_F(FormatTestTextProto, ImplicitStringLiteralConcatenation) {
+  verifyFormat("field_a: 'a'\n"
+   " 'b'");
+  verifyFormat("field_a: \"a\"\n"
+   " \"b\"");
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  

r327253 - Don't re-format raw string literal contents when formatting is disable

2018-03-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Mar 12 03:11:30 2018
New Revision: 327253

URL: http://llvm.org/viewvc/llvm-project?rev=327253=rev
Log:
Don't re-format raw string literal contents when formatting is disable

Not entirely sure this is the best place to put this check, but it fixes
the immediate issue.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestRawStrings.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=327253=327252=327253=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Mar 12 03:11:30 2018
@@ -1480,7 +1480,7 @@ unsigned ContinuationIndenter::handleEnd
   // Compute the raw string style to use in case this is a raw string literal
   // that can be reformatted.
   auto RawStringStyle = getRawStringStyle(Current, State);
-  if (RawStringStyle) {
+  if (RawStringStyle && !Current.Finalized) {
 Penalty = reformatRawStringLiteral(Current, State, *RawStringStyle, 
DryRun);
   } else if (Current.IsMultiline && Current.isNot(TT_BlockComment)) {
 // Don't break multi-line tokens other than block comments and raw string

Modified: cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestRawStrings.cpp?rev=327253=327252=327253=diff
==
--- cfe/trunk/unittests/Format/FormatTestRawStrings.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestRawStrings.cpp Mon Mar 12 03:11:30 2018
@@ -164,6 +164,20 @@ t = R"pb(item:1)pb";)test",
getRawStringPbStyleWithColumns(40)));
 }
 
+TEST_F(FormatTestRawStrings, RespectsClangFormatOff) {
+  expect_eq(R"test(
+// clang-format off
+s = R"pb(item:  1)pb";
+// clang-format on
+t = R"pb(item: 1)pb";)test",
+format(R"test(
+// clang-format off
+s = R"pb(item:  1)pb";
+// clang-format on
+t = R"pb(item:  1)pb";)test",
+   getRawStringPbStyleWithColumns(40)));
+}
+
 TEST_F(FormatTestRawStrings, ReformatsShortRawStringsOnSingleLine) {
   expect_eq(
   R"test(P p = TP(R"pb()pb");)test",


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


r326024 - Remove unused variable. We should be warning-free.

2018-02-23 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Feb 23 22:57:47 2018
New Revision: 326024

URL: http://llvm.org/viewvc/llvm-project?rev=326024=rev
Log:
Remove unused variable. We should be warning-free.

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=326024=326023=326024=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Fri Feb 23 
22:57:47 2018
@@ -440,7 +440,7 @@ private:
 os << Sep;
 FR->getDecl()->getDeclName().print(os, PP);
 Sep = ".";
-  } else if (auto *CXXR = dyn_cast(*I)) {
+  } else if (isa(*I)) {
 continue; // Just keep going up to the base region.
   } else {
 llvm_unreachable("Previous check has missed an unexpected region");


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


r326023 - Make module use diagnostics refer to the top-level module

2018-02-23 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Feb 23 22:54:09 2018
New Revision: 326023

URL: http://llvm.org/viewvc/llvm-project?rev=326023=rev
Log:
Make module use diagnostics refer to the top-level module

All use declarations need to be directly placed in the top-level module
anyway, knowing the submodule doesn't really help. The header that has
the offending #include can easily be seen in the diagnostics source
location.

Review: https://reviews.llvm.org/D43673

Modified:
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/test/Modules/Inputs/declare-use/h.h

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=326023=326022=326023=diff
==
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Feb 23 22:54:09 2018
@@ -475,7 +475,7 @@ void ModuleMap::diagnoseHeaderInclusion(
   // We have found a module, but we don't use it.
   if (NotUsed) {
 Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
-<< RequestingModule->getFullModuleName() << Filename;
+<< RequestingModule->getTopLevelModule()->Name << Filename;
 return;
   }
 
@@ -486,7 +486,7 @@ void ModuleMap::diagnoseHeaderInclusion(
 
   if (LangOpts.ModulesStrictDeclUse) {
 Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
-<< RequestingModule->getFullModuleName() << Filename;
+<< RequestingModule->getTopLevelModule()->Name << Filename;
   } else if (RequestingModule && RequestingModuleIsModuleInterface &&
  LangOpts.isCompilingModule()) {
 // Do not diagnose when we are not compiling a module. 

Modified: cfe/trunk/test/Modules/Inputs/declare-use/h.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/declare-use/h.h?rev=326023=326022=326023=diff
==
--- cfe/trunk/test/Modules/Inputs/declare-use/h.h (original)
+++ cfe/trunk/test/Modules/Inputs/declare-use/h.h Fri Feb 23 22:54:09 2018
@@ -1,7 +1,7 @@
 #ifndef H_H
 #define H_H
 #include "c.h"
-#include "d.h" // expected-error {{does not depend on a module exporting}}
+#include "d.h" // expected-error {{module XH does not depend on a module 
exporting}}
 #include "h1.h"
 const int h1 = aux_h*c*7*d;
 #endif


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


r317901 - [clang-format] Handle leading comments in using declaration

2017-11-10 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Nov 10 09:11:18 2017
New Revision: 317901

URL: http://llvm.org/viewvc/llvm-project?rev=317901=rev
Log:
[clang-format] Handle leading comments in using declaration

This fixes clang-format internal assertion for the following code:

  /* override */ using std::string;

Patch by Igor Sugak. Thank you.

Modified:
cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp

Modified: cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp?rev=317901=317900=317901=diff
==
--- cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp (original)
+++ cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp Fri Nov 10 09:11:18 2017
@@ -172,15 +172,17 @@ std::pair UsingDeclarations;
   for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
+const auto *FirstTok = AnnotatedLines[I]->First;
 if (AnnotatedLines[I]->InPPDirective ||
-!AnnotatedLines[I]->startsWith(tok::kw_using) ||
-AnnotatedLines[I]->First->Finalized) {
+!AnnotatedLines[I]->startsWith(tok::kw_using) || FirstTok->Finalized) {
   endUsingDeclarationBlock(, SourceMgr, );
   continue;
 }
-if (AnnotatedLines[I]->First->NewlinesBefore > 1)
+if (FirstTok->NewlinesBefore > 1)
   endUsingDeclarationBlock(, SourceMgr, );
-std::string Label = computeUsingDeclarationLabel(AnnotatedLines[I]->First);
+const auto *UsingTok =
+FirstTok->is(tok::comment) ? FirstTok->getNextNonComment() : FirstTok;
+std::string Label = computeUsingDeclarationLabel(UsingTok);
 if (Label.empty()) {
   endUsingDeclarationBlock(, SourceMgr, );
   continue;

Modified: cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp?rev=317901=317900=317901=diff
==
--- cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp (original)
+++ cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp Fri Nov 10 
09:11:18 2017
@@ -348,6 +348,13 @@ TEST_F(UsingDeclarationsSorterTest, Sort
   {tooling::Range(19, 1)}));
 }
 
+TEST_F(UsingDeclarationsSorterTest, 
SortsUsingDeclarationsWithLeadingkComments) {
+  EXPECT_EQ("/* comment */ using a;\n"
+"/* comment */ using b;",
+sortUsingDeclarations("/* comment */ using b;\n"
+  "/* comment */ using a;"));
+}
+
 } // 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


r317473 - [clang-format] Handle unary operator overload with arguments and specifiers

2017-11-06 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Nov  6 04:11:51 2017
New Revision: 317473

URL: http://llvm.org/viewvc/llvm-project?rev=317473=rev
Log:
[clang-format] Handle unary operator overload with arguments and specifiers

Before:
  int operator++(int)noexcept;

After:
  int operator++(int) noexcept;

Patch by Igor Sugak. Thank you!

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=317473=317472=317473=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Nov  6 04:11:51 2017
@@ -696,7 +696,8 @@ private:
   CurrentToken->Type = TT_PointerOrReference;
 consumeToken();
 if (CurrentToken &&
-CurrentToken->Previous->isOneOf(TT_BinaryOperator, tok::comma))
+CurrentToken->Previous->isOneOf(TT_BinaryOperator, 
TT_UnaryOperator,
+tok::comma))
   CurrentToken->Previous->Type = TT_OverloadedOperator;
   }
   if (CurrentToken) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=317473=317472=317473=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Nov  6 04:11:51 2017
@@ -5591,6 +5591,7 @@ TEST_F(FormatTest, UnderstandsOverloaded
   verifyFormat("bool operator!=();");
   verifyFormat("int operator+();");
   verifyFormat("int operator++();");
+  verifyFormat("int operator++(int) volatile noexcept;");
   verifyFormat("bool operator,();");
   verifyFormat("bool operator();");
   verifyFormat("bool operator()();");


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


r315439 - Revert r314955: "Remove PendingBody mechanism for function and ObjC method deserialization."

2017-10-11 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Oct 11 00:47:54 2017
New Revision: 315439

URL: http://llvm.org/viewvc/llvm-project?rev=315439=rev
Log:
Revert r314955: "Remove PendingBody mechanism for function and ObjC method 
deserialization."

This is breaking a build of https://github.com/abseil/abseil-cpp and so
likely not really NFC. Also reverted subsequent r314956/7.

I'll forward reproduction instructions to Richard.

Removed:
cfe/trunk/test/Modules/merge-lambdas.cpp
Modified:
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=315439=315438=315439=diff
==
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Wed Oct 11 00:47:54 2017
@@ -559,9 +559,13 @@ private:
   /// declarations that have not yet been linked to their definitions.
   llvm::SmallPtrSet PendingDefinitions;
 
-  /// \brief Functions or methods that are known to already have a definition
-  /// (that might not yet be merged into the redeclaration chain).
-  llvm::SmallDenseMap FunctionDefinitions;
+  typedef llvm::MapVector,
+  SmallVector >
+PendingBodiesMap;
+
+  /// \brief Functions or methods that have bodies that will be attached.
+  PendingBodiesMap PendingBodies;
 
   /// \brief Definitions for which we have added merged definitions but not yet
   /// performed deduplication.
@@ -987,13 +991,25 @@ private:
   /// the last time we loaded information about this identifier.
   llvm::DenseMap IdentifierGeneration;
 
+  class InterestingDecl {
+Decl *D;
+bool DeclHasPendingBody;
+
+  public:
+InterestingDecl(Decl *D, bool HasBody)
+: D(D), DeclHasPendingBody(HasBody) {}
+Decl *getDecl() { return D; }
+/// Whether the declaration has a pending body.
+bool hasPendingBody() { return DeclHasPendingBody; }
+  };
+
   /// \brief Contains declarations and definitions that could be
   /// "interesting" to the ASTConsumer, when we get that AST consumer.
   ///
   /// "Interesting" declarations are those that have data that may
   /// need to be emitted, such as inline function definitions or
   /// Objective-C protocols.
-  std::deque PotentiallyInterestingDecls;
+  std::deque PotentiallyInterestingDecls;
 
   /// \brief The list of redeclaration chains that still need to be 
   /// reconstructed, and the local offset to the corresponding list

Modified: cfe/trunk/lib/Serialization/ASTCommon.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTCommon.cpp?rev=315439=315438=315439=diff
==
--- cfe/trunk/lib/Serialization/ASTCommon.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTCommon.cpp Wed Oct 11 00:47:54 2017
@@ -344,8 +344,8 @@ bool serialization::needsAnonymousDeclar
 return true;
   }
 
-  // Otherwise, we only care about anonymous class members / block-scope decls.
-  if (D->getDeclName() || D->getLexicalDeclContext()->isFileContext())
+  // Otherwise, we only care about anonymous class members.
+  if (D->getDeclName() || !isa(D->getLexicalDeclContext()))
 return false;
   return isa(D) || isa(D);
 }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=315439=315438=315439=diff
==
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Wed Oct 11 00:47:54 2017
@@ -9169,6 +9169,30 @@ void ASTReader::finishPendingActions() {
   }
   PendingDefinitions.clear();
 
+  // Load the bodies of any functions or methods we've encountered. We do
+  // this now (delayed) so that we can be sure that the declaration chains
+  // have been fully wired up (hasBody relies on this).
+  // FIXME: We shouldn't require complete redeclaration chains here.
+  for (PendingBodiesMap::iterator PB = PendingBodies.begin(),
+   PBEnd = PendingBodies.end();
+   PB != PBEnd; ++PB) {
+if (FunctionDecl *FD = dyn_cast(PB->first)) {
+  // FIXME: Check for =delete/=default?
+  // FIXME: Complain about ODR violations here?
+  const FunctionDecl *Defn = nullptr;
+  if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) {
+FD->setLazyBody(PB->second);
+  } else
+mergeDefinitionVisibility(const_cast(Defn), FD);
+  continue;
+}
+
+ObjCMethodDecl *MD = cast(PB->first);
+if (!getContext().getLangOpts().Modules || !MD->hasBody())
+  

r312897 - Revert r312830: "Reinstall the patch "Use EmitPointerWithAlignment to get alignment information of the pointer used in atomic expr"."

2017-09-11 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Sep 11 00:35:01 2017
New Revision: 312897

URL: http://llvm.org/viewvc/llvm-project?rev=312897=rev
Log:
Revert r312830: "Reinstall the patch "Use EmitPointerWithAlignment to get 
alignment information of the pointer used in atomic expr"."

This triggers llvm.org/PR31620 in several of our internal builds. I'll
forward reproduction instructions to the original author.

Removed:
cfe/trunk/test/CodeGenCXX/atomic-align.cpp
Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=312897=312896=312897=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Mon Sep 11 00:35:01 2017
@@ -745,20 +745,20 @@ RValue CodeGenFunction::EmitAtomicExpr(A
   QualType MemTy = AtomicTy;
   if (const AtomicType *AT = AtomicTy->getAs())
 MemTy = AT->getValueType();
-  llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
-
-  Address Val1 = Address::invalid();
-  Address Val2 = Address::invalid();
-  Address Dest = Address::invalid();
-  Address Ptr = EmitPointerWithAlignment(E->getPtr());
-
   CharUnits sizeChars, alignChars;
   std::tie(sizeChars, alignChars) = getContext().getTypeInfoInChars(AtomicTy);
   uint64_t Size = sizeChars.getQuantity();
   unsigned MaxInlineWidthInBits = getTarget().getMaxAtomicInlineWidth();
-  bool UseLibcall = ((Ptr.getAlignment() % sizeChars) != 0 ||
+  bool UseLibcall = (sizeChars != alignChars ||
  getContext().toBits(sizeChars) > MaxInlineWidthInBits);
 
+  llvm::Value *IsWeak = nullptr, *OrderFail = nullptr;
+
+  Address Val1 = Address::invalid();
+  Address Val2 = Address::invalid();
+  Address Dest = Address::invalid();
+  Address Ptr(EmitScalarExpr(E->getPtr()), alignChars);
+
   if (E->getOp() == AtomicExpr::AO__c11_atomic_init ||
   E->getOp() == AtomicExpr::AO__opencl_atomic_init) {
 LValue lvalue = MakeAddrLValue(Ptr, AtomicTy);

Removed: cfe/trunk/test/CodeGenCXX/atomic-align.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/atomic-align.cpp?rev=312896=auto
==
--- cfe/trunk/test/CodeGenCXX/atomic-align.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/atomic-align.cpp (removed)
@@ -1,30 +0,0 @@
-// RUN: %clang_cc1 %s -std=c++11 -emit-llvm -o - -triple=x86_64-linux-gnu | 
FileCheck %s
-
-struct AM {
-  int f1, f2;
-};
-alignas(8) AM m;
-AM load1() {
-  AM am;
-  // m is declared to align to 8bytes, so generate load atomic instead
-  // of libcall.
-  // CHECK-LABEL: @_Z5load1v
-  // CHECK: load atomic {{.*}} monotonic
-  __atomic_load(, , 0);
-  return am;
-}
-
-struct BM {
-  int f1;
-  alignas(8) AM f2;
-};
-BM bm;
-AM load2() {
-  AM am;
-  // BM::f2 is declared to align to 8bytes, so generate load atomic instead
-  // of libcall.
-  // CHECK-LABEL: @_Z5load2v
-  // CHECK: load atomic {{.*}} monotonic
-  __atomic_load(, , 0);
-  return am;
-}


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


Re: r312766 - Update for llvm change.

2017-09-08 Thread Daniel Jasper via cfe-commits
Hi Rafael,

could you write slightly more extensive commit messages? This really
doesn't say anything..

Thank you,
Daniel

On Fri, Sep 8, 2017 at 2:01 AM, Rafael Espindola via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rafael
> Date: Thu Sep  7 17:01:26 2017
> New Revision: 312766
>
> URL: http://llvm.org/viewvc/llvm-project?rev=312766=rev
> Log:
> Update for llvm change.
>
> Modified:
> cfe/trunk/tools/clang-format/ClangFormat.cpp
> cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp
>
> Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-
> format/ClangFormat.cpp?rev=312766=312765=312766=diff
> 
> ==
> --- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
> +++ cfe/trunk/tools/clang-format/ClangFormat.cpp Thu Sep  7 17:01:26 2017
> @@ -351,8 +351,10 @@ int main(int argc, const char **argv) {
>"together with s, the files are edited in-place. Otherwise,
> the\n"
>"result is written to the standard output.\n");
>
> -  if (Help)
> +  if (Help) {
>  cl::PrintHelpMessage();
> +return 0;
> +  }
>
>if (DumpConfig) {
>  llvm::Expected FormatStyle =
>
> Modified: cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-
> offload-bundler/ClangOffloadBundler.cpp?rev=312766=312765=312766&
> view=diff
> 
> ==
> --- cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp
> (original)
> +++ cfe/trunk/tools/clang-offload-bundler/ClangOffloadBundler.cpp Thu
> Sep  7 17:01:26 2017
> @@ -931,8 +931,10 @@ int main(int argc, const char **argv) {
>"one. The resulting file can also be unbundled into different files
> by \n"
>"this tool if -unbundle is provided.\n");
>
> -  if (Help)
> +  if (Help) {
>  cl::PrintHelpMessage();
> +return 0;
> +  }
>
>bool Error = false;
>if (Unbundle) {
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r312721 - [clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

2017-09-07 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Sep  7 06:45:41 2017
New Revision: 312721

URL: http://llvm.org/viewvc/llvm-project?rev=312721=rev
Log:
[clang-format] Fix documentation for AllowAllParametersOfDeclarationOnNextLine

The current description of AllowAllParametersOfDeclarationOnNextLine in
the Clang-Format Style Options guide suggests that it is possible to
format function declaration, which fits in a single line (what is not
supported in current clang-format version). Also the example was not
reproducible and mades no sense.

Patch by Lucja Mazur, thank you!

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=312721=312720=312721=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Sep  7 06:45:41 2017
@@ -271,15 +271,22 @@ the configuration (without a prefix: ``A
 int b = 2; // comment  bint b = 2; // comment about b
 
 **AllowAllParametersOfDeclarationOnNextLine** (``bool``)
-  Allow putting all parameters of a function declaration onto
+  If the function declaration doesn't fit on a line,
+  allow putting all parameters of a function declaration onto
   the next line even if ``BinPackParameters`` is ``false``.
 
   .. code-block:: c++
 
-true:   false:
-myFunction(foo, vs. myFunction(foo, bar, plop);
-   bar,
-   plop);
+true:
+void myFunction(
+int a, int b, int c, int d, int e);
+
+false:
+void myFunction(int a,
+int b,
+int c,
+int d,
+int e);
 
 **AllowShortBlocksOnASingleLine** (``bool``)
   Allows contracting simple braced statements to a single line.

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=312721=312720=312721=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Sep  7 06:45:41 2017
@@ -151,13 +151,20 @@ struct FormatStyle {
   /// \endcode
   bool AlignTrailingComments;
 
-  /// \brief Allow putting all parameters of a function declaration onto
+  /// \brief If the function declaration doesn't fit on a line,
+  /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
   /// \code
-  ///   true:   false:
-  ///   myFunction(foo, vs. myFunction(foo, bar, plop);
-  ///  bar,
-  ///  plop);
+  ///   true:
+  ///   void myFunction(
+  ///   int a, int b, int c, int d, int e);
+  ///
+  ///   false:
+  ///   void myFunction(int a,
+  ///   int b,
+  ///   int c,
+  ///   int d,
+  ///   int e);
   /// \endcode
   bool AllowAllParametersOfDeclarationOnNextLine;
 


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


r312484 - clang-format: Fix indentation of macros in include guards (after r312125).

2017-09-04 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Sep  4 06:33:52 2017
New Revision: 312484

URL: http://llvm.org/viewvc/llvm-project?rev=312484=rev
Log:
clang-format: Fix indentation of macros in include guards (after r312125).

Before:
  #ifndef A_H
  #define A_H

  #define A() \
  int i;\
  int j;

  #endif // A_H

After:
  #ifndef A_H
  #define A_H

  #define A() \
int i;\
int j;

  #endif // A_H

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=312484=312483=312484=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Sep  4 06:33:52 2017
@@ -742,12 +742,11 @@ void UnwrappedLineParser::parsePPEndIf()
   // preprocessor indent.
   unsigned TokenPosition = Tokens->getPosition();
   FormatToken *PeekNext = AllTokens[TokenPosition];
-  if (FoundIncludeGuardStart && PPBranchLevel == -1 && PeekNext->is(tok::eof)) 
{
-for (auto  : Lines) {
+  if (FoundIncludeGuardStart && PPBranchLevel == -1 && PeekNext->is(tok::eof) 
&&
+  Style.IndentPPDirectives != FormatStyle::PPDIS_None)
+for (auto  : Lines)
   if (Line.InPPDirective && Line.Level > 0)
 --Line.Level;
-}
-  }
 }
 
 void UnwrappedLineParser::parsePPDefine() {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=312484=312483=312484=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Sep  4 06:33:52 2017
@@ -2332,7 +2332,6 @@ TEST_F(FormatTest, IndentPreprocessorDir
"#define A 1\n"
"#endif",
Style);
-
   Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
   verifyFormat("#ifdef _WIN32\n"
"#  define A 0\n"
@@ -2493,6 +2492,15 @@ TEST_F(FormatTest, IndentPreprocessorDir
"#\tdefine A 1\n"
"#endif",
Style);
+
+  // Regression test: Multiline-macro inside include guards.
+  verifyFormat("#ifndef HEADER_H\n"
+   "#define HEADER_H\n"
+   "#define A()\\\n"
+   "  int i;   \\\n"
+   "  int j;\n"
+   "#endif // HEADER_H",
+   getLLVMStyleWithColumns(20));
 }
 
 TEST_F(FormatTest, FormatHashIfNotAtStartOfLine) {


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


r312437 - clang-format: Fix formatting of for loops with multiple increments.

2017-09-03 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sun Sep  3 01:56:24 2017
New Revision: 312437

URL: http://llvm.org/viewvc/llvm-project?rev=312437=rev
Log:
clang-format: Fix formatting of for loops with multiple increments.

This fixes llvm.org/PR34366.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=312437=312436=312437=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sun Sep  3 01:56:24 2017
@@ -1116,6 +1116,11 @@ private:
(!Line.MightBeFunctionDecl || Current.NestingLevel != 0)) {
   Contexts.back().FirstStartOfName = 
   Current.Type = TT_StartOfName;
+} else if (Current.is(tok::semi)) {
+  // Reset FirstStartOfName after finding a semicolon so that a for loop
+  // with multiple increment statements is not confused with a for loop
+  // having multiple variable declarations.
+  Contexts.back().FirstStartOfName = nullptr;
 } else if (Current.isOneOf(tok::kw_auto, tok::kw___auto_type)) {
   AutoFound = true;
 } else if (Current.is(tok::arrow) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=312437=312436=312437=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sun Sep  3 01:56:24 2017
@@ -657,6 +657,10 @@ TEST_F(FormatTest, FormatsForLoop) {
   " I != E;\n"
   " ++I) {\n}",
   NoBinPacking);
+
+  FormatStyle AlignLeft = getLLVMStyle();
+  AlignLeft.PointerAlignment = FormatStyle::PAS_Left;
+  verifyFormat("for (A* a = start; a < end; ++a, ++value) {\n}", AlignLeft);
 }
 
 TEST_F(FormatTest, RangeBasedForLoops) {


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


r311792 - [Format] Invert nestingAndIndentLevel pair in WhitespaceManager used for

2017-08-25 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Aug 25 12:14:53 2017
New Revision: 311792

URL: http://llvm.org/viewvc/llvm-project?rev=311792=rev
Log:
[Format] Invert nestingAndIndentLevel pair in WhitespaceManager used for
alignments

Indent should be compared before nesting level to determine if a token
is on the same scope as the one we align with. Because it was inverted,
clang-format sometimes tried to align tokens with tokens from outer
scopes, causing the assert(Shift >= 0) to fire.

This fixes bug #33507. Patch by Beren Minor, thank you!

Modified:
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/lib/Format/WhitespaceManager.h
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=311792=311791=311792=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp Fri Aug 25 12:14:53 2017
@@ -246,12 +246,12 @@ AlignTokenSequence(unsigned Start, unsig
 
   for (unsigned i = Start; i != End; ++i) {
 if (ScopeStack.size() != 0 &&
-Changes[i].nestingAndIndentLevel() <
-Changes[ScopeStack.back()].nestingAndIndentLevel())
+Changes[i].indentAndNestingLevel() <
+Changes[ScopeStack.back()].indentAndNestingLevel())
   ScopeStack.pop_back();
 
-if (i != Start && Changes[i].nestingAndIndentLevel() >
-  Changes[i - 1].nestingAndIndentLevel())
+if (i != Start && Changes[i].indentAndNestingLevel() >
+  Changes[i - 1].indentAndNestingLevel())
   ScopeStack.push_back(i);
 
 bool InsideNestedScope = ScopeStack.size() != 0;
@@ -327,8 +327,8 @@ static unsigned AlignTokens(const Format
 
   // Measure the scope level (i.e. depth of (), [], {}) of the first token, and
   // abort when we hit any token in a higher scope than the starting one.
-  auto NestingAndIndentLevel = StartAt < Changes.size()
-   ? Changes[StartAt].nestingAndIndentLevel()
+  auto IndentAndNestingLevel = StartAt < Changes.size()
+   ? Changes[StartAt].indentAndNestingLevel()
: std::pair(0, 0);
 
   // Keep track of the number of commas before the matching tokens, we will 
only
@@ -359,7 +359,7 @@ static unsigned AlignTokens(const Format
 
   unsigned i = StartAt;
   for (unsigned e = Changes.size(); i != e; ++i) {
-if (Changes[i].nestingAndIndentLevel() < NestingAndIndentLevel)
+if (Changes[i].indentAndNestingLevel() < IndentAndNestingLevel)
   break;
 
 if (Changes[i].NewlinesBefore != 0) {
@@ -375,7 +375,7 @@ static unsigned AlignTokens(const Format
 
 if (Changes[i].Tok->is(tok::comma)) {
   ++CommasBeforeMatch;
-} else if (Changes[i].nestingAndIndentLevel() > NestingAndIndentLevel) {
+} else if (Changes[i].indentAndNestingLevel() > IndentAndNestingLevel) {
   // Call AlignTokens recursively, skipping over this scope block.
   unsigned StoppedAt = AlignTokens(Style, Matches, Changes, i);
   i = StoppedAt - 1;

Modified: cfe/trunk/lib/Format/WhitespaceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.h?rev=311792=311791=311792=diff
==
--- cfe/trunk/lib/Format/WhitespaceManager.h (original)
+++ cfe/trunk/lib/Format/WhitespaceManager.h Fri Aug 25 12:14:53 2017
@@ -154,12 +154,11 @@ public:
 const Change *StartOfBlockComment;
 int IndentationOffset;
 
-// A combination of nesting level and indent level, which are used in
+// A combination of indent level and nesting level, which are used in
 // tandem to compute lexical scope, for the purposes of deciding
 // when to stop consecutive alignment runs.
-std::pair
-nestingAndIndentLevel() const {
-  return std::make_pair(Tok->NestingLevel, Tok->IndentLevel);
+std::pair indentAndNestingLevel() const {
+  return std::make_pair(Tok->IndentLevel, Tok->NestingLevel);
 }
   };
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=311792=311791=311792=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Aug 25 12:14:53 2017
@@ -8958,6 +8958,16 @@ TEST_F(FormatTest, AlignConsecutiveDecla
Alignment);
   Alignment.BinPackParameters = true;
   Alignment.ColumnLimit = 80;
+
+  // Bug 33507
+  Alignment.PointerAlignment = FormatStyle::PAS_Middle;
+  verifyFormat(
+  "auto found = range::find_if(vsProducts, [&](auto * aProduct) {\n"
+  "  static const 

r311070 - Fix undefined behavior that is caused by not always initializing a bool.

2017-08-17 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Aug 16 23:33:46 2017
New Revision: 311070

URL: http://llvm.org/viewvc/llvm-project?rev=311070=rev
Log:
Fix undefined behavior that is caused by not always initializing a bool.

The fix in r310994 is incomplete, as moveFromAndCancel can set the
pointer without initializing OldIsSpeculativelyEvaluating.

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=311070=311069=311070=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Aug 16 23:33:46 2017
@@ -984,6 +984,7 @@ namespace {
 void moveFromAndCancel(SpeculativeEvaluationRAII &) {
   Info = Other.Info;
   OldStatus = Other.OldStatus;
+  OldIsSpeculativelyEvaluating = Other.OldIsSpeculativelyEvaluating;
   Other.Info = nullptr;
 }
 


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


r306804 - Fix heap use after free introduced by r306769.

2017-06-30 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Jun 30 01:02:37 2017
New Revision: 306804

URL: http://llvm.org/viewvc/llvm-project?rev=306804=rev
Log:
Fix heap use after free introduced by r306769.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=306804=306803=306804=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Jun 30 01:02:37 2017
@@ -1319,7 +1319,7 @@ void Clang::AddARMTargetArgs(const llvm:
   if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
 ABIName = A->getValue();
   else {
-StringRef CPU = getCPUName(Args, Triple, /*FromAs*/ false);
+std::string CPU = getCPUName(Args, Triple, /*FromAs*/ false);
 ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data();
   }
 


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


r305667 - clang-format: Improve understanding of combined typedef+record declarations

2017-06-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jun 19 02:45:41 2017
New Revision: 305667

URL: http://llvm.org/viewvc/llvm-project?rev=305667=rev
Log:
clang-format: Improve understanding of combined typedef+record declarations

Fixes an issue where struct A { int X; }; would be broken onto multiple
lines, but typedef struct A { int X; } A2; was collapsed onto a single
line.

Patch by Jacob Bandes-Storch. Thank you.

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

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=305667=305666=305667=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Mon Jun 19 02:45:41 2017
@@ -434,8 +434,11 @@ private:
 } else if (Limit != 0 && !Line.startsWith(tok::kw_namespace) &&
!startsExternCBlock(Line)) {
   // We don't merge short records.
-  if (Line.First->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
-  Keywords.kw_interface))
+  FormatToken *RecordTok =
+  Line.First->is(tok::kw_typedef) ? Line.First->Next : Line.First;
+  if (RecordTok &&
+  RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct,
+ Keywords.kw_interface))
 return 0;
 
   // Check that we still have three lines and they fit into the limit.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=305667=305666=305667=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 19 02:45:41 2017
@@ -458,6 +458,14 @@ TEST_F(FormatTest, FormatShortBracedStat
"}",
AllowSimpleBracedStatements);
 
+  verifyFormat("struct A2 {\n"
+   "  int X;\n"
+   "};",
+   AllowSimpleBracedStatements);
+  verifyFormat("typedef struct A2 {\n"
+   "  int X;\n"
+   "} A2_t;",
+   AllowSimpleBracedStatements);
   verifyFormat("template  struct A2 {\n"
"  struct B {};\n"
"};",


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


r305666 - clang-format: Handle "if constexpr".

2017-06-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jun 19 02:40:49 2017
New Revision: 305666

URL: http://llvm.org/viewvc/llvm-project?rev=305666=rev
Log:
clang-format: Handle "if constexpr".

c++1z adds the following constructions to the language:

  if constexpr (cond)
statement1;
  else if constexpr (cond)
statement2;
  else if constexpr (cond)
statement3;
  else
statement4;

A first version of this was proposed in reviews.llvm.org/D26953 by
Francis Visoiu Mistrih, but never commited. This patch additionally
fixes the behavior when allowing short if statements on a single line
and was authored by Jacob Bandes-Storch. Thank you to both authors.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=305666=305665=305666=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jun 19 02:40:49 2017
@@ -453,7 +453,8 @@ void ContinuationIndenter::addTokenOnCur
   State.Column += Spaces;
   if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
   Previous.Previous &&
-  Previous.Previous->isOneOf(tok::kw_if, tok::kw_for)) {
+  (Previous.Previous->isOneOf(tok::kw_if, tok::kw_for) ||
+   Previous.Previous->endsSequence(tok::kw_constexpr, tok::kw_if))) {
 // Treat the condition inside an if as if it was a second function
 // parameter, i.e. let nested calls have a continuation indent.
 State.Stack.back().LastSpace = State.Column;

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=305666=305665=305666=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 19 02:40:49 2017
@@ -145,6 +145,7 @@ private:
 (Left->Previous->isOneOf(tok::kw_static_assert, tok::kw_decltype,
  tok::kw_if, tok::kw_while, tok::l_paren,
  tok::comma) ||
+ Left->Previous->endsSequence(tok::kw_constexpr, tok::kw_if) ||
  Left->Previous->is(TT_BinaryOperator))) {
   // static_assert, if and while usually contain expressions.
   Contexts.back().IsExpression = true;
@@ -572,6 +573,8 @@ private:
   break;
 case tok::kw_if:
 case tok::kw_while:
+  if (Tok->is(tok::kw_if) && CurrentToken && 
CurrentToken->is(tok::kw_constexpr))
+next();
   if (CurrentToken && CurrentToken->is(tok::l_paren)) {
 next();
 if (!parseParens(/*LookForDecls=*/true))
@@ -2060,7 +2063,8 @@ unsigned TokenAnnotator::splitPenalty(co
   Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign)
 return 100;
   if (Left.is(tok::l_paren) && Left.Previous &&
-  Left.Previous->isOneOf(tok::kw_if, tok::kw_for))
+  (Left.Previous->isOneOf(tok::kw_if, tok::kw_for)
+   || Left.Previous->endsSequence(tok::kw_constexpr, tok::kw_if)))
 return 1000;
   if (Left.is(tok::equal) && InFunctionDecl)
 return 110;
@@ -2211,6 +2215,7 @@ bool TokenAnnotator::spaceRequiredBetwee
 (Left.isOneOf(tok::kw_if, tok::pp_elif, tok::kw_for, tok::kw_while,
   tok::kw_switch, tok::kw_case, TT_ForEachMacro,
   TT_ObjCForIn) ||
+ Left.endsSequence(tok::kw_constexpr, tok::kw_if) ||
  (Left.isOneOf(tok::kw_try, Keywords.kw___except, tok::kw_catch,
tok::kw_new, tok::kw_delete) &&
   (!Left.Previous || Left.Previous->isNot(tok::period) ||

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=305666=305665=305666=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jun 19 02:40:49 2017
@@ -1516,6 +1516,8 @@ void UnwrappedLineParser::parseSquare()
 void UnwrappedLineParser::parseIfThenElse() {
   assert(FormatTok->Tok.is(tok::kw_if) && "'if' expected");
   nextToken();
+  if (FormatTok->Tok.is(tok::kw_constexpr))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   bool NeedsUnwrappedLine = false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=305666=305665=305666=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)

r305665 - clang-format: Add capability to format the diff on save in vim.

2017-06-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jun 19 02:30:04 2017
New Revision: 305665

URL: http://llvm.org/viewvc/llvm-project?rev=305665=rev
Log:
clang-format: Add capability to format the diff on save in vim.

With this patch, one can configure a BufWrite hook that will make the
clang-format integration compute a diff of the current buffer with the file
that's on disk and format all changed lines. This should create a
zero-overhead auto-format solution that doesn't require the file to
already be clang-format clean to avoid spurious diffs.

Review: https://reviews.llvm.org/D32429

Modified:
cfe/trunk/docs/ClangFormat.rst
cfe/trunk/tools/clang-format/clang-format.py

Modified: cfe/trunk/docs/ClangFormat.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormat.rst?rev=305665=305664=305665=diff
==
--- cfe/trunk/docs/ClangFormat.rst (original)
+++ cfe/trunk/docs/ClangFormat.rst Mon Jun 19 02:30:04 2017
@@ -120,6 +120,18 @@ entity.
 It operates on the current, potentially unsaved buffer and does not create
 or save any files. To revert a formatting, just undo.
 
+An alternative option is to format changes when saving a file and thus to
+have a zero-effort integration into the coding workflow. To do this, add this 
to
+your `.vimrc`:
+
+.. code-block:: vim
+
+  function! Formatonsave()
+let l:formatdiff = 1
+pyf ~/llvm/tools/clang/tools/clang-format/clang-format.py
+  endfunction
+  autocmd BufWritePre *.h,*.cc,*.cpp call Formatonsave()
+
 
 Emacs Integration
 =

Modified: cfe/trunk/tools/clang-format/clang-format.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=305665=305664=305665=diff
==
--- cfe/trunk/tools/clang-format/clang-format.py (original)
+++ cfe/trunk/tools/clang-format/clang-format.py Mon Jun 19 02:30:04 2017
@@ -63,8 +63,19 @@ def main():
   # Determine range to format.
   if vim.eval('exists("l:lines")') == '1':
 lines = vim.eval('l:lines')
+  elif vim.eval('exists("l:formatdiff")') == '1':
+with open(vim.current.buffer.name, 'r') as f:
+  ondisk = f.read().splitlines();
+sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer)
+lines = []
+for op in reversed(sequence.get_opcodes()):
+  if op[0] not in ['equal', 'delete']:
+lines += ['-lines', '%s:%s' % (op[3] + 1, op[4])]
+if lines == []:
+  return
   else:
-lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
+lines = ['-lines', '%s:%s' % (vim.current.range.start + 1,
+  vim.current.range.end + 1)]
 
   # Determine the cursor position.
   cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
@@ -82,7 +93,7 @@ def main():
   # Call formatter.
   command = [binary, '-style', style, '-cursor', str(cursor)]
   if lines != 'all':
-command.extend(['-lines', lines])
+command += lines
   if fallback_style:
 command.extend(['-fallback-style', fallback_style])
   if vim.current.buffer.name:


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


r305574 - Ignore return value in test.

2017-06-16 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Jun 16 14:29:20 2017
New Revision: 305574

URL: http://llvm.org/viewvc/llvm-project?rev=305574=rev
Log:
Ignore return value in test.

Modified:
cfe/trunk/test/Driver/m_and_mm.c

Modified: cfe/trunk/test/Driver/m_and_mm.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/m_and_mm.c?rev=305574=305573=305574=diff
==
--- cfe/trunk/test/Driver/m_and_mm.c (original)
+++ cfe/trunk/test/Driver/m_and_mm.c Fri Jun 16 14:29:20 2017
@@ -5,7 +5,7 @@
 // RUN: %clang -M -MM %s 2> %t
 // RUN: not grep "warning" %t
 
-// RUN: %clang -MMD -MD %s 2> %t
+// RUN: %clang -MMD -MD %s 2> %t || true
 // RUN: grep "warning" %t
 
 #warning "This warning shouldn't show up with -M and -MM"


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


r305456 - Revert "Define _GNU_SOURCE for rtems c++"

2017-06-15 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Jun 15 04:17:12 2017
New Revision: 305456

URL: http://llvm.org/viewvc/llvm-project?rev=305456=rev
Log:
Revert "Define _GNU_SOURCE for rtems c++"

This reverts commit r305399.

This breaks a build in libcxx:
libcxx/src/system_error.cpp:90:16: error: assigning to 'int' from incompatible 
type 'char *'
if ((ret = ::strerror_r(ev, buffer, strerror_buff_size)) != 0) {
   ^~~~
1 error generated.

Which makes sense according to:
https://linux.die.net/man/3/strerror_r

Not entirely sure how this needs to be fixed.

Modified:
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/test/Preprocessor/init.c

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=305456=305455=305456=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Jun 15 04:17:12 2017
@@ -4734,9 +4734,6 @@ protected:
 
 Builder.defineMacro("__rtems__");
 Builder.defineMacro("__ELF__");
-// Required by the libc++ locale support.
-if (Opts.CPlusPlus)
-  Builder.defineMacro("_GNU_SOURCE");
   }
 
 public:

Modified: cfe/trunk/test/Preprocessor/init.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/init.c?rev=305456=305455=305456=diff
==
--- cfe/trunk/test/Preprocessor/init.c (original)
+++ cfe/trunk/test/Preprocessor/init.c Thu Jun 15 04:17:12 2017
@@ -8779,7 +8779,6 @@
 // KFREEBSDI686-DEFINE:#define __GLIBC__ 1
 //
 // RUN: %clang_cc1 -x c++ -triple i686-pc-linux-gnu -fobjc-runtime=gcc -E -dM 
< /dev/null | FileCheck -match-full-lines -check-prefix GNUSOURCE %s
-// RUN: %clang_cc1 -x c++ -triple sparc-rtems-elf -E -dM < /dev/null | 
FileCheck -match-full-lines -check-prefix GNUSOURCE %s
 // GNUSOURCE:#define _GNU_SOURCE 1
 //
 // RUN: %clang_cc1 -x c++ -std=c++98 -fno-rtti -E -dM < /dev/null | FileCheck 
-match-full-lines -check-prefix NORTTI %s


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


r305182 - Revert r305164/5/7.

2017-06-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jun 12 03:08:18 2017
New Revision: 305182

URL: http://llvm.org/viewvc/llvm-project?rev=305182=rev
Log:
Revert r305164/5/7.

cc1as does not currently access the "--" version of this flag. At the
very least this needs to be fixed and proper test cases need to be
added.

Simple reproducer:
clang -Wa,--compress-debug-sections /tmp/test.cc

Result:
error: unknown argument: '--compress-debug-sections'

Removed:
cfe/trunk/test/Driver/compress-noias.c
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/compress.c
cfe/trunk/test/Driver/nozlibcompress.c
cfe/trunk/tools/driver/cc1as_main.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=305182=305181=305182=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Jun 12 03:08:18 2017
@@ -134,6 +134,7 @@ def migrator_no_finalize_removal : Flag<
 
//===--===//
 
 let Flags = [CC1Option, CC1AsOption, NoDriverOption] in {
+
 def debug_info_kind_EQ : Joined<["-"], "debug-info-kind=">;
 def debug_info_macro : Flag<["-"], "debug-info-macro">,
   HelpText<"Emit macro debug information">;
@@ -143,16 +144,14 @@ def fdebug_compilation_dir : Separate<["
   HelpText<"The compilation directory to embed in the debug info.">;
 def dwarf_debug_flags : Separate<["-"], "dwarf-debug-flags">,
   HelpText<"The string to embed in the Dwarf debug flags record.">;
-def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
-HelpText<"DWARF debug sections compression">;
-def compress_debug_sections_EQ : Flag<["-"], "compress-debug-sections=">,
-HelpText<"DWARF debug sections compression type">;
 def mno_exec_stack : Flag<["-"], "mnoexecstack">,
   HelpText<"Mark the file as not needing an executable stack">;
 def massembler_fatal_warnings : Flag<["-"], "massembler-fatal-warnings">,
   HelpText<"Make assembler warnings fatal">;
 def mrelax_relocations : Flag<["--"], "mrelax-relocations">,
 HelpText<"Use relaxable elf relocations">;
+def compress_debug_sections : Flag<["-"], "compress-debug-sections">,
+HelpText<"Compress DWARF debug sections using zlib">;
 def msave_temp_labels : Flag<["-"], "msave-temp-labels">,
   HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics and shouldn't generally be used "

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=305182=305181=305182=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Jun 12 03:08:18 2017
@@ -1563,10 +1563,6 @@ def gdwarf_aranges : Flag<["-"], "gdwarf
 def gmodules : Flag <["-"], "gmodules">, Group,
   HelpText<"Generate debug info with external references to clang modules"
" or precompiled headers">;
-def gz : Flag<["-"], "gz">, Group,
-HelpText<"DWARF debug sections compression type">;
-def gz_EQ : Joined<["-"], "gz=">, Group,
-HelpText<"DWARF debug sections compression type">;
 def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names">;
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>,
   HelpText<"Display available options">;

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=305182=305181=305182=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Mon Jun 12 03:08:18 2017
@@ -910,37 +910,6 @@ static void RenderDebugEnablingArgs(cons
   }
 }
 
-static void RenderDebugInfoCompressionArgs(const ArgList ,
-   ArgStringList ,
-   const Driver ) {
-  const Arg *A = Args.getLastArg(options::OPT_gz, options::OPT_gz_EQ);
-  if (!A)
-return;
-
-  if (A->getOption().getID() == options::OPT_gz) {
-if (llvm::zlib::isAvailable())
-  CmdArgs.push_back("-compress-debug-sections");
-else
-  D.Diag(diag::warn_debug_compression_unavailable);
-return;
-  }
-
-  StringRef Value = A->getValue();
-  if (Value == "none") {
-CmdArgs.push_back("-compress-debug-sections=none");
-  } else if (Value == "zlib" || Value == "zlib-gnu") {
-if (llvm::zlib::isAvailable()) {
-  CmdArgs.push_back(
-  

r303037 - Revert r302965 - [modules] When creating a declaration, cache its owning

2017-05-15 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon May 15 02:51:10 2017
New Revision: 303037

URL: http://llvm.org/viewvc/llvm-project?rev=303037=rev
Log:
Revert r302965 - [modules] When creating a declaration, cache its owning
module immediately

Also revert dependent r302969. This is leading to crashes.
Will provide more details reproduction instructions to Richard.

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=303037=303036=303037=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon May 15 02:51:10 2017
@@ -301,6 +301,16 @@ public:
   using Decl::isModulePrivate;
   using Decl::setModulePrivate;
 
+  /// \brief Determine whether this declaration is hidden from name lookup.
+  bool isHidden() const { return Hidden; }
+
+  /// \brief Set whether this declaration is hidden from name lookup.
+  void setHidden(bool Hide) {
+assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
+   "declaration with no owning module can't be hidden");
+Hidden = Hide;
+  }
+
   /// \brief Determine whether this declaration is a C++ class member.
   bool isCXXClassMember() const {
 const DeclContext *DC = getDeclContext();

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=303037=303036=303037=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Mon May 15 02:51:10 2017
@@ -706,20 +706,6 @@ public:
 reinterpret_cast(this)[-1] = M;
   }
 
-  Module *getOwningModule() const {
-return isFromASTFile() ? getImportedOwningModule() : 
getLocalOwningModule();
-  }
-
-  /// \brief Determine whether this declaration is hidden from name lookup.
-  bool isHidden() const { return Hidden; }
-
-  /// \brief Set whether this declaration is hidden from name lookup.
-  void setHidden(bool Hide) {
-assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
-   "declaration with no owning module can't be hidden");
-Hidden = Hide;
-  }
-
   unsigned getIdentifierNamespace() const {
 return IdentifierNamespace;
   }

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=303037=303036=303037=diff
==
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Mon May 15 02:51:10 2017
@@ -166,11 +166,6 @@ public:
 return getCompilingModule() != CMK_None;
   }
 
-  /// Do we need to track the owning module for a local declaration?
-  bool trackLocalOwningModule() const {
-return ModulesLocalVisibility;
-  }
-
   bool isSignedOverflowDefined() const {
 return getSignedOverflowBehavior() == SOB_Defined;
   }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=303037=303036=303037=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon May 15 02:51:10 2017
@@ -1463,9 +1463,11 @@ private:
 
   VisibleModuleSet VisibleModules;
 
+  Module *CachedFakeTopLevelModule;
+
 public:
   /// \brief Get the module owning an entity.
-  Module *getOwningModule(Decl *Entity) { return Entity->getOwningModule(); }
+  Module *getOwningModule(Decl *Entity);
 
   /// \brief Make a merged definition of an existing hidden definition \p ND
   /// visible at the specified location.

Modified: cfe/trunk/lib/AST/ASTDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=303037=303036=303037=diff
==
--- cfe/trunk/lib/AST/ASTDumper.cpp (original)
+++ cfe/trunk/lib/AST/ASTDumper.cpp Mon May 15 02:51:10 2017
@@ -1038,10 +1038,10 @@ void ASTDumper::dumpDecl(const Decl *D)
 dumpSourceRange(D->getSourceRange());
 OS << ' ';
 dumpLocation(D->getLocation());
-if (D->isFromASTFile())
-  OS << " imported";
-if (Module *M = D->getOwningModule())
+if (Module *M = D->getImportedOwningModule())
   OS << " in " << M->getFullModuleName();
+else if (Module *M = D->getLocalOwningModule())
+  OS << 

Re: r302965 - [modules] When creating a declaration, cache its owning module immediately

2017-05-15 Thread Daniel Jasper via cfe-commits
This was leading to many crashers. Reverted in r303037.

On Sat, May 13, 2017 at 1:27 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Fri May 12 18:27:00 2017
> New Revision: 302965
>
> URL: http://llvm.org/viewvc/llvm-project?rev=302965=rev
> Log:
> [modules] When creating a declaration, cache its owning module immediately
> rather than waiting until it's queried.
>
> Currently this is only applied to local submodule visibility mode, as we
> don't
> yet allocate storage for the owning module in non-local-visibility modules
> compilations.
>
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/DeclBase.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/AST/ASTDumper.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/DeclBase.cpp
> cfe/trunk/lib/Sema/Sema.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaLookup.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/Decl.h?rev=302965=302964=302965=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri May 12 18:27:00 2017
> @@ -301,16 +301,6 @@ public:
>using Decl::isModulePrivate;
>using Decl::setModulePrivate;
>
> -  /// \brief Determine whether this declaration is hidden from name
> lookup.
> -  bool isHidden() const { return Hidden; }
> -
> -  /// \brief Set whether this declaration is hidden from name lookup.
> -  void setHidden(bool Hide) {
> -assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
> -   "declaration with no owning module can't be hidden");
> -Hidden = Hide;
> -  }
> -
>/// \brief Determine whether this declaration is a C++ class member.
>bool isCXXClassMember() const {
>  const DeclContext *DC = getDeclContext();
>
> Modified: cfe/trunk/include/clang/AST/DeclBase.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/DeclBase.h?rev=302965=302964=302965=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
> +++ cfe/trunk/include/clang/AST/DeclBase.h Fri May 12 18:27:00 2017
> @@ -706,6 +706,20 @@ public:
>  reinterpret_cast(this)[-1] = M;
>}
>
> +  Module *getOwningModule() const {
> +return isFromASTFile() ? getImportedOwningModule() :
> getLocalOwningModule();
> +  }
> +
> +  /// \brief Determine whether this declaration is hidden from name
> lookup.
> +  bool isHidden() const { return Hidden; }
> +
> +  /// \brief Set whether this declaration is hidden from name lookup.
> +  void setHidden(bool Hide) {
> +assert((!Hide || isFromASTFile() || hasLocalOwningModuleStorage()) &&
> +   "declaration with no owning module can't be hidden");
> +Hidden = Hide;
> +  }
> +
>unsigned getIdentifierNamespace() const {
>  return IdentifierNamespace;
>}
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=302965=302964=302965=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Fri May 12 18:27:00 2017
> @@ -1463,11 +1463,9 @@ private:
>
>VisibleModuleSet VisibleModules;
>
> -  Module *CachedFakeTopLevelModule;
> -
>  public:
>/// \brief Get the module owning an entity.
> -  Module *getOwningModule(Decl *Entity);
> +  Module *getOwningModule(Decl *Entity) { return
> Entity->getOwningModule(); }
>
>/// \brief Make a merged definition of an existing hidden definition \p
> ND
>/// visible at the specified location.
>
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ASTDumper.cpp?rev=302965=302964=302965=diff
> 
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Fri May 12 18:27:00 2017
> @@ -1038,10 +1038,10 @@ void ASTDumper::dumpDecl(const Decl *D)
>  dumpSourceRange(D->getSourceRange());
>  OS << ' ';
>  dumpLocation(D->getLocation());
> -if (Module *M = D->getImportedOwningModule())
> +if (D->isFromASTFile())
> +  OS << " imported";
> +if (Module *M = D->getOwningModule())
>OS << " in " << M->getFullModuleName();
> -else if (Module *M = D->getLocalOwningModule())
> -  OS << " in (local) " << M->getFullModuleName();
>  if (auto *ND = dyn_cast(D))
>for (Module *M : D->getASTContext().getModulesWithMergedDefinition(
> const_cast(ND)))
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> 

r302428 - [clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding

2017-05-08 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon May  8 10:08:00 2017
New Revision: 302428

URL: http://llvm.org/viewvc/llvm-project?rev=302428=rev
Log:
[clang-format] Convert AlignEscapedNewlinesLeft to an enum, adding
DontAlign

This converts the clang-format option AlignEscapedNewlinesLeft from a
boolean to an enum, named AlignEscapedNewlines, with options Left (prev.
true), Right (prev. false), and a new option DontAlign.

When set to DontAlign, the backslashes are placed just after the last token in 
each line:
  #define EXAMPLE \
do { \
int x = a; \
int b; \
int dd; \
} while (0)

Patch by jtbandes. Thank you!

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Format/FormatTestSelective.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=302428=302427=302428=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Mon May  8 10:08:00 2017
@@ -209,23 +209,45 @@ the configuration (without a prefix: ``A
 float   b = 23;
 std::string ccc = 23;
 
-**AlignEscapedNewlinesLeft** (``bool``)
-  If ``true``, aligns escaped newlines as far left as possible.
-  Otherwise puts them into the right-most column.
+**AlignEscapedNewlines** (``EscapedNewlineAlignmentStyle``)
+  Options for aligning backslashes in escaped newlines.
 
-  .. code-block:: c++
+  Possible values:
+
+  * ``ENAS_DontAlign`` (in configuration: ``DontAlign``)
+Don't align escaped newlines.
+
+.. code-block:: c++
+
+  #define A \
+int ; \
+int b; \
+int dd;
+
+  * ``ENAS_Left`` (in configuration: ``Left``)
+Align escaped newlines as far left as possible.
+
+.. code-block:: c++
+
+  true:
+  #define A   \
+int ; \
+int b;\
+int dd;
+
+  false:
+
+  * ``ENAS_Right`` (in configuration: ``Right``)
+Align escaped newlines in the right-most column.
+
+.. code-block:: c++
+
+  #define A
  \
+int ;  
  \
+int b; 
  \
+int dd;
 
-true:
-#define A   \
-  int ; \
-  int b;\
-  int dd;
 
-false:
-#define A  
\
-  int ;
\
-  int b;   
\
-  int dd;
 
 **AlignOperands** (``bool``)
   If ``true``, horizontally align operands of binary and ternary
@@ -1525,7 +1547,7 @@ the configuration (without a prefix: ``A
 Use C++03-compatible syntax.
 
   * ``LS_Cpp11`` (in configuration: ``Cpp11``)
-Use features of C++11, C++14 and C++1z (e.g. ``A`` instead of 
+Use features of C++11, C++14 and C++1z (e.g. ``A`` instead of
 ``A``).
 
   * ``LS_Auto`` (in configuration: ``Auto``)

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=302428=302427=302428=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon May  8 10:08:00 2017
@@ -98,22 +98,39 @@ struct FormatStyle {
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
-  /// \brief If ``true``, aligns escaped newlines as far left as possible.
-  /// Otherwise puts them into the right-most column.
-  /// \code
-  ///   true:
-  ///   #define A   \
-  /// int ; \
-  /// int b;\
-  /// int dd;
-  ///
-  ///   false:
-  ///   #define A  
\
-  /// int ;
\
-  /// int b;   
\
-  /// int dd;
-  /// \endcode
-  bool AlignEscapedNewlinesLeft;
+  /// \brief Different styles for aligning escaped newlines.
+  enum EscapedNewlineAlignmentStyle {
+/// \brief Don't align escaped newlines.
+/// \code
+///   #define A \
+/// int ; \
+/// int b; \
+/// int dd;
+/// \endcode
+ENAS_DontAlign,
+/// \brief Align escaped newlines as far left as possible.
+/// \code
+///   true:
+///   #define A   \
+/// 

r302012 - Undo turning ExtBehavior into a bitfield.

2017-05-03 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed May  3 06:27:34 2017
New Revision: 302012

URL: http://llvm.org/viewvc/llvm-project?rev=302012=rev
Log:
Undo turning ExtBehavior into a bitfield.

This produces warnings that I can't explain in a GCC build:

In file included from ../tools/clang/include/clang/Lex/LexDiagnostic.h:13:0,
 from 
/usr/local/google/home/djasper/llvm/tools/clang/lib/Lex/PTHLexer.cpp:19:
../tools/clang/include/clang/Basic/Diagnostic.h:219:34: warning: 
‘clang::DiagnosticsEngine::DiagState::ExtBehavior’ is too small to hold all 
values of ‘enum class clang::diag::Severity’ [enabled by default]
 diag::Severity ExtBehavior : 4; // Map extensions to warnings or 
errors?
  ^

While I don't think this warning makes sense, I'd like to get this back to being
warning-free. This only seems to trigger for "enum class".

Reproducer:
https://godbolt.org/g/P2ekVd

Modified:
cfe/trunk/include/clang/Basic/Diagnostic.h

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=302012=302011=302012=diff
==
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed May  3 06:27:34 2017
@@ -216,7 +216,7 @@ private:
 unsigned WarningsAsErrors : 1;   // Treat warnings like errors.
 unsigned ErrorsAsFatal : 1;  // Treat errors like fatal errors.
 unsigned SuppressSystemWarnings : 1; // Suppress warnings in system 
headers.
-diag::Severity ExtBehavior : 4; // Map extensions to warnings or 
errors?
+diag::Severity ExtBehavior; // Map extensions to warnings or 
errors?
 
 DiagState()
 : IgnoreAllWarnings(false), EnableAllWarnings(false),


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


r302003 - Silences gcc's -Wnarrowing.

2017-05-03 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed May  3 02:48:27 2017
New Revision: 302003

URL: http://llvm.org/viewvc/llvm-project?rev=302003=rev
Log:
Silences gcc's -Wnarrowing.

I think this is a false positive in GCC's warning, but nonetheless, we
should try to be warning-free. Smaller reproducer (reproduces with GCC
6.3):
https://godbolt.org/g/cJuO2z

Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=302003=302002=302003=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Wed May  3 02:48:27 2017
@@ -2872,8 +2872,9 @@ void ASTWriter::WritePragmaDiagnosticMap
   [](const DiagnosticsEngine::DiagState *DS) -> unsigned {
 unsigned Result = (unsigned)DS->ExtBehavior;
 for (unsigned Val :
- {DS->IgnoreAllWarnings, DS->EnableAllWarnings, DS->WarningsAsErrors,
-  DS->ErrorsAsFatal, DS->SuppressSystemWarnings})
+ {(unsigned)DS->IgnoreAllWarnings, (unsigned)DS->EnableAllWarnings,
+  (unsigned)DS->WarningsAsErrors, (unsigned)DS->ErrorsAsFatal,
+  (unsigned)DS->SuppressSystemWarnings})
   Result = (Result << 1) | Val;
 return Result;
   };


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


r301963 - Revert r301822 (and dependent r301825), which tried to improve the

2017-05-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue May  2 14:21:42 2017
New Revision: 301963

URL: http://llvm.org/viewvc/llvm-project?rev=301963=rev
Log:
Revert r301822 (and dependent r301825), which tried to improve the
handling of constexprs with unknown bounds.

This triggers a corner case of the language where it's not yet clear
whether this should be an error:

  struct A {
static void *const a[];
static void *const b[];
  };
  constexpr void *A::a[] = {[0]};
  constexpr void *A::b[] = {[0]};

When discovering the initializer for A::a, the bounds of A::b aren't known yet.
It is unclear whether warning about errors should be deferred until the end of
the translation unit, possibly resolving errors that can be resolved. In
practice, the compiler can know the bounds of all arrays in this example.

Credits for reproducers and explanation go to Richard Smith. Richard, please
add more info in case my explanation is wrong.

Removed:
cfe/trunk/test/SemaCXX/constexpr-array-unknown-bound.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=301963=301962=301963=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Tue May  2 14:21:42 2017
@@ -154,14 +154,12 @@ def note_constexpr_baa_insufficient_alig
 def note_constexpr_baa_value_insufficient_alignment : Note<
   "value of the aligned pointer (%0) is not a multiple of the asserted %1 "
   "%plural{1:byte|:bytes}1">;
-def note_constexpr_array_unknown_bound_arithmetic : Note<
-  "cannot perform pointer arithmetic on pointer to array without constant 
bound">;
 
 def warn_integer_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,
   InGroup>;
 
-// This is a temporary diagnostic, and shall be removed once our
+// This is a temporary diagnostic, and shall be removed once our 
 // implementation is complete, and like the preceding constexpr notes belongs
 // in Sema.
 def note_unimplemented_constexpr_lambda_feature_ast : Note<

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=301963=301962=301963=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May  2 14:21:42 2017
@@ -148,8 +148,7 @@ namespace {
   static unsigned
   findMostDerivedSubobject(ASTContext , APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t , QualType , bool ,
-   bool ) {
+   uint64_t , QualType , bool ) 
{
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
@@ -158,34 +157,28 @@ namespace {
 Type = getType(Base);
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
-  if (auto AT = Ctx.getAsArrayType(Type)) {
+  if (Type->isArrayType()) {
+const ConstantArrayType *CAT =
+cast(Ctx.getAsArrayType(Type));
+Type = CAT->getElementType();
+ArraySize = CAT->getSize().getZExtValue();
 MostDerivedLength = I + 1;
 IsArray = true;
-if (auto CAT = Ctx.getAsConstantArrayType(Type))
-  ArraySize = CAT->getSize().getZExtValue();
-else {
-  ArraySize = 0;
-  IsUnsizedArray = true;
-}
-Type = AT->getElementType();
   } else if (Type->isAnyComplexType()) {
 const ComplexType *CT = Type->castAs();
 Type = CT->getElementType();
 ArraySize = 2;
 MostDerivedLength = I + 1;
 IsArray = true;
-IsUnsizedArray = false;
   } else if (const FieldDecl *FD = getAsField(Path[I])) {
 Type = FD->getType();
 ArraySize = 0;
 MostDerivedLength = I + 1;
 IsArray = false;
-IsUnsizedArray = false;
   } else {
 // Path[I] describes a base class.
 ArraySize = 0;
 IsArray = false;
-IsUnsizedArray = false;
   }
 }
 return MostDerivedLength;
@@ -207,9 +200,8 @@ namespace {
 /// Is this a pointer one past the end of an object?
 unsigned IsOnePastTheEnd : 1;
 
-/// Indicator of whether the most-derived object is an unsized array (e.g.
-/// of unknown bound).
-unsigned MostDerivedIsAnUnsizedArray : 1;
+/// Indicator of whether the first entry is an unsized array.
+unsigned FirstEntryIsAnUnsizedArray : 1;
 
 /// Indicator of whether the most-derived object is an array element.
 unsigned MostDerivedIsArrayElement : 1;
@@ 

Re: r301916 - Revert r301735 (and subsequent r301786).

2017-05-02 Thread Daniel Jasper via cfe-commits
I forgot the () in the lambda definition, this should be:

  ..
  auto l = [this] { auto l = []() EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
  ..

Doesn't change the fact that clang segfaults without this revert, though.

On Tue, May 2, 2017 at 2:38 PM, Daniel Jasper via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: djasper
> Date: Tue May  2 07:38:27 2017
> New Revision: 301916
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301916=rev
> Log:
> Revert r301735 (and subsequent r301786).
>
> It leads to clang crashing, e.g. on this short code fragment (added to
> test/SemaCXX/warn-thread-safety-parsing.cpp):
>
>   class SomeClass {
>   public:
> void foo() {
>   auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
> }
> Mutex mu_;
>   };
>
> Modified:
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=301916=301915=301916=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue May  2 07:38:27 2017
> @@ -901,35 +901,17 @@ static QualType adjustCVQualifiersForCXX
>// capturing lamdbda's call operator.
>//
>
> -  // Since the FunctionScopeInfo stack is representative of the lexical
> -  // nesting of the lambda expressions during initial parsing (and is the
> best
> -  // place for querying information about captures about lambdas that are
> -  // partially processed) and perhaps during instantiation of function
> templates
> -  // that contain lambda expressions that need to be transformed BUT not
> -  // necessarily during instantiation of a nested generic lambda's
> function call
> -  // operator (which might even be instantiated at the end of the TU) -
> at which
> -  // time the DeclContext tree is mature enough to query capture
> information
> -  // reliably - we use a two pronged approach to walk through all the
> lexically
> -  // enclosing lambda expressions:
> -  //
> -  //  1) Climb down the FunctionScopeInfo stack as long as each item
> represents
> -  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is
> lexically
> -  //  enclosed by the call-operator of the LSI below it on the stack
> (while
> -  //  tracking the enclosing DC for step 2 if needed).  Note the topmost
> LSI on
> -  //  the stack represents the innermost lambda.
> -  //
> -  //  2) Iterate out through the DeclContext chain (if it represents a
> lambda's
> -  //  call operator, and therefore must be a generic lambda's call
> operator,
> -  //  which is the only time an inconsistency between the LSI and the
> -  //  DeclContext should occur) querying closure types regarding capture
> -  //  information.
> +  // The issue is that we cannot rely entirely on the FunctionScopeInfo
> stack
> +  // since ScopeInfos are pushed on during parsing and treetransforming.
> But
> +  // since a generic lambda's call operator can be instantiated anywhere
> (even
> +  // end of the TU) we need to be able to examine its enclosing lambdas
> and so
> +  // we use the DeclContext to get a hold of the closure-class and query
> it for
> +  // capture information.  The reason we don't just resort to always
> using the
> +  // DeclContext chain is that it is only mature for lambda expressions
> +  // enclosing generic lambda's call operators that are being
> instantiated.
>
> -
> -  // 1) Climb down the function scope info stack.
>for (int I = FunctionScopes.size();
> -   I-- && isa(FunctionScopes[I]) &&
> -   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
> -   cast(FunctionScopes[I])->
> CallOperator);
> +   I-- && isa(FunctionScopes[I]);
> CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
>  CurLSI = cast(FunctionScopes[I]);
>
> @@ -945,17 +927,11 @@ static QualType adjustCVQualifiersForCXX
>return ASTCtx.getPointerType(ClassType);
>  }
>}
> -
> -  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which
> can
> -  // happen during instantiation of its nested generic lambda call
> operator)
> +  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
> +  // happen during instantiation of generic lambdas)
>if (isLambdaCallOperator(CurDC)) {
> -assert(CurLSI && "While computing 'this' capture-type for a generic "
> - "lambda, we must have a corresponding
> LambdaSc

r301916 - Revert r301735 (and subsequent r301786).

2017-05-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue May  2 07:38:27 2017
New Revision: 301916

URL: http://llvm.org/viewvc/llvm-project?rev=301916=rev
Log:
Revert r301735 (and subsequent r301786).

It leads to clang crashing, e.g. on this short code fragment (added to
test/SemaCXX/warn-thread-safety-parsing.cpp):

  class SomeClass {
  public:
void foo() {
  auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
}
Mutex mu_;
  };

Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=301916=301915=301916=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Tue May  2 07:38:27 2017
@@ -901,35 +901,17 @@ static QualType adjustCVQualifiersForCXX
   // capturing lamdbda's call operator.
   //
 
-  // Since the FunctionScopeInfo stack is representative of the lexical
-  // nesting of the lambda expressions during initial parsing (and is the best
-  // place for querying information about captures about lambdas that are
-  // partially processed) and perhaps during instantiation of function 
templates
-  // that contain lambda expressions that need to be transformed BUT not
-  // necessarily during instantiation of a nested generic lambda's function 
call
-  // operator (which might even be instantiated at the end of the TU) - at 
which
-  // time the DeclContext tree is mature enough to query capture information
-  // reliably - we use a two pronged approach to walk through all the lexically
-  // enclosing lambda expressions:
-  //
-  //  1) Climb down the FunctionScopeInfo stack as long as each item represents
-  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is 
lexically
-  //  enclosed by the call-operator of the LSI below it on the stack (while
-  //  tracking the enclosing DC for step 2 if needed).  Note the topmost LSI on
-  //  the stack represents the innermost lambda.
-  //
-  //  2) Iterate out through the DeclContext chain (if it represents a lambda's
-  //  call operator, and therefore must be a generic lambda's call operator,
-  //  which is the only time an inconsistency between the LSI and the
-  //  DeclContext should occur) querying closure types regarding capture
-  //  information.
+  // The issue is that we cannot rely entirely on the FunctionScopeInfo stack
+  // since ScopeInfos are pushed on during parsing and treetransforming. But
+  // since a generic lambda's call operator can be instantiated anywhere (even
+  // end of the TU) we need to be able to examine its enclosing lambdas and so
+  // we use the DeclContext to get a hold of the closure-class and query it for
+  // capture information.  The reason we don't just resort to always using the
+  // DeclContext chain is that it is only mature for lambda expressions
+  // enclosing generic lambda's call operators that are being instantiated.
 
-
-  // 1) Climb down the function scope info stack.
   for (int I = FunctionScopes.size();
-   I-- && isa(FunctionScopes[I]) &&
-   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
-   cast(FunctionScopes[I])->CallOperator);
+   I-- && isa(FunctionScopes[I]);
CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
 CurLSI = cast(FunctionScopes[I]);
 
@@ -945,17 +927,11 @@ static QualType adjustCVQualifiersForCXX
   return ASTCtx.getPointerType(ClassType);
 }
   }
-
-  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which can
-  // happen during instantiation of its nested generic lambda call operator)
+  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
+  // happen during instantiation of generic lambdas)
   if (isLambdaCallOperator(CurDC)) {
-assert(CurLSI && "While computing 'this' capture-type for a generic "
- "lambda, we must have a corresponding LambdaScopeInfo");
-assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator) &&
-   "While computing 'this' capture-type for a generic lambda, when we "
-   "run out of enclosing LSI's, yet the enclosing DC is a "
-   "lambda-call-operator we must be (i.e. Current LSI) in a generic "
-   "lambda call oeprator");
+assert(CurLSI);
+assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator));
 assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator));
 
 auto IsThisCaptured =

Modified: cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp?rev=301916=301915=301916=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp (original)
+++ 

Re: r301735 - Fix PR32831: 'this capture while instantiating generic lambda call operator specialization

2017-05-02 Thread Daniel Jasper via cfe-commits
I'll revert this as it makes the following snippet makes clang crash:

class SomeClass {
 public:
  void foo() {
auto l = [this] { auto l = [] EXCLUSIVE_LOCKS_REQUIRED(mu_) {}; };
  }
  Mutex mu_;
};

(e.g. this can be added to test/SemaCXX/warn-thread-safety-parsing.cpp)
>From a brief look at the backtrace, it seems like
CurLSI->Lambda->getDeclContext() fails.

On Fri, Apr 28, 2017 at 8:49 PM, Faisal Vali via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: faisalv
> Date: Fri Apr 28 22:49:17 2017
> New Revision: 301735
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301735=rev
> Log:
> Fix PR32831: 'this capture while instantiating generic lambda call
> operator specialization
>
> When computing the appropriate cv-qualifiers for the 'this' capture, we
> have to examine each enclosing lambda - but when using the
> FunctionScopeInfo stack we have to ensure that the lambda below (outer) is
> the decl-context of the closure-class of the current lambda.
>
> https://bugs.llvm.org/show_bug.cgi?id=32831
>
> Modified:
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
> SemaExprCXX.cpp?rev=301735=301734=301735=diff
> 
> ==
> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Apr 28 22:49:17 2017
> @@ -901,17 +901,35 @@ static QualType adjustCVQualifiersForCXX
>// capturing lamdbda's call operator.
>//
>
> -  // The issue is that we cannot rely entirely on the FunctionScopeInfo
> stack
> -  // since ScopeInfos are pushed on during parsing and treetransforming.
> But
> -  // since a generic lambda's call operator can be instantiated anywhere
> (even
> -  // end of the TU) we need to be able to examine its enclosing lambdas
> and so
> -  // we use the DeclContext to get a hold of the closure-class and query
> it for
> -  // capture information.  The reason we don't just resort to always
> using the
> -  // DeclContext chain is that it is only mature for lambda expressions
> -  // enclosing generic lambda's call operators that are being
> instantiated.
> +  // Since the FunctionScopeInfo stack is representative of the lexical
> +  // nesting of the lambda expressions during initial parsing (and is the
> best
> +  // place for querying information about captures about lambdas that are
> +  // partially processed) and perhaps during instantiation of function
> templates
> +  // that contain lambda expressions that need to be transformed BUT not
> +  // necessarily during instantiation of a nested generic lambda's
> function call
> +  // operator (which might even be instantiated at the end of the TU) -
> at which
> +  // time the DeclContext tree is mature enough to query capture
> information
> +  // reliably - we use a two pronged approach to walk through all the
> lexically
> +  // enclosing lambda expressions:
> +  //
> +  //  1) Climb down the FunctionScopeInfo stack as long as each item
> represents
> +  //  a Lambda (i.e. LambdaScopeInfo) AND each LSI's 'closure-type' is
> lexically
> +  //  enclosed by the call-operator of the LSI below it on the stack
> (while
> +  //  tracking the enclosing DC for step 2 if needed).  Note the topmost
> LSI on
> +  //  the stack represents the innermost lambda.
> +  //
> +  //  2) Iterate out through the DeclContext chain (if it represents a
> lambda's
> +  //  call operator, and therefore must be a generic lambda's call
> operator,
> +  //  which is the only time an inconsistency between the LSI and the
> +  //  DeclContext should occur) querying closure types regarding capture
> +  //  information.
>
> +
> +  // 1) Climb down the function scope info stack.
>for (int I = FunctionScopes.size();
> -   I-- && isa(FunctionScopes[I]);
> +   I-- && isa(FunctionScopes[I]) &&
> +   (!CurLSI || CurLSI->Lambda->getDeclContext() ==
> +   cast(FunctionScopes[I])->
> CallOperator);
> CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
>  CurLSI = cast(FunctionScopes[I]);
>
> @@ -927,11 +945,17 @@ static QualType adjustCVQualifiersForCXX
>return ASTCtx.getPointerType(ClassType);
>  }
>}
> -  // We've run out of ScopeInfos but check if CurDC is a lambda (which can
> -  // happen during instantiation of generic lambdas)
> +
> +  // 2) We've run out of ScopeInfos but check if CurDC is a lambda (which
> can
> +  // happen during instantiation of its nested generic lambda call
> operator)
>if (isLambdaCallOperator(CurDC)) {
> -assert(CurLSI);
> -assert(isGenericLambdaCallOperatorSpecialization(CurLSI->
> CallOperator));
> +assert(CurLSI && "While computing 'this' capture-type for a generic "
> + "lambda, we must have a corresponding
> LambdaScopeInfo");
> +

r301182 - clang-format: Fix bad corner case in formatting of function types.

2017-04-24 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Apr 24 09:28:49 2017
New Revision: 301182

URL: http://llvm.org/viewvc/llvm-project?rev=301182=rev
Log:
clang-format: Fix bad corner case in formatting of function types.

Before:
  std::function<
  LngTemplatedType*(
  LongType
  type)>
  function;

After:
  std::function<
  LngTemplatedType<
  SomeType>*(
  LongType type)>
  function;

clang-format generally avoids having lines like "SomeType>*(" as they
lead to parameter lists that don't belong together to be aligned. However, in
case it is better than the alternative, which can even be violating the column
limit.

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=301182=301181=301182=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Apr 24 09:28:49 2017
@@ -792,7 +792,8 @@ unsigned ContinuationIndenter::moveState
 if (Previous && Previous->is(tok::question))
   State.Stack.back().QuestionColumn = State.Column;
   }
-  if (!Current.opensScope() && !Current.closesScope())
+  if (!Current.opensScope() && !Current.closesScope() &&
+  !Current.is(TT_PointerOrReference))
 State.LowestLevelOnLine =
 std::min(State.LowestLevelOnLine, Current.NestingLevel);
   if (Current.isMemberAccess())

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=301182=301181=301182=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 24 09:28:49 2017
@@ -5221,6 +5221,12 @@ TEST_F(FormatTest, FormatsFunctionTypes)
   verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }");
   verifyFormat("int x = f()();");
   verifyFormat("returnsFunction(, )(param);");
+  verifyFormat("std::function<\n"
+   "LooongTemplatedType<\n"
+   "SomeType>*(\n"
+   "LongType type)>\n"
+   "function;",
+   getGoogleStyleWithColumns(40));
 }
 
 TEST_F(FormatTest, FormatsPointersToArrayTypes) {


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


r300661 - clang-format: Properly match parens of macro parameter lists.

2017-04-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Apr 19 01:06:38 2017
New Revision: 300661

URL: http://llvm.org/viewvc/llvm-project?rev=300661=rev
Log:
clang-format: Properly match parens of macro parameter lists.

No tests yet, but this will be tested by the upcoming:
https://reviews.llvm.org/D28462

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=300661=300660=300661=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr 19 01:06:38 2017
@@ -796,10 +796,11 @@ private:
 while (CurrentToken) {
   FormatToken *Tok = CurrentToken;
   next();
-  if (Tok->isOneOf(Keywords.kw___has_include,
-   Keywords.kw___has_include_next)) {
+  if (Tok->is(tok::l_paren))
+parseParens();
+  else if (Tok->isOneOf(Keywords.kw___has_include,
+   Keywords.kw___has_include_next))
 parseHasInclude();
-  }
 }
 return Type;
   }


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


r299214 - clang-format: Fix post-commit review comment of r299204, use Style.isCpp().

2017-03-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Mar 31 08:30:24 2017
New Revision: 299214

URL: http://llvm.org/viewvc/llvm-project?rev=299214=rev
Log:
clang-format: Fix post-commit review comment of r299204, use Style.isCpp().

Also, while at it, s/IsCpp/isCpp/ so that it follows LLVM style.

Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=299214=299213=299214=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Fri Mar 31 08:30:24 2017
@@ -963,7 +963,7 @@ struct FormatStyle {
 /// Should be used for TableGen code.
 LK_TableGen
   };
-  bool IsCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
+  bool isCpp() const { return Language == LK_Cpp || Language == LK_ObjC; }
 
   /// \brief Language, this format style is targeted at.
   LanguageKind Language;

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=299214=299213=299214=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Mar 31 08:30:24 2017
@@ -158,7 +158,7 @@ bool ContinuationIndenter::mustBreak(con
 return true;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
(Previous.is(TT_TemplateCloser) && Current.is(TT_StartOfName) &&
-Style.IsCpp() &&
+Style.isCpp() &&
 // FIXME: This is a temporary workaround for the case where 
clang-format
 // sets BreakBeforeParameter to avoid bin packing and this creates a
 // completely unnecessary line break after a template type that isn't
@@ -605,7 +605,7 @@ unsigned ContinuationIndenter::addTokenO
   // Any break on this level means that the parent level has been broken
   // and we need to avoid bin packing there.
   bool NestedBlockSpecialCase =
-  !Style.IsCpp() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
+  !Style.isCpp() && Current.is(tok::r_brace) && State.Stack.size() > 1 &&
   State.Stack[State.Stack.size() - 2].NestedBlockInlined;
   if (!NestedBlockSpecialCase)
 for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=299214=299213=299214=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Mar 31 08:30:24 2017
@@ -1671,7 +1671,7 @@ bool isDeletedHeader(llvm::StringRef Hea
 tooling::Replacements
 fixCppIncludeInsertions(StringRef Code, const tooling::Replacements ,
 const FormatStyle ) {
-  if (!Style.IsCpp())
+  if (!Style.isCpp())
 return Replaces;
 
   tooling::Replacements HeaderInsertions;
@@ -1895,7 +1895,7 @@ LangOptions getFormattingLangOpts(const
   LangOpts.CPlusPlus11 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.CPlusPlus14 = Style.Standard == FormatStyle::LS_Cpp03 ? 0 : 1;
   LangOpts.LineComment = 1;
-  bool AlternativeOperators = Style.IsCpp();
+  bool AlternativeOperators = Style.isCpp();
   LangOpts.CXXOperatorNames = AlternativeOperators ? 1 : 0;
   LangOpts.Bool = 1;
   LangOpts.ObjC1 = 1;

Modified: cfe/trunk/lib/Format/FormatTokenLexer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatTokenLexer.cpp?rev=299214=299213=299214=diff
==
--- cfe/trunk/lib/Format/FormatTokenLexer.cpp (original)
+++ cfe/trunk/lib/Format/FormatTokenLexer.cpp Fri Mar 31 08:30:24 2017
@@ -560,7 +560,7 @@ FormatToken *FormatTokenLexer::getNextTo
 Column = FormatTok->LastLineColumnWidth;
   }
 
-  if (Style.IsCpp()) {
+  if (Style.isCpp()) {
 if (!(Tokens.size() > 0 && Tokens.back()->Tok.getIdentifierInfo() &&
   Tokens.back()->Tok.getIdentifierInfo()->getPPKeywordID() ==
   tok::pp_define) &&

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=299214=299213=299214=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Mar 31 08:30:24 2017
@@ -311,13 +311,13 @@ private:
 // In C++, this can happen either in array of templates (foo[10])
 // or when array 

r299204 - clang-format: [JavaScript] Ignore QT keywords.

2017-03-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Mar 31 07:04:37 2017
New Revision: 299204

URL: http://llvm.org/viewvc/llvm-project?rev=299204=rev
Log:
clang-format: [JavaScript] Ignore QT keywords.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=299204=299203=299204=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Fri Mar 31 07:04:37 2017
@@ -916,7 +916,9 @@ void UnwrappedLineParser::parseStructura
 return;
   }
 }
-if (FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
+if ((Style.Language == FormatStyle::LK_Cpp ||
+ Style.Language == FormatStyle::LK_ObjC) &&
+FormatTok->isOneOf(Keywords.kw_signals, Keywords.kw_qsignals,
Keywords.kw_slots, Keywords.kw_qslots)) {
   nextToken();
   if (FormatTok->is(tok::colon)) {

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=299204=299203=299204=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Mar 31 07:04:37 2017
@@ -167,6 +167,8 @@ TEST_F(FormatTestJS, ReservedWordsMethod
 TEST_F(FormatTestJS, CppKeywords) {
   // Make sure we don't mess stuff up because of C++ keywords.
   verifyFormat("return operator && (aa);");
+  // .. or QT ones.
+  verifyFormat("slots: Slot[];");
 }
 
 TEST_F(FormatTestJS, ES6DestructuringAssignment) {


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


r298853 - Look through CXXBindTemporaryExprs when checking CXXFunctionCastExprs

2017-03-27 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Mar 27 11:29:41 2017
New Revision: 298853

URL: http://llvm.org/viewvc/llvm-project?rev=298853=rev
Log:
Look through CXXBindTemporaryExprs when checking CXXFunctionCastExprs
for unused values.

This fixes a regression caused by r298676, where constructor calls to
classes with non-trivial dtor were marked as unused if the first
argument is an initializer list. This is inconsistent (as the test
shows) and also warns on a reasonbly common code pattern where people
just call constructors to create and immediately destroy an object.

Modified:
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/warn-unused-value.cpp

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=298853=298852=298853=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Mar 27 11:29:41 2017
@@ -290,9 +290,15 @@ void Sema::DiagnoseUnusedExprResult(cons
   DiagID = diag::warn_unused_property_expr;
   } else if (const CXXFunctionalCastExpr *FC
= dyn_cast(E)) {
-if (isa(FC->getSubExpr()) ||
-isa(FC->getSubExpr()))
+const Expr *E = FC->getSubExpr();
+if (const CXXBindTemporaryExpr *TE = dyn_cast(E))
+  E = TE->getSubExpr();
+if (isa(E))
   return;
+if (const CXXConstructExpr *CE = dyn_cast(E))
+  if (const CXXRecordDecl *RD = CE->getType()->getAsCXXRecordDecl())
+if (!RD->getAttr())
+  return;
   }
   // Diagnose "(void*) blah" as a typo for "(void) blah".
   else if (const CStyleCastExpr *CE = dyn_cast(E)) {

Modified: cfe/trunk/test/SemaCXX/warn-unused-value.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unused-value.cpp?rev=298853=298852=298853=diff
==
--- cfe/trunk/test/SemaCXX/warn-unused-value.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unused-value.cpp Mon Mar 27 11:29:41 2017
@@ -59,11 +59,13 @@ struct Used {
   Used();
   Used(int);
   Used(int, int);
+  ~Used() {}
 };
 struct __attribute__((warn_unused)) Unused {
   Unused();
   Unused(int);
   Unused(int, int);
+  ~Unused() {}
 };
 void f() {
   Used();
@@ -72,6 +74,10 @@ void f() {
   Unused(); // expected-warning {{expression result unused}}
   Unused(1);// expected-warning {{expression result unused}}
   Unused(1, 1); // expected-warning {{expression result unused}}
+#if __cplusplus >= 201103L // C++11 or later
+  Used({});
+  Unused({}); // expected-warning {{expression result unused}}
+#endif
 }
 }
 


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


Re: r298676 - Fix handling of initialization from parenthesized initializer list.

2017-03-27 Thread Daniel Jasper via cfe-commits
-Wunused-value is always triggered if a constructor of an object with a
non-trivial destructor has an initializer list as first parameter. So in
the test, even "Used({});" triggers -Wunused-value. That seems inconsistent
(replacing the init list with something else silences the warning) and also
there is a code pattern where this is used to construct and immediately
destruct an object.

On Mon, Mar 27, 2017 at 3:49 PM, Richard Smith 
wrote:

> What is the effect on that testcase? (Sorry, heading to vacation and can't
> easily check.)
>
> On 27 Mar 2017 6:33 am, "Daniel Jasper"  wrote:
>
>> Hi Richard,
>>
>> this seems to have an unwanted side-effect on -Wunused-value (test case
>> attached). Could you take a look?
>>
>> Cheers,
>> Daniel
>>
>> On Fri, Mar 24, 2017 at 2:14 AM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> Author: rsmith
>>> Date: Thu Mar 23 20:14:25 2017
>>> New Revision: 298676
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=298676=rev
>>> Log:
>>> Fix handling of initialization from parenthesized initializer list.
>>>
>>> This change fixes a crash on initialization of a reference from ({})
>>> during
>>> template instantiation and incidentally improves diagnostics.
>>>
>>> This reverts a prior attempt to handle this in r286721. Instead, we
>>> teach the
>>> initialization code that initialization cannot be performed if a source
>>> type
>>> is required and the initializer is an initializer list (which is not an
>>> expression and does not have a type), and likewise for function-style
>>> cast
>>> expressions.
>>>
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/include/clang/Sema/Initialization.h
>>> cfe/trunk/include/clang/Sema/Sema.h
>>> cfe/trunk/lib/Sema/SemaDecl.cpp
>>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>>> cfe/trunk/lib/Sema/SemaInit.cpp
>>> cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp
>>> cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp
>>> cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp
>>> cfe/trunk/test/SemaCXX/type-convert-construct.cpp
>>>
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Basic/DiagnosticSemaKinds.td?rev=298676=298675=298676=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 23
>>> 20:14:25 2017
>>> @@ -1814,8 +1814,9 @@ def note_uninit_fixit_remove_cond : Note
>>>"remove the %select{'%1' if its condition|condition if it}0 "
>>>"is always %select{false|true}2">;
>>>  def err_init_incomplete_type : Error<"initialization of incomplete type
>>> %0">;
>>> -def err_list_init_in_parens : Error<"list-initializer for non-class
>>> type %0 "
>>> -  "must not be parenthesized">;
>>> +def err_list_init_in_parens : Error<
>>> +  "cannot initialize %select{non-class|reference}0 type %1 with a "
>>> +  "parenthesized initializer list">;
>>>
>>>  def warn_unsequenced_mod_mod : Warning<
>>>"multiple unsequenced modifications to %0">, InGroup;
>>> @@ -5865,8 +5866,8 @@ def err_builtin_func_cast_more_than_one_
>>>"function-style cast to a builtin type can only take one argument">;
>>>  def err_value_init_for_array_type : Error<
>>>"array types cannot be value-initialized">;
>>> -def err_value_init_for_function_type : Error<
>>> -  "function types cannot be value-initialized">;
>>> +def err_init_for_function_type : Error<
>>> +  "cannot create object of function type %0">;
>>>  def warn_format_nonliteral_noargs : Warning<
>>>"format string is not a string literal (potentially insecure)">,
>>>InGroup;
>>>
>>> Modified: cfe/trunk/include/clang/Sema/Initialization.h
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>>> Sema/Initialization.h?rev=298676=298675=298676=diff
>>> 
>>> ==
>>> --- cfe/trunk/include/clang/Sema/Initialization.h (original)
>>> +++ cfe/trunk/include/clang/Sema/Initialization.h Thu Mar 23 20:14:25
>>> 2017
>>> @@ -822,6 +822,8 @@ public:
>>>enum FailureKind {
>>>  /// \brief Too many initializers provided for a reference.
>>>  FK_TooManyInitsForReference,
>>> +/// \brief Reference initialized from a parenthesized initializer
>>> list.
>>> +FK_ParenthesizedListInitForReference,
>>>  /// \brief Array must be initialized with an initializer list.
>>>  FK_ArrayNeedsInitList,
>>>  /// \brief Array must be initialized with an initializer list or a
>>> @@ -866,6 +868,8 @@ public:
>>>  FK_ConversionFromPropertyFailed,
>>>  /// \brief Too many initializers for scalar
>>>  FK_TooManyInitsForScalar,
>>> +/// \brief Scalar initialized from a parenthesized 

Re: r298676 - Fix handling of initialization from parenthesized initializer list.

2017-03-27 Thread Daniel Jasper via cfe-commits
Hi Richard,

this seems to have an unwanted side-effect on -Wunused-value (test case
attached). Could you take a look?

Cheers,
Daniel

On Fri, Mar 24, 2017 at 2:14 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Thu Mar 23 20:14:25 2017
> New Revision: 298676
>
> URL: http://llvm.org/viewvc/llvm-project?rev=298676=rev
> Log:
> Fix handling of initialization from parenthesized initializer list.
>
> This change fixes a crash on initialization of a reference from ({}) during
> template instantiation and incidentally improves diagnostics.
>
> This reverts a prior attempt to handle this in r286721. Instead, we teach
> the
> initialization code that initialization cannot be performed if a source
> type
> is required and the initializer is an initializer list (which is not an
> expression and does not have a type), and likewise for function-style cast
> expressions.
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/Initialization.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/test/SemaCXX/cxx0x-initializer-constructor.cpp
> cfe/trunk/test/SemaCXX/cxx0x-initializer-references.cpp
> cfe/trunk/test/SemaCXX/cxx0x-initializer-scalars.cpp
> cfe/trunk/test/SemaCXX/type-convert-construct.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=298676=298675=298676=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar 23
> 20:14:25 2017
> @@ -1814,8 +1814,9 @@ def note_uninit_fixit_remove_cond : Note
>"remove the %select{'%1' if its condition|condition if it}0 "
>"is always %select{false|true}2">;
>  def err_init_incomplete_type : Error<"initialization of incomplete type
> %0">;
> -def err_list_init_in_parens : Error<"list-initializer for non-class type
> %0 "
> -  "must not be parenthesized">;
> +def err_list_init_in_parens : Error<
> +  "cannot initialize %select{non-class|reference}0 type %1 with a "
> +  "parenthesized initializer list">;
>
>  def warn_unsequenced_mod_mod : Warning<
>"multiple unsequenced modifications to %0">, InGroup;
> @@ -5865,8 +5866,8 @@ def err_builtin_func_cast_more_than_one_
>"function-style cast to a builtin type can only take one argument">;
>  def err_value_init_for_array_type : Error<
>"array types cannot be value-initialized">;
> -def err_value_init_for_function_type : Error<
> -  "function types cannot be value-initialized">;
> +def err_init_for_function_type : Error<
> +  "cannot create object of function type %0">;
>  def warn_format_nonliteral_noargs : Warning<
>"format string is not a string literal (potentially insecure)">,
>InGroup;
>
> Modified: cfe/trunk/include/clang/Sema/Initialization.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Initialization.h?rev=298676=298675=298676=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Initialization.h (original)
> +++ cfe/trunk/include/clang/Sema/Initialization.h Thu Mar 23 20:14:25 2017
> @@ -822,6 +822,8 @@ public:
>enum FailureKind {
>  /// \brief Too many initializers provided for a reference.
>  FK_TooManyInitsForReference,
> +/// \brief Reference initialized from a parenthesized initializer
> list.
> +FK_ParenthesizedListInitForReference,
>  /// \brief Array must be initialized with an initializer list.
>  FK_ArrayNeedsInitList,
>  /// \brief Array must be initialized with an initializer list or a
> @@ -866,6 +868,8 @@ public:
>  FK_ConversionFromPropertyFailed,
>  /// \brief Too many initializers for scalar
>  FK_TooManyInitsForScalar,
> +/// \brief Scalar initialized from a parenthesized initializer list.
> +FK_ParenthesizedListInitForScalar,
>  /// \brief Reference initialization from an initializer list
>  FK_ReferenceBindingToInitList,
>  /// \brief Initialization of some unused destination type with an
> @@ -892,7 +896,7 @@ public:
>  /// having its address taken.
>  FK_AddressOfUnaddressableFunction,
>  /// \brief List-copy-initialization chose an explicit constructor.
> -FK_ExplicitConstructor
> +FK_ExplicitConstructor,
>};
>
>  private:
>
> Modified: cfe/trunk/include/clang/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Sema.h?rev=298676=298675=298676=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Sema.h (original)
> +++ cfe/trunk/include/clang/Sema/Sema.h Thu Mar 

r297931 - clang-format: Fix bug in wrapping behavior of operators.

2017-03-16 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Mar 16 02:54:11 2017
New Revision: 297931

URL: http://llvm.org/viewvc/llvm-project?rev=297931=rev
Log:
clang-format: Fix bug in wrapping behavior of operators.

Before (even violating the column limit):
  auto Diag =
  diag()
  << (, a, 
aa);

After:
  auto Diag = diag() << (, a,
 aa);

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=297931=297930=297931=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Mar 16 02:54:11 2017
@@ -915,6 +915,7 @@ void ContinuationIndenter::moveStatePast
I != E; ++I) {
 ParenState NewParenState = State.Stack.back();
 NewParenState.ContainsLineBreak = false;
+NewParenState.LastOperatorWrapped = true;
 NewParenState.NoLineBreak =
 NewParenState.NoLineBreak || State.Stack.back().NoLineBreakInOperand;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=297931=297930=297931=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Mar 16 02:54:11 2017
@@ -4132,6 +4132,9 @@ TEST_F(FormatTest, AlignsPipes) {
   verifyFormat(
   "llvm::errs() << aa(\n"
   ", );");
+  verifyFormat(
+  "auto Diag = diag() << (, a,\n"
+  "   aa);");
 
   verifyFormat("llvm::outs() << \": \"\n"
" << 
.(aaa)->aa();");


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


r297696 - clang-format: Make it very slighly more expensive to wrap between "= {".

2017-03-13 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Mar 13 19:40:32 2017
New Revision: 297696

URL: http://llvm.org/viewvc/llvm-project?rev=297696=rev
Log:
clang-format: Make it very slighly more expensive to wrap between "= {".

This prevents unwanted fallout from r296664. Specifically in proto formatting,
this changed:
  optional Aaaa  = 12 [
(aaa) = ,
(bb) = {
  a: true,
  : true
}
  ];

Into:
  optional Aaaa  = 12 [
(aaa) = ,
(bb) =
{a: true, : true}
  ];

Which is considered less readable. Generally, it seems preferable to
format such dict literals as blocks rather than contract them to one
line.

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=297696=297695=297696=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Mar 13 19:40:32 2017
@@ -1976,7 +1976,7 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Right.is(TT_LambdaArrow))
 return 110;
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
-return 150;
+return 160;
   if (Left.is(TT_CastRParen))
 return 100;
   if (Left.is(tok::coloncolon) ||

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=297696=297695=297696=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Mon Mar 13 19:40:32 2017
@@ -138,6 +138,13 @@ TEST_F(FormatTestProto, MessageFieldAttr
   verifyFormat("optional string test = 1 [default =\n"
"  \"test\"\n"
"  \"test\"];");
+  verifyFormat("optional Aaaa  = 12 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {


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


r297268 - clang-format: Get slightly better at understanding */&.

2017-03-08 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  8 03:49:12 2017
New Revision: 297268

URL: http://llvm.org/viewvc/llvm-project?rev=297268=rev
Log:
clang-format: Get slightly better at understanding */&.

Before:
  void f() { MACRO(A * const a); }

After:
  void f() { MACRO(A *const a); }

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=297268=297267=297268=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar  8 03:49:12 2017
@@ -1302,7 +1302,8 @@ private:
   return TT_UnaryOperator;
 
 const FormatToken *NextToken = Tok.getNextNonComment();
-if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal) ||
+if (!NextToken ||
+NextToken->isOneOf(tok::arrow, tok::equal, tok::kw_const) ||
 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
   return TT_PointerOrReference;
 

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=297268=297267=297268=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar  8 03:49:12 2017
@@ -4965,6 +4965,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   verifyIndependentOfContext("MACRO(int *i);");
   verifyIndependentOfContext("MACRO(auto *a);");
   verifyIndependentOfContext("MACRO(const A *a);");
+  verifyIndependentOfContext("MACRO(A *const a);");
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
   verifyFormat("void f() { f(float{1}, a * a); }");
   // FIXME: Is there a way to make this work?


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


Re: r297034 - [clang-format] Add tests for ambiguous namespaces to the comment fixer

2017-03-06 Thread Daniel Jasper via cfe-commits
On Mon, Mar 6, 2017 at 6:29 PM, Krasimir Georgiev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: krasimir
> Date: Mon Mar  6 11:29:25 2017
> New Revision: 297034
>
> URL: http://llvm.org/viewvc/llvm-project?rev=297034=rev
> Log:
> [clang-format] Add tests for ambiguous namespaces to the comment fixer
>
> Modified:
> cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
>
> Modified: cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/
> NamespaceEndCommentsFixerTest.cpp?rev=297034=297033=297034=diff
> 
> ==
> --- cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp
> (original)
> +++ cfe/trunk/unittests/Format/NamespaceEndCommentsFixerTest.cpp Mon Mar
> 6 11:29:25 2017
> @@ -406,6 +406,86 @@ TEST_F(NamespaceEndCommentsFixerTest,
>  "#else\n"
>  "  int j;\n"
>  "#endif"));
> +  EXPECT_EQ("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"}",
> +fixNamespaceEndComments("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"}"));
>

I don't understand why we aren't adding "// namespace A" here. I mean I
don't think it matters much, but it seems weird to me.


> +  EXPECT_EQ("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"} // namespace A",
> +fixNamespaceEndComments("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"} // namespace A"));
>

I'd consider merging this test with the previous one. Might make it more
obvious what the difference is. But I am not sure.


> +  EXPECT_EQ("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"} // namespace B",
> +fixNamespaceEndComments("#if A\n"
> +"namespace A {\n"
> +"#else\n"
> +"namespace B {\n"
> +"#endif\n"
> +"int i;\n"
> +"int j;\n"
> +"} // namespace B"));
> +  EXPECT_EQ("namespace A\n"
> +"int i;\n"
> +"int j;\n"
> +"#if A\n"
> +"}\n"
> +"#else\n"
> +"}\n"
> +"#endif",
> +fixNamespaceEndComments("namespace A\n"
> +"int i;\n"
> +"int j;\n"
> +"#if A\n"
> +"}\n"
> +"#else\n"
> +"}\n"
> +"#endif"));
>

Similarly, I would have expected us to insert "//namespace A" here. Why
don't we. Is that related to the missing "{" after "namespace A"?


> +  EXPECT_EQ("namespace A\n"
> +"int i;\n"
> +"int j;\n"
> +"#if A\n"
> +"} // namespace A\n"
> +"#else\n"
> +"} // namespace A\n"
> +"#endif",
> +fixNamespaceEndComments("namespace A\n"
> +"int i;\n"
> +"int j;\n"
> +"#if A\n"
> +"} // namespace A\n"
> +"#else\n"
> +"} // namespace A\n"
> +"#endif"));
>  }
>
>  TEST_F(NamespaceEndCommentsFixerTest,
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

r296664 - clang-format: [JS] Properly format object literals with shorthands.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 13:47:28 2017
New Revision: 296664

URL: http://llvm.org/viewvc/llvm-project?rev=296664=rev
Log:
clang-format: [JS] Properly format object literals with shorthands.

Before:
  return {
a,
b: 'b', c,
  };

After:
  return {
a,
b: 'b',
c,
  };

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296664=296663=296664=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar  1 13:47:28 2017
@@ -1517,13 +1517,14 @@ private:
 return prec::Conditional;
   if (NextNonComment && NextNonComment->is(tok::colon) &&
   NextNonComment->is(TT_DictLiteral))
-return prec::Comma;
+return prec::Assignment;
+  if (Current->is(TT_JsComputedPropertyName))
+return prec::Assignment;
   if (Current->is(TT_LambdaArrow))
 return prec::Comma;
   if (Current->is(TT_JsFatArrow))
 return prec::Assignment;
-  if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName,
-   TT_JsComputedPropertyName) ||
+  if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName) ||
   (Current->is(tok::comment) && NextNonComment &&
NextNonComment->is(TT_SelectorName)))
 return 0;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=296664=296663=296664=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Mar  1 13:47:28 2017
@@ -278,6 +278,11 @@ TEST_F(FormatTestJS, ContainerLiterals)
"  aaa,\n"
"  aaa,\n"
"};");
+  verifyFormat("return {\n"
+   "  a,\n"
+   "  b: 'b',\n"
+   "  c,\n"
+   "};");
 }
 
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {


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


r296659 - clang-format: [JS/TS] Properly understand cast expressions.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 13:26:12 2017
New Revision: 296659

URL: http://llvm.org/viewvc/llvm-project?rev=296659=rev
Log:
clang-format: [JS/TS] Properly understand cast expressions.

Many things were wrong:
- We didn't always allow wrapping after "as", which can be necessary.
- We used to Undestand the identifier after "as" as a start of a name.
- We didn't properly parse the structure of the expression with "as"
  having the precedence of relational operators

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296659=296658=296659=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar  1 13:26:12 2017
@@ -1158,7 +1158,8 @@ private:
 if (Tok.isNot(tok::identifier) || !Tok.Previous)
   return false;
 
-if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, 
Keywords.kw_instanceof))
+if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof,
+  Keywords.kw_as))
   return false;
 if (Style.Language == FormatStyle::LK_JavaScript &&
 Tok.Previous->is(Keywords.kw_in))
@@ -1533,7 +1534,7 @@ private:
   Current->is(Keywords.kw_instanceof))
 return prec::Relational;
   if (Style.Language == FormatStyle::LK_JavaScript &&
-  Current->is(Keywords.kw_in))
+  Current->isOneOf(Keywords.kw_in, Keywords.kw_as))
 return prec::Relational;
   if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
 return Current->getPrecedence();
@@ -2531,6 +2532,8 @@ bool TokenAnnotator::canBreakBefore(cons
   return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_as))
   return false; // must not break before as in 'x as type' casts
+if (Left.is(Keywords.kw_as))
+  return true;
 if (Left.is(Keywords.kw_declare) &&
 Right.isOneOf(Keywords.kw_module, tok::kw_namespace,
   Keywords.kw_function, tok::kw_class, tok::kw_enum,

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=296659=296658=296659=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Mar  1 13:26:12 2017
@@ -1502,6 +1502,9 @@ TEST_F(FormatTestJS, CastSyntax) {
   verifyFormat("x = x as {a: string};");
   verifyFormat("x = x as (string);");
   verifyFormat("x = x! as (string);");
+  verifyFormat("var x = something.someFunction() as\n"
+   "something;",
+   getGoogleJSStyleWithColumns(40));
 }
 
 TEST_F(FormatTestJS, TypeArguments) {


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


r296608 - Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 05:10:11 2017
New Revision: 296608

URL: http://llvm.org/viewvc/llvm-project?rev=296608=rev
Log:
Fix r296605 so that stuff in #ifndef SWIG blocks is still formatted.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296608=296607=296608=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 05:10:11 2017
@@ -589,11 +589,12 @@ void UnwrappedLineParser::conditionalCom
 }
 
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
+  bool IfNDef = FormatTok->is(tok::pp_ifndef);
   nextToken();
   bool Unreachable = false;
   if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
 Unreachable = true;
-  if (IfDef && FormatTok->TokenText == "SWIG")
+  if (IfDef && !IfNDef && FormatTok->TokenText == "SWIG")
 Unreachable = true;
   conditionalCompilationStart(Unreachable);
   parsePPUnknown();

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=296608=296607=296608=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Mar  1 05:10:11 2017
@@ -1683,14 +1683,6 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"void f(  ) {  }\n"
"#endif\n"
"void g(  ) {  }\n"));
-  EXPECT_EQ("#ifdef SWIG\n"
-"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-"#endif\n"
-"void f() {}",
-format("#ifdef SWIG\n"
-   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
-   "#endif\n"
-   "void f(  ) {  }"));
   EXPECT_EQ("enum E {\n"
 "  One,\n"
 "  Two,\n"
@@ -1809,6 +1801,22 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"#endif\n"
"Five\n"
"};"));
+
+  // Ignore stuff in SWIG-blocks.
+  EXPECT_EQ("#ifdef SWIG\n"
+"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+"#endif\n"
+"void f() {}",
+format("#ifdef SWIG\n"
+   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+   "#endif\n"
+   "void f(  ) {  }"));
+  EXPECT_EQ("#ifndef SWIG\n"
+"void f() {}\n"
+"#endif",
+format("#ifndef SWIG\n"
+   "void f(  ) {   }\n"
+   "#endif"));
 }
 
 TEST_F(FormatTestComments, DontCrashOnBlockComments) {


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


r296605 - clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.

2017-03-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Mar  1 04:47:52 2017
New Revision: 296605

URL: http://llvm.org/viewvc/llvm-project?rev=296605=rev
Log:
clang-format: Ignore contents of #ifdef SWIG .. #endif blocks.

Those blocks are used if C++ code is SWIG-wrapped (see swig.org) and
usually do not contain C++ code. Also cleanup the implementation of for #if 0
and #if false a bit.

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTestComments.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=296605=296604=296605=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Mar  1 04:47:52 2017
@@ -590,12 +590,12 @@ void UnwrappedLineParser::conditionalCom
 
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
   nextToken();
-  bool IsLiteralFalse = (FormatTok->Tok.isLiteral() &&
- FormatTok->Tok.getLiteralData() != nullptr &&
- StringRef(FormatTok->Tok.getLiteralData(),
-   FormatTok->Tok.getLength()) == "0") ||
-FormatTok->Tok.is(tok::kw_false);
-  conditionalCompilationStart(!IfDef && IsLiteralFalse);
+  bool Unreachable = false;
+  if (!IfDef && (FormatTok->is(tok::kw_false) || FormatTok->TokenText == "0"))
+Unreachable = true;
+  if (IfDef && FormatTok->TokenText == "SWIG")
+Unreachable = true;
+  conditionalCompilationStart(Unreachable);
   parsePPUnknown();
 }
 

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=296605=296604=296605=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Mar  1 04:47:52 2017
@@ -1683,6 +1683,14 @@ TEST_F(FormatTestComments, IgnoresIf0Con
"void f(  ) {  }\n"
"#endif\n"
"void g(  ) {  }\n"));
+  EXPECT_EQ("#ifdef SWIG\n"
+"}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+"#endif\n"
+"void f() {}",
+format("#ifdef SWIG\n"
+   "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
+   "#endif\n"
+   "void f(  ) {  }"));
   EXPECT_EQ("enum E {\n"
 "  One,\n"
 "  Two,\n"


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


r296499 - clang-format: [Java] Fix bug in enum formatting.

2017-02-28 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Feb 28 12:28:15 2017
New Revision: 296499

URL: http://llvm.org/viewvc/llvm-project?rev=296499=rev
Log:
clang-format: [Java] Fix bug in enum formatting.

Before:
  public enum VeryLongEnum {
ENUM_WITH_MANY_PARAMETERS("aa",
  "bbb",
  "ccc")
,
SECOND_ENUM("a", "b", "c");

private VeryLongEnum(String a, String b, String c) {}
  }

After:
  public enum VeryLongEnum {
ENUM_WITH_MANY_PARAMETERS("aa",
  "bbb",
  "ccc") ,
SECOND_ENUM("a", "b", "c");

private VeryLongEnum(String a, String b, String c) {}
  }

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJava.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=296499=296498=296499=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb 28 12:28:15 2017
@@ -1083,7 +1083,8 @@ private:
   if (Current.MatchingParen && Current.Next &&
   !Current.Next->isBinaryOperator() &&
   !Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
- tok::period, tok::arrow, tok::coloncolon))
+ tok::comma, tok::period, tok::arrow,
+ tok::coloncolon))
 if (FormatToken *AfterParen = Current.MatchingParen->Next) {
   // Make sure this isn't the return type of an Obj-C block declaration
   if (AfterParen->Tok.isNot(tok::caret)) {

Modified: cfe/trunk/unittests/Format/FormatTestJava.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJava.cpp?rev=296499=296498=296499=diff
==
--- cfe/trunk/unittests/Format/FormatTestJava.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJava.cpp Tue Feb 28 12:28:15 2017
@@ -225,6 +225,13 @@ TEST_F(FormatTestJava, EnumDeclarations)
"}\n"
"  };\n"
"}");
+  verifyFormat("public enum VeryLongEnum {\n"
+   "  ENUM_WITH_MANY_PARAMETERS(\n"
+   "  \"a\", \"\", 
"
+   "\"\"),\n"
+   "  SECOND_ENUM(\"a\", \"b\", \"c\");\n"
+   "  private VeryLongEnum(String a, String b, String c) {}\n"
+   "}\n");
 }
 
 TEST_F(FormatTestJava, ArrayInitializers) {


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


r295663 - clang-format: [JS] Improve line-wrapping behavior of template strings.

2017-02-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Feb 20 08:51:16 2017
New Revision: 295663

URL: http://llvm.org/viewvc/llvm-project?rev=295663=rev
Log:
clang-format: [JS] Improve line-wrapping behavior of template strings.

Specifically, similar to other blocks, clang-format now wraps both
after "${" and before the corresponding "}", if the contained
expression spans multiple lines.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=295663=295662=295663=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Feb 20 08:51:16 2017
@@ -383,6 +383,8 @@ void ContinuationIndenter::addTokenOnCur
   Current.FakeLParens.size() > 0 &&
   Current.FakeLParens.back() > prec::Unknown)
 State.Stack.back().NoLineBreak = true;
+  if (Previous.is(TT_TemplateString) && Previous.opensScope())
+State.Stack.back().NoLineBreak = true;
 
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
@@ -398,7 +400,7 @@ void ContinuationIndenter::addTokenOnCur
 State.Stack.back().NoLineBreak = true;
   if (Current.isMemberAccess() && Previous.is(tok::r_paren) &&
   (Previous.MatchingParen &&
-   (Previous.TotalLength - Previous.MatchingParen->TotalLength > 10))) {
+   (Previous.TotalLength - Previous.MatchingParen->TotalLength > 10)))
 // If there is a function call with long parameters, break before trailing
 // calls. This prevents things like:
 //   EXPECT_CALL(SomeLongParameter).Times(
@@ -406,7 +408,6 @@ void ContinuationIndenter::addTokenOnCur
 // We don't want to do this for short parameters as they can just be
 // indexes.
 State.Stack.back().NoLineBreak = true;
-  }
 
   // Don't allow the RHS of an operator to be split over multiple lines unless
   // there is a line-break right after the operator.
@@ -618,7 +619,9 @@ unsigned ContinuationIndenter::addTokenO
   // If we break after { or the [ of an array initializer, we should also break
   // before the corresponding } or ].
   if (PreviousNonComment &&
-  (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)))
+  (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+   (PreviousNonComment->is(TT_TemplateString) &&
+PreviousNonComment->opensScope(
 State.Stack.back().BreakBeforeClosingBrace = true;
 
   if (State.Stack.back().AvoidBinPacking) {
@@ -666,6 +669,8 @@ unsigned ContinuationIndenter::getNewLin
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;
   }
+  if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
+return State.Stack[State.Stack.size() - 2].LastSpace;
   if (Current.is(tok::identifier) && Current.Next &&
   Current.Next->is(TT_DictLiteral))
 return State.Stack.back().Indent;
@@ -840,6 +845,11 @@ unsigned ContinuationIndenter::moveState
 
   moveStatePastFakeLParens(State, Newline);
   moveStatePastScopeCloser(State);
+  if (Current.is(TT_TemplateString) && Current.opensScope())
+State.Stack.back().LastSpace =
+(Current.IsMultiline ? Current.LastLineColumnWidth
+ : State.Column + Current.ColumnWidth) -
+strlen("${");
   moveStatePastScopeOpener(State, Newline);
   moveStatePastFakeRParens(State);
 

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=295663=295662=295663=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Mon Feb 20 08:51:16 2017
@@ -455,6 +455,8 @@ struct FormatToken {
   /// \brief Returns \c true if this tokens starts a block-type list, i.e. a
   /// list that should be indented with a block indent.
   bool opensBlockOrBlockTypeList(const FormatStyle ) const {
+if (is(TT_TemplateString) && opensScope())
+  return true;
 return is(TT_ArrayInitializerLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
@@ -463,6 +465,8 @@ struct FormatToken {
 
   /// \brief Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
+if (is(TT_TemplateString) && closesScope())
+  return true;
 return MatchingParen && MatchingParen->opensBlockOrBlockTypeList(Style);
   }
 

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 

r295659 - clang-format: Prevent weird line-wraps in complex lambda introducers

2017-02-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Feb 20 06:43:48 2017
New Revision: 295659

URL: http://llvm.org/viewvc/llvm-project?rev=295659=rev
Log:
clang-format: Prevent weird line-wraps in complex lambda introducers

Before:
  a.(
  [aaa]() -> ::std::
  unordered_set {
//
  });

After:
  a.(
  [aaa]()
  -> ::std::unordered_set<
  > {
//
  });

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=295659=295658=295659=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Feb 20 06:43:48 2017
@@ -810,6 +810,8 @@ unsigned ContinuationIndenter::moveState
   if (Current.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && Newline)
 State.Stack.back().NestedBlockIndent =
 State.Column + Current.ColumnWidth + 1;
+  if (Current.isOneOf(TT_LambdaLSquare, TT_LambdaArrow))
+State.Stack.back().LastSpace = State.Column;
 
   // Insert scopes created by fake parenthesis.
   const FormatToken *Previous = Current.getPreviousNonComment();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=295659=295658=295659=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 20 06:43:48 2017
@@ -9262,10 +9262,11 @@ TEST_F(FormatTest, FormatsLambdas) {
" << std::count_if(v.begin(), v.end(), [](int x) 
{\n"
"  return x == 2; // force break\n"
"});");
-  verifyFormat("return aa([=](\n"
-   "int ) {\n"
-   "  return aaa != aaa;\n"
-   "});",
+  verifyFormat("return aa(\n"
+   "[=](int ) {\n"
+   "  return aaa !=\n"
+   " aaa;\n"
+   "});",
getLLVMStyleWithColumns(60));
   verifyFormat("SomeFunction({[&] {\n"
"// comment\n"
@@ -9351,6 +9352,15 @@ TEST_F(FormatTest, FormatsLambdas) {
"#endif\n"
"  ;\n"
"};");
+
+  // Lambdas with complex multiline introducers.
+  verifyFormat(
+  "a.(\n"
+  "[aaa]()\n"
+  "-> ::std::unordered_set<\n"
+  "> {\n"
+  "  //\n"
+  "});");
 }
 
 TEST_F(FormatTest, FormatsBlocks) {


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


r295658 - clang-format: [JS/TS] Improve detection for array subscripts in types.

2017-02-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Feb 20 06:43:41 2017
New Revision: 295658

URL: http://llvm.org/viewvc/llvm-project?rev=295658=rev
Log:
clang-format: [JS/TS] Improve detection for array subscripts in types.

Before:
  var someValue = (v as [
  ]).someFunction(aa);

After:
  var someValue = (v as [])
  .someFunction(aa);

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=295658=295657=295658=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 20 06:43:41 2017
@@ -337,6 +337,9 @@ private:
  Contexts.back().ContextKind == tok::l_brace &&
  Parent->isOneOf(tok::l_brace, tok::comma)) {
 Left->Type = TT_JsComputedPropertyName;
+  } else if (CurrentToken->is(tok::r_square) && Parent &&
+ Parent->is(TT_TemplateCloser)) {
+Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  (!CppArrayTemplates && Parent &&
   Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, 
tok::at,

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=295658=295657=295658=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Feb 20 06:43:41 2017
@@ -1095,6 +1095,9 @@ TEST_F(FormatTestJS, TypeAnnotations) {
   verifyFormat("function someFunc(args: string[]):\n"
"{longReturnValue: string[]} {}",
getGoogleJSStyleWithColumns(60));
+  verifyFormat(
+  "var someValue = (v as [])\n"
+  ".someFunction(aa);");
 }
 
 TEST_F(FormatTestJS, UnionIntersectionTypes) {


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


r295437 - clang-format: Don't remove existing spaces between identifier and ::.

2017-02-17 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Feb 17 04:44:07 2017
New Revision: 295437

URL: http://llvm.org/viewvc/llvm-project?rev=295437=rev
Log:
clang-format: Don't remove existing spaces between identifier and ::.

This can lead to bad behavior with macros that are used to annotate
functions (e.g. ALWAYS_INLINE).

Before, this:
  ALWAYS_INLINE ::std::string getName() ...

was turned into:
  ALWAYS_INLINE::std::string getName() ...

If it turns out that clang-format is failing to clean up a lot of the
existing spaces now, we can add more analyses of the identifier. It
should not currently. Cases where clang-format breaks nested name
specifiers should be fine as clang-format wraps after the "::". Thus, a
line getting longer and then shorter again should lead to the same
original code.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=295437=295436=295437=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb 17 04:44:07 2017
@@ -2343,12 +2343,16 @@ bool TokenAnnotator::spaceRequiredBefore
   if (!Style.SpaceBeforeAssignmentOperators &&
   Right.getPrecedence() == prec::Assignment)
 return false;
+  if (Right.is(tok::coloncolon) && Left.is(tok::identifier))
+// Generally don't remove existing spaces between an identifier and "::".
+// The identifier might actually be a macro name such as ALWAYS_INLINE. If
+// this turns out to be too lenient, add analysis of the identifier itself.
+return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) && !Left.isOneOf(tok::l_brace, tok::comment))
 return (Left.is(TT_TemplateOpener) &&
 Style.Standard == FormatStyle::LS_Cpp03) ||
-   !(Left.isOneOf(tok::identifier, tok::l_paren, tok::r_paren,
-  tok::l_square) ||
- Left.isOneOf(TT_TemplateCloser, TT_TemplateOpener));
+   !(Left.isOneOf(tok::l_paren, tok::r_paren, tok::l_square,
+  TT_TemplateCloser, TT_TemplateOpener));
   if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser)))
 return Style.SpacesInAngles;
   if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=295437=295436=295437=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Feb 17 04:44:07 2017
@@ -139,6 +139,8 @@ TEST_F(FormatTest, NestedNameSpecifiers)
   verifyFormat("::ns::SomeFunction(::ns::SomeOtherFunction())");
   verifyFormat("static constexpr bool Bar = decltype(bar())::value;");
   verifyFormat("bool a = 2 < ::SomeFunction();");
+  verifyFormat("ALWAYS_INLINE ::std::string getName();");
+  verifyFormat("some::string getName();");
 }
 
 TEST_F(FormatTest, OnlyGeneratesNecessaryReplacements) {


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


r294358 - clang-format: Fix bad variable declaration detection.

2017-02-07 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Feb  7 15:38:16 2017
New Revision: 294358

URL: http://llvm.org/viewvc/llvm-project?rev=294358=rev
Log:
clang-format: Fix bad variable declaration detection.

Before:
  LongType
  variable(nullptr, [](A *a) {});

After:
  LongType
  variable(nullptr, [](A *a) {});

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294358=294357=294358=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Feb  7 15:38:16 2017
@@ -1707,7 +1707,7 @@ static bool isFunctionDeclarationName(co
 }
   }
 
-  // Check whether parameter list can be long to a function declaration.
+  // Check whether parameter list can belong to a function declaration.
   if (!Next || !Next->is(tok::l_paren) || !Next->MatchingParen)
 return false;
   // If the lines ends with "{", this is likely an function definition.
@@ -1721,6 +1721,10 @@ static bool isFunctionDeclarationName(co
 return true;
   for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+if (Tok->is(tok::l_paren) && Tok->MatchingParen) {
+  Tok = Tok->MatchingParen;
+  continue;
+}
 if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
 Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis))
   return true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=294358=294357=294358=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Feb  7 15:38:16 2017
@@ -6934,6 +6934,11 @@ TEST_F(FormatTest, BreaksLongVariableDec
"LngVariable({});");
   verifyFormat("LngType\n"
"LoongVariable([A 
a]);");
+
+  // Lambdas should not confuse the variable declaration heuristic.
+  verifyFormat("LongType\n"
+   "variable(nullptr, [](A *a) {});",
+   getLLVMStyleWithColumns(40));
 }
 
 TEST_F(FormatTest, BreaksLongDeclarations) {


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


r294179 - clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and AlignAfterOpenBracket

2017-02-06 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Feb  6 04:55:49 2017
New Revision: 294179

URL: http://llvm.org/viewvc/llvm-project?rev=294179=rev
Log:
clang-format: Fix bug with conflicting BreakBeforeBinaryOperations and 
AlignAfterOpenBracket

Fix for the formatting options combination of
BreakBeforeBinaryOperators: All, AlignAfterOpenBracket: AlwaysBreak not
handling long templates correctly. This patch allows a break after an
opening left parenthesis, TemplateOpener, or bracket when both options
are enabled.

Patch by Daphne Pfister, thank you!

Fixes llvm.org/PR30304.

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294179=294178=294179=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb  6 04:55:49 2017
@@ -2635,7 +2635,8 @@ bool TokenAnnotator::canBreakBefore(cons
tok::colon, tok::l_square, tok::at) ||
  (Left.is(tok::r_paren) &&
   Right.isOneOf(tok::identifier, tok::kw_const)) ||
- (Left.is(tok::l_paren) && !Right.is(tok::r_paren));
+ (Left.is(tok::l_paren) && !Right.is(tok::r_paren)) ||
+ (Left.is(TT_TemplateOpener) && !Right.is(TT_TemplateCloser));
 }
 
 void TokenAnnotator::printDebugInfo(const AnnotatedLine ) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=294179=294178=294179=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb  6 04:55:49 2017
@@ -6140,6 +6140,44 @@ TEST_F(FormatTest, WrapsTemplateDeclarat
"};");
 }
 
+TEST_F(FormatTest, WrapsTemplateParameters) {
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+  verifyFormat(
+  "template  struct q {};\n"
+  "extern q\n"
+  "y;",
+  Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  verifyFormat(
+  "template  struct r {};\n"
+  "extern r\n"
+  "y;",
+  Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
+  verifyFormat(
+  "template  struct s {};\n"
+  "extern s<\n"
+  "aa, aa, 
aa,\n"
+  "aa, aa, 
aa>\n"
+  "y;",
+  Style);
+  Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  verifyFormat(
+  "template  struct t {};\n"
+  "extern t<\n"
+  "aa, aa, 
aa,\n"
+  "aa, aa, 
aa>\n"
+  "y;",
+  Style);
+}
+
 TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
   verifyFormat(
   
"::\n"


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


r294009 - clang-format: [JS] Fix bugs in parsing and aligning template strings.

2017-02-03 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Feb  3 08:32:38 2017
New Revision: 294009

URL: http://llvm.org/viewvc/llvm-project?rev=294009=rev
Log:
clang-format: [JS] Fix bugs in parsing and aligning template strings.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=294009=294008=294009=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Feb  3 08:32:38 2017
@@ -837,8 +837,8 @@ unsigned ContinuationIndenter::moveState
   }
 
   moveStatePastFakeLParens(State, Newline);
-  moveStatePastScopeOpener(State, Newline);
   moveStatePastScopeCloser(State);
+  moveStatePastScopeOpener(State, Newline);
   moveStatePastFakeRParens(State);
 
   if (Current.isStringLiteral() && State.StartOfStringLiteral == 0)
@@ -1060,7 +1060,7 @@ void ContinuationIndenter::moveStatePast
   // If we encounter a closing ), ], } or >, we can remove a level from our
   // stacks.
   if (State.Stack.size() > 1 &&
-  (Current.isOneOf(tok::r_paren, tok::r_square) ||
+  (Current.isOneOf(tok::r_paren, tok::r_square, TT_TemplateString) ||
(Current.is(tok::r_brace) && State.NextToken != State.Line->First) ||
State.NextToken->is(TT_TemplateCloser)))
 State.Stack.pop_back();

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=294009=294008=294009=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb  3 08:32:38 2017
@@ -1445,7 +1445,9 @@ public:
 
   // At the end of the line or when an operator with higher precedence is
   // found, insert fake parenthesis and return.
-  if (!Current || (Current->closesScope() && Current->MatchingParen) ||
+  if (!Current ||
+  (Current->closesScope() &&
+   (Current->MatchingParen || Current->is(TT_TemplateString))) ||
   (CurrentPrecedence != -1 && CurrentPrecedence < Precedence) ||
   (CurrentPrecedence == prec::Conditional &&
Precedence == prec::Assignment && Current->is(tok::colon))) {

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=294009=294008=294009=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Feb  3 08:32:38 2017
@@ -1399,6 +1399,10 @@ TEST_F(FormatTestJS, TemplateStrings) {
" a:${aaa.a} `;",
"var f = `a:${aaa.  a} \n"
" a:${  aaa. a} `;");
+  verifyFormat("var x = someFunction(`${})`)  //\n"
+   ".oon();");
+  verifyFormat("var x = someFunction(`${}${a(  //\n"
+   "   a)})`);");
 }
 
 TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {


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


r293995 - clang-format: [Proto] Also supports implicit string literal concatenation

2017-02-03 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Fri Feb  3 02:29:02 2017
New Revision: 293995

URL: http://llvm.org/viewvc/llvm-project?rev=293995=rev
Log:
clang-format: [Proto] Also supports implicit string literal concatenation

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=293995=293994=293995=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb  3 02:29:02 2017
@@ -2391,7 +2391,8 @@ bool TokenAnnotator::mustBreakBefore(con
 Right.Next->is(tok::string_literal))
   return true;
   } else if (Style.Language == FormatStyle::LK_Cpp ||
- Style.Language == FormatStyle::LK_ObjC) {
+ Style.Language == FormatStyle::LK_ObjC ||
+ Style.Language == FormatStyle::LK_Proto) {
 if (Left.isStringLiteral() &&
 (Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral)))
   return true;

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=293995=293994=293995=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Fri Feb  3 02:29:02 2017
@@ -135,6 +135,9 @@ TEST_F(FormatTestProto, MessageFieldAttr
"key: 'a'  //\n"
"  }\n"
"];");
+  verifyFormat("optional string test = 1 [default =\n"
+   "  \"test\"\n"
+   "  \"test\"];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {


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


r293875 - clang-format: Do not use two-argument/operand special case with no alignment

2017-02-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Feb  2 02:30:21 2017
New Revision: 293875

URL: http://llvm.org/viewvc/llvm-project?rev=293875=rev
Log:
clang-format: Do not use two-argument/operand special case with no alignment

Without alignment, there is no clean separation between the arguments, even if
there are only two.

Before:
  aa(
  , a +
  aa);

After:
  aa(,
 aaa +
 aa);

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293875=293874=293875=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Feb  2 02:30:21 2017
@@ -429,7 +429,7 @@ void ContinuationIndenter::addTokenOnCur
 // does not help.
 bool HasTwoOperands =
 P->OperatorIndex == 0 && !P->NextOperator && 
!P->is(TT_ConditionalExpr);
-if ((!BreakBeforeOperator && !HasTwoOperands) ||
+if ((!BreakBeforeOperator && !(HasTwoOperands && Style.AlignOperands)) ||
 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
   State.Stack.back().NoLineBreakInOperand = true;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293875=293874=293875=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb  2 02:30:21 2017
@@ -4163,6 +4163,10 @@ TEST_F(FormatTest, EnforcedOperatorWraps
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;
+  verifyFormat("aa(,\n"
+   "   a +\n"
+   "   aa);",
+   Style);
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
   verifyFormat("bool value = a\n"
"+ a\n"


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


r293839 - clang-format: Fix incorrect line breaks after forced operator wraps.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 17:27:37 2017
New Revision: 293839

URL: http://llvm.org/viewvc/llvm-project?rev=293839=rev
Log:
clang-format: Fix incorrect line breaks after forced operator wraps.

Before:
  bool x = a //
   ||
   b
   //
   || ;

After:
  bool x = a //
   || b
   //
   || ;

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293839=293838=293839=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Feb  1 17:27:37 2017
@@ -420,7 +420,7 @@ void ContinuationIndenter::addTokenOnCur
   P->getPrecedence() != prec::Assignment &&
   P->getPrecedence() != prec::Relational) {
 bool BreakBeforeOperator =
-P->is(tok::lessless) ||
+P->MustBreakBefore || P->is(tok::lessless) ||
 (P->is(TT_BinaryOperator) &&
  Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
 (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293839=293838=293839=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  1 17:27:37 2017
@@ -4151,6 +4151,15 @@ TEST_F(FormatTest, ExpressionIndentation
Style);
 }
 
+TEST_F(FormatTest, EnforcedOperatorWraps) {
+  // Here we'd like to wrap after the || operators, but a comment is forcing an
+  // earlier wrap.
+  verifyFormat("bool x = a //\n"
+   " || b\n"
+   " //\n"
+   " || ;");
+}
+
 TEST_F(FormatTest, NoOperandAlignment) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignOperands = false;


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


r293754 - Fix Index test after recent clang-format change.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 04:00:10 2017
New Revision: 293754

URL: http://llvm.org/viewvc/llvm-project?rev=293754=rev
Log:
Fix Index test after recent clang-format change.

Modified:
cfe/trunk/test/Index/overriding-ftemplate-comments.cpp

Modified: cfe/trunk/test/Index/overriding-ftemplate-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-ftemplate-comments.cpp?rev=293754=293753=293754=diff
==
--- cfe/trunk/test/Index/overriding-ftemplate-comments.cpp (original)
+++ cfe/trunk/test/Index/overriding-ftemplate-comments.cpp Wed Feb  1 04:00:10 
2017
@@ -77,10 +77,10 @@ void comment_to_html_conversion_21();
 template  class 
BBB > class AAA>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class C1,\n template class C2, template class C3, class C4 
class BBB\n  class AAA\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class C1, template class C2, template class C3, class C4 class 
BBB\n  class AAA\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
 
 template 
class QQQ> class PPP>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class CCC1,\n template class CCC2, template class CCC3, class 
CCC4 class QQQ\n class PPP\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class CCC1, template class CCC2, template class CCC3, class 
CCC4\n class QQQ class PPP\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
 


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


r293752 - clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.

2017-02-01 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Feb  1 03:23:39 2017
New Revision: 293752

URL: http://llvm.org/viewvc/llvm-project?rev=293752=rev
Log:
clang-format: Don't force-wrap multiline RHSs for 2-operand experssions.

This rows back on r288120, r291801 and r292110. I apologize in advance
for the churn. All of those revisions where meant to make the wrapping
of RHS expressions more consistent. However, now that they are
consistent, we seem to be a bit too eager.

The reasoning here is that I think it is generally correct that we want
to line-wrap before multiline RHS expressions (or multiline arguments to
a function call). However, if there are only two of such operands or
arguments, there is always a clear vertical separation between them and
the additional line break seems much less desirable.

Somewhat good examples are expressions like:

  EXPECT_EQ(2, someLongExpression(
   orCall));

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293752=293751=293752=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Feb  1 03:23:39 2017
@@ -424,7 +424,12 @@ void ContinuationIndenter::addTokenOnCur
 (P->is(TT_BinaryOperator) &&
  Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
 (P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);
-if (!BreakBeforeOperator ||
+// Don't do this if there are only two operands. In these cases, there is
+// always a nice vertical separation between them and the extra line break
+// does not help.
+bool HasTwoOperands =
+P->OperatorIndex == 0 && !P->NextOperator && 
!P->is(TT_ConditionalExpr);
+if ((!BreakBeforeOperator && !HasTwoOperands) ||
 (!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
   State.Stack.back().NoLineBreakInOperand = true;
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=293752=293751=293752=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Feb  1 03:23:39 2017
@@ -4060,9 +4060,14 @@ TEST_F(FormatTest, ExpressionIndentation
"aa +\n"
"bbb) {\n}");
   verifyFormat("if () {\n"
+   "} else if (a && b > // break\n"
+   "c) {\n"
+   "}");
+  verifyFormat("if () {\n"
"} else if (a &&\n"
"   b > // break\n"
-   "   c) {\n"
+   "   c &&\n"
+   "   d) {\n"
"}");
 
   // Presence of a trailing comment used to change indentation of b.
@@ -4167,7 +4172,7 @@ TEST_F(FormatTest, NoOperandAlignment) {
Style);
   verifyFormat("int a = aa\n"
"+ b\n"
-   "* ;",
+   "* ;\n",
Style);
 
   Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
@@ -4659,9 +4664,13 @@ TEST_F(FormatTest, BreaksDesireably) {
   "aa(new Aaaa(\n"
   "a));");
   verifyFormat(
+  "aa(aaa, new Aaaa(\n"
+  "a));");
+  verifyFormat(
   "aa(aaa,\n"
   "   new Aaaa(\n"
-  "   a));");
+  "   a),\n"
+  "   );");
   verifyFormat("a(aa +\n"
"  aa,\n"
"  aa);");
@@ -5140,11 +5149,18 @@ TEST_F(FormatTest, ParenthesesAndOperand
 
 TEST_F(FormatTest, BreaksConditionalExpressions) {
   verifyFormat(
-  "(,\n"
+  "(, aa\n"
+  "   ? a\n"
+  "   : aa);");
+  verifyFormat(
+  "(aa, ,\n"
   " aa ? a\n"

r293636 - clang-format: [JS] Indent expressions in ${} relative to their surrounding

2017-01-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Jan 31 08:39:33 2017
New Revision: 293636

URL: http://llvm.org/viewvc/llvm-project?rev=293636=rev
Log:
clang-format: [JS] Indent expressions in ${} relative to their surrounding

This only affects expressions inside ${} scopes of template strings.
Here, we want to indent relative to the surrounding template string and
not the surrounding expression. Otherwise, this can create quite a mess.

Before:
  var f = `
aa: ${someFunction(
  a +  //
  )}`;

After:
  var f = `
aa: ${someFunction(
  a +  //
  )}`;

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293636=293635=293636=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jan 31 08:39:33 2017
@@ -985,12 +985,23 @@ void ContinuationIndenter::moveStatePast
 //   int> v);
 // FIXME: We likely want to do this for more combinations of brackets.
 // Verify that it is wanted for ObjC, too.
-if (Current.Tok.getKind() == tok::less &&
-Current.ParentBracket == tok::l_paren) {
+if (Current.is(tok::less) && Current.ParentBracket == tok::l_paren) {
   NewIndent = std::max(NewIndent, State.Stack.back().Indent);
   LastSpace = std::max(LastSpace, State.Stack.back().Indent);
 }
 
+// JavaScript template strings are special as we always want to indent
+// nested expressions relative to the ${}. Otherwise, this can create quite
+// a mess.
+if (Current.is(TT_TemplateString)) {
+  unsigned Column = Current.IsMultiline
+? Current.LastLineColumnWidth
+: State.Column + Current.ColumnWidth;
+  NewIndent = Column;
+  LastSpace = Column;
+  NestedBlockIndent = Column;
+}
+
 AvoidBinPacking =
 (State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
 (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293636=293635=293636=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jan 31 08:39:33 2017
@@ -1401,6 +1401,63 @@ TEST_F(FormatTestJS, TemplateStrings) {
" a:${  aaa. a} `;");
 }
 
+TEST_F(FormatTestJS, TemplateStringMultiLineExpression) {
+  verifyFormat("var f = `aa: ${a +  //\n"
+   "   }`;",
+   "var f = `aa: ${a +  //\n"
+   "   }`;");
+  verifyFormat("var f = `aa: ${ //\n"
+   "   a +  //\n"
+   "   }`;",
+   "var f = `aa: ${ //\n"
+   "   a +  //\n"
+   "   }`;");
+  verifyFormat("var f = `\n"
+   "  aa: ${a +  //\n"
+   "}`;",
+   "var f  =  `\n"
+   "  aa: ${   a  +  //\n"
+   " }`;");
+  verifyFormat("var f = `\n"
+   "  aa: ${ //\n"
+   "a +  //\n"
+   "}`;",
+   "var f  =  `\n"
+   "  aa: ${ //\n"
+   "a  +  //\n"
+   "}`  ;");
+  verifyFormat("var f = `\n"
+   "  aa: ${someFunction(\n"
+   "a +  //\n"
+   ")}`;",
+   "var f  =  `\n"
+   "  aa: ${ someFunction  (\n"
+   "a  +   //\n"
+   ")}`;");
+  verifyFormat("var f = `\n"
+   "  aa: ${  //\n"
+   "someFunction(\n"
+   "a +  //\n"
+   ")}`;",
+   "var f  =  `\n"
+   "  aa: ${  //\n"
+   " 

r293622 - clang-format: [JS] Properly set scopes inside template strings.

2017-01-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Jan 31 07:03:07 2017
New Revision: 293622

URL: http://llvm.org/viewvc/llvm-project?rev=293622=rev
Log:
clang-format: [JS] Properly set scopes inside template strings.

Before:
  var f = `a:${aaa
  .a} 
   a:${aaa.a} `;

After:
  var f = `a:${aaa.a} 
   a:${aaa.a} `;

Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=293622=293621=293622=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Jan 31 07:03:07 2017
@@ -337,11 +337,15 @@ struct FormatToken {
 
   /// \brief Returns whether \p Tok is ([{ or a template opening <.
   bool opensScope() const {
+if (is(TT_TemplateString) && TokenText.endswith("${"))
+  return true;
 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
TT_TemplateOpener);
   }
   /// \brief Returns whether \p Tok is )]} or a template closing >.
   bool closesScope() const {
+if (is(TT_TemplateString) && TokenText.startswith("}"))
+  return true;
 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
TT_TemplateCloser);
   }

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=293622=293621=293622=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jan 31 07:03:07 2017
@@ -1454,7 +1454,9 @@ public:
 
   // Consume scopes: (), [], <> and {}
   if (Current->opensScope()) {
-while (Current && !Current->closesScope()) {
+// In fragment of a JavaScript template string can look like '}..${' 
and
+// thus close a scope and open a new one at the same time.
+while (Current && (!Current->closesScope() || Current->opensScope())) {
   next();
   parse();
 }

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293622=293621=293622=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jan 31 07:03:07 2017
@@ -1392,6 +1392,13 @@ TEST_F(FormatTestJS, TemplateStrings) {
   // The token stream can contain two string_literals in sequence, but that
   // doesn't mean that they are implicitly concatenated in JavaScript.
   verifyFormat("var f = ` ${a ? 'a' : 'b'}`;");
+
+  // Ensure that scopes are appropriately set around evaluated expressions in
+  // template strings.
+  verifyFormat("var f = `a:${aaa.a} \n"
+   " a:${aaa.a} `;",
+   "var f = `a:${aaa.  a} \n"
+   " a:${  aaa. a} `;");
 }
 
 TEST_F(FormatTestJS, TemplateStringASI) {


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


r293618 - clang-format: [JS] Fix incorrect line break in template strings.

2017-01-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Jan 31 06:07:35 2017
New Revision: 293618

URL: http://llvm.org/viewvc/llvm-project?rev=293618=rev
Log:
clang-format: [JS] Fix incorrect line break in template strings.

Before:
  var f = ` ${a ? 'a' : 'b'
}`;

After:
  var f = ` ${a ? 'a' : 'b'}`;

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=293618=293617=293618=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jan 31 06:07:35 2017
@@ -2388,6 +2388,11 @@ bool TokenAnnotator::mustBreakBefore(con
 if (Right.is(tok::plus) && Left.is(tok::string_literal) && Right.Next &&
 Right.Next->is(tok::string_literal))
   return true;
+  } else if (Style.Language == FormatStyle::LK_Cpp ||
+ Style.Language == FormatStyle::LK_ObjC) {
+if (Left.isStringLiteral() &&
+(Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral)))
+  return true;
   }
 
   // If the last token before a '}' is a comma or a trailing comment, the
@@ -2411,9 +2416,6 @@ bool TokenAnnotator::mustBreakBefore(con
(Right.NewlinesBefore > 0 && Right.HasUnescapedNewline);
   if (Left.isTrailingComment())
 return true;
-  if (Left.isStringLiteral() &&
-  (Right.isStringLiteral() || Right.is(TT_ObjCStringLiteral)))
-return true;
   if (Right.Previous->IsUnterminatedLiteral)
 return true;
   if (Right.is(tok::lessless) && Right.Next &&

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293618=293617=293618=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jan 31 06:07:35 2017
@@ -1388,6 +1388,10 @@ TEST_F(FormatTestJS, TemplateStrings) {
"var y;");
   // Escaped dollar.
   verifyFormat("var x = ` \\${foo}`;\n");
+
+  // The token stream can contain two string_literals in sequence, but that
+  // doesn't mean that they are implicitly concatenated in JavaScript.
+  verifyFormat("var f = ` ${a ? 'a' : 'b'}`;");
 }
 
 TEST_F(FormatTestJS, TemplateStringASI) {


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


r293616 - [clang-format] Refactor WhitespaceManager and friends

2017-01-31 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Jan 31 05:25:01 2017
New Revision: 293616

URL: http://llvm.org/viewvc/llvm-project?rev=293616=rev
Log:
[clang-format] Refactor WhitespaceManager and friends

The main motivation behind this is to cleanup the WhitespaceManager and
make it more extensible for future alignment etc. features.
Specifically, WhitespaceManager has started to copy more and more code
that is already present in FormatToken. Instead, I think it makes more
sense to actually store a reference to each FormatToken for each change.

This has as a consequence led to a change in the calculation of indent
levels. Now, we actually compute them for each Token ahead of time,
which should be more efficient as it removes an unsigned value for the
ParenState, which is used during the combinatorial exploration of the
solution space.

No functional changes intended.

Review: https://reviews.llvm.org/D29300

Modified:
cfe/trunk/lib/Format/BreakableToken.cpp
cfe/trunk/lib/Format/BreakableToken.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
cfe/trunk/lib/Format/UnwrappedLineFormatter.h
cfe/trunk/lib/Format/WhitespaceManager.cpp
cfe/trunk/lib/Format/WhitespaceManager.h

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=293616=293615=293616=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Tue Jan 31 05:25:01 2017
@@ -181,10 +181,10 @@ unsigned BreakableSingleLineToken::getLi
 }
 
 BreakableSingleLineToken::BreakableSingleLineToken(
-const FormatToken , unsigned IndentLevel, unsigned StartColumn,
-StringRef Prefix, StringRef Postfix, bool InPPDirective,
-encoding::Encoding Encoding, const FormatStyle )
-: BreakableToken(Tok, IndentLevel, InPPDirective, Encoding, Style),
+const FormatToken , unsigned StartColumn, StringRef Prefix,
+StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding,
+const FormatStyle )
+: BreakableToken(Tok, InPPDirective, Encoding, Style),
   StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) {
   assert(Tok.TokenText.endswith(Postfix));
   Line = Tok.TokenText.substr(
@@ -192,11 +192,11 @@ BreakableSingleLineToken::BreakableSingl
 }
 
 BreakableStringLiteral::BreakableStringLiteral(
-const FormatToken , unsigned IndentLevel, unsigned StartColumn,
-StringRef Prefix, StringRef Postfix, bool InPPDirective,
-encoding::Encoding Encoding, const FormatStyle )
-: BreakableSingleLineToken(Tok, IndentLevel, StartColumn, Prefix, Postfix,
-   InPPDirective, Encoding, Style) {}
+const FormatToken , unsigned StartColumn, StringRef Prefix,
+StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding,
+const FormatStyle )
+: BreakableSingleLineToken(Tok, StartColumn, Prefix, Postfix, 
InPPDirective,
+   Encoding, Style) {}
 
 BreakableToken::Split
 BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset,
@@ -218,16 +218,16 @@ void BreakableStringLiteral::insertBreak
 --LeadingSpaces;
   Whitespaces.replaceWhitespaceInToken(
   Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
-  Prefix, InPPDirective, 1, IndentLevel, LeadingSpaces);
+  Prefix, InPPDirective, 1, LeadingSpaces);
 }
 
 BreakableComment::BreakableComment(const FormatToken ,
-   unsigned IndentLevel, unsigned StartColumn,
+   unsigned StartColumn,
unsigned OriginalStartColumn,
bool FirstInLine, bool InPPDirective,
encoding::Encoding Encoding,
const FormatStyle )
-: BreakableToken(Token, IndentLevel, InPPDirective, Encoding, Style),
+: BreakableToken(Token, InPPDirective, Encoding, Style),
   StartColumn(StartColumn), OriginalStartColumn(OriginalStartColumn),
   FirstInLine(FirstInLine) {}
 
@@ -254,8 +254,7 @@ void BreakableComment::compressWhitespac
   unsigned CharsToRemove = Split.second;
   Whitespaces.replaceWhitespaceInToken(
   tokenAt(LineIndex), BreakOffsetInToken, CharsToRemove, "", "",
-  /*InPPDirective=*/false,
-  /*Newlines=*/0, /*IndentLevel=*/0, /*Spaces=*/1);
+  /*InPPDirective=*/false, /*Newlines=*/0, /*Spaces=*/1);
 }
 
 BreakableToken::Split
@@ -319,11 +318,11 @@ bool BreakableComment::mayReflow(unsigne
 }
 
 BreakableBlockComment::BreakableBlockComment(
-const FormatToken , unsigned IndentLevel, unsigned StartColumn,
+const FormatToken , unsigned StartColumn,
 unsigned 

r293465 - clang-format: [JavaScript] Undo r291974 for JavaScript.

2017-01-29 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jan 30 01:08:40 2017
New Revision: 293465

URL: http://llvm.org/viewvc/llvm-project?rev=293465=rev
Log:
clang-format: [JavaScript] Undo r291974 for JavaScript.

This had significant negative consequences and I don't have a good
solution for it yet.

Before:
  var string =
  [
'aa',
'bb',
  ]
  .join('+');

After:
  var string = [
'aa',
'bb',
  ].join('+');

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=293465=293464=293465=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jan 30 01:08:40 2017
@@ -199,7 +199,14 @@ bool ContinuationIndenter::mustBreak(con
 
   if (startsSegmentOfBuilderTypeCall(Current) &&
   (State.Stack.back().CallContinuation != 0 ||
-   State.Stack.back().BreakBeforeParameter))
+   State.Stack.back().BreakBeforeParameter) &&
+  // JavaScript is treated different here as there is a frequent pattern:
+  //   SomeFunction(function() {
+  // ...
+  //   }.bind(...));
+  // FIXME: We should find a more generic solution to this problem.
+  !(State.Column <= NewLineColumn &&
+Style.Language == FormatStyle::LK_JavaScript))
 return true;
 
   if (State.Column <= NewLineColumn)

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=293465=293464=293465=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan 30 01:08:40 2017
@@ -497,6 +497,11 @@ TEST_F(FormatTestJS, ArrayLiterals) {
"[];");
 
   verifyFormat("someFunction([], {a: a});");
+
+  verifyFormat("var string = [\n"
+   "  'aa',\n"
+   "  'bb',\n"
+   "].join('+');");
 }
 
 TEST_F(FormatTestJS, ColumnLayoutForArrayLiterals) {
@@ -587,6 +592,11 @@ TEST_F(FormatTestJS, FunctionLiterals) {
"  doSomething();\n"
"}, this));");
 
+  verifyFormat("SomeFunction(function() {\n"
+   "  foo();\n"
+   "  bar();\n"
+   "}.bind(this));");
+
   // FIXME: This is bad, we should be wrapping before "function() {".
   verifyFormat("someFunction(function() {\n"
"  doSomething();  // break\n"


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


r292116 - Fix test failures after recent clang-format format change.

2017-01-16 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jan 16 07:43:46 2017
New Revision: 292116

URL: http://llvm.org/viewvc/llvm-project?rev=292116=rev
Log:
Fix test failures after recent clang-format format change.

Modified:
cfe/trunk/test/Index/overriding-ftemplate-comments.cpp

Modified: cfe/trunk/test/Index/overriding-ftemplate-comments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/overriding-ftemplate-comments.cpp?rev=292116=292115=292116=diff
==
--- cfe/trunk/test/Index/overriding-ftemplate-comments.cpp (original)
+++ cfe/trunk/test/Index/overriding-ftemplate-comments.cpp Mon Jan 16 07:43:46 
2017
@@ -77,10 +77,10 @@ void comment_to_html_conversion_21();
 template  class 
BBB > class AAA>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class C1, template class C2, template class C3, class C4 class 
BBB\n  class AAA\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class C1,\n template class C2, template class C3, class C4 
class BBB\n  class AAA\nvoid 
comment_to_html_conversion_22()C10
 Ccc 1 
AAA1
 Zzz 
C2 
Ccc 2 
C3 
Ccc 3 
C4 
Ccc 4 
BBB 
Bbb]
 
 template 
class QQQ> class PPP>
 void comment_to_html_conversion_22();
 
-// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class CCC1, template class CCC2, template class CCC3, class 
CCC4\nclass QQQ class PPP\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
+// CHECK: FullCommentAsXML=[comment_to_html_conversion_22c:@FT@2#T#t2#T#t2#T#Tcomment_to_html_conversion_22#v#template
 class CCC1,\n template class CCC2, template class CCC3, class 
CCC4 class QQQ\n class PPP\nvoid 
comment_to_html_conversion_22()CCC10
 Ccc 1 
PPP1
 Zzz 
CCC2 
Ccc 2 
CCC3 
Ccc 3 
CCC4 
Ccc 4 
QQQ 
Bbb]
 


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


r292110 - clang-format: Always wrap before multi-line parameters/operands.

2017-01-16 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jan 16 07:13:15 2017
New Revision: 292110

URL: http://llvm.org/viewvc/llvm-project?rev=292110=rev
Log:
clang-format: Always wrap before multi-line parameters/operands.

Before:
  aa(, aaa::
   ,
 a);

After:
  aa(,
 aaa::
 ,
 a);

No new test cases, as the existing ones cover this fairly well.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/ContinuationIndenter.h
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=292110=292109=292110=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jan 16 07:13:15 2017
@@ -135,6 +135,12 @@ bool ContinuationIndenter::canBreak(cons
   return false;
   }
 
+  // If binary operators are moved to the next line (including commas for some
+  // styles of constructor initializers), that's always ok.
+  if (!Current.isOneOf(TT_BinaryOperator, tok::comma) &&
+  State.Stack.back().NoLineBreakInOperand)
+return false;
+
   return !State.Stack.back().NoLineBreak;
 }
 
@@ -395,6 +401,27 @@ void ContinuationIndenter::addTokenOnCur
 State.Stack.back().NoLineBreak = true;
   }
 
+  // Don't allow the RHS of an operator to be split over multiple lines unless
+  // there is a line-break right after the operator.
+  // Exclude relational operators, as there, it is always more desirable to
+  // have the LHS 'left' of the RHS.
+  const FormatToken *P = Current.getPreviousNonComment();
+  if (!Current.is(tok::comment) && P &&
+  (P->isOneOf(TT_BinaryOperator, tok::comma) ||
+   (P->is(TT_ConditionalExpr) && P->is(tok::colon))) &&
+  !P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
+  P->getPrecedence() != prec::Assignment &&
+  P->getPrecedence() != prec::Relational) {
+bool BreakBeforeOperator =
+P->is(tok::lessless) ||
+(P->is(TT_BinaryOperator) &&
+ Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None) ||
+(P->is(TT_ConditionalExpr) && Style.BreakBeforeTernaryOperators);
+if (!BreakBeforeOperator ||
+(!State.Stack.back().LastOperatorWrapped && BreakBeforeOperator))
+  State.Stack.back().NoLineBreakInOperand = true;
+  }
+
   State.Column += Spaces;
   if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
   Previous.Previous &&
@@ -716,6 +743,8 @@ unsigned ContinuationIndenter::moveState
   assert(State.Stack.size());
   const FormatToken  = *State.NextToken;
 
+  if (Current.isOneOf(tok::comma, TT_BinaryOperator))
+State.Stack.back().NoLineBreakInOperand = false;
   if (Current.is(TT_InheritanceColon))
 State.Stack.back().AvoidBinPacking = true;
   if (Current.is(tok::lessless) && Current.isNot(TT_OverloadedOperator)) {
@@ -724,8 +753,10 @@ unsigned ContinuationIndenter::moveState
 else
   State.Stack.back().LastOperatorWrapped = Newline;
   }
-  if ((Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless)) ||
-  Current.is(TT_ConditionalExpr))
+  if (Current.is(TT_BinaryOperator) && Current.isNot(tok::lessless))
+State.Stack.back().LastOperatorWrapped = Newline;
+  if (Current.is(TT_ConditionalExpr) && Current.Previous &&
+  !Current.Previous->is(TT_ConditionalExpr))
 State.Stack.back().LastOperatorWrapped = Newline;
   if (Current.is(TT_ArraySubscriptLSquare) &&
   State.Stack.back().StartOfArraySubscripts == 0)
@@ -848,6 +879,8 @@ void ContinuationIndenter::moveStatePast
I != E; ++I) {
 ParenState NewParenState = State.Stack.back();
 NewParenState.ContainsLineBreak = false;
+NewParenState.NoLineBreak =
+NewParenState.NoLineBreak || State.Stack.back().NoLineBreakInOperand;
 
 // Indent from 'LastSpace' unless these are fake parentheses encapsulating
 // a builder type call after 'return' or, if the alignment after opening
@@ -862,24 +895,6 @@ void ContinuationIndenter::moveStatePast
   std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
 
-// Don't allow the RHS of an operator to be split over multiple lines 
unless
-// there is a line-break right after the operator.
-// Exclude relational operators, as there, it is always more desirable to
-// have the LHS 'left' of the RHS.
-if (Previous && Previous->getPrecedence() != prec::Assignment &&
-Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr, tok::comma) 

Re: r291905 - [Sema] Add warning for unused lambda captures

2017-01-15 Thread Daniel Jasper via cfe-commits
Sorry, for the noise.
This is probably not the revision that caused this.

On Mon, Jan 16, 2017 at 1:08 AM, Daniel Jasper  wrote:

> This patch seems to break on some of our code. Reproducer:
>
> $ cat /tmp/ctor.cc
> template 
> struct A {
>   A() {}
> };
>
> template 
> class B : T {
>   using T::T;
> };
>
> struct C {
>   B d;
>   C(A b) : d(b) {}
> };
>
> djasper@dj:~/llvm/release$ bin/clang -cc1 -std=c++11 /tmp/ctor.cc
> /tmp/ctor.cc:13:17: error: no matching constructor for initialization of
> 'B'
>   C(A b) : d(b) {}
> ^ ~
> /tmp/ctor.cc:7:7: note: candidate constructor (the implicit copy
> constructor) not viable: no known conversion from 'A' to 'const
> B' for 1st argument
> class B : T {
>   ^
> /tmp/ctor.cc:7:7: note: candidate constructor (the implicit move
> constructor) not viable: no known conversion from 'A' to 'B'
> for 1st argument
> class B : T {
>   ^
> /tmp/ctor.cc:7:7: note: candidate constructor (the implicit default
> constructor) not viable: requires 0 arguments, but 1 was provided
> 1 error generated.
>
> As far as I can tell, the copy constructor of class A does not get
> forwarded with the "using T::T". I am not an expert on this parts of the
> language, but this does seem like an unwanted side-effect. It builds find
> with a version of Clang prior to this patch.
>
> On Fri, Jan 13, 2017 at 4:01 PM, Malcolm Parsons via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: malcolm.parsons
>> Date: Fri Jan 13 09:01:06 2017
>> New Revision: 291905
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=291905=rev
>> Log:
>> [Sema] Add warning for unused lambda captures
>>
>> Summary:
>> Warn when a lambda explicitly captures something that is not used in its
>> body.
>>
>> The warning is part of -Wunused and can be enabled with
>> -Wunused-lambda-capture.
>>
>> Reviewers: rsmith, arphaman, jbcoe, aaron.ballman
>>
>> Subscribers: Quuxplusone, arphaman, cfe-commits
>>
>> Differential Revision: https://reviews.llvm.org/D28467
>>
>> Added:
>> cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/include/clang/Sema/ScopeInfo.h
>> cfe/trunk/include/clang/Sema/Sema.h
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/lib/Sema/SemaLambda.cpp
>> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
>> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
>> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
>> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
>> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
>> cfe/trunk/test/SemaCXX/uninitialized.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticGroups.td?rev=291905=291904=291905=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jan 13
>> 09:01:06 2017
>> @@ -480,6 +480,7 @@ def UnusedFunction : DiagGroup<"unused-f
>>  def UnusedMemberFunction : DiagGroup<"unused-member-function",
>>   [UnneededMemberFunction]>;
>>  def UnusedLabel : DiagGroup<"unused-label">;
>> +def UnusedLambdaCapture : DiagGroup<"unused-lambda-capture">;
>>  def UnusedParameter : DiagGroup<"unused-parameter">;
>>  def UnusedResult : DiagGroup<"unused-result">;
>>  def PotentiallyEvaluatedExpression : DiagGroup<"potentially-evaluat
>> ed-expression">;
>> @@ -617,8 +618,9 @@ def Unused : DiagGroup<"unused",
>> [UnusedArgument, UnusedFunction, UnusedLabel,
>>  // UnusedParameter, (matches GCC's behavior)
>>  // UnusedMemberFunction, (clean-up llvm before
>> enabling)
>> -UnusedPrivateField, UnusedLocalTypedef,
>> -UnusedValue, UnusedVariable,
>> UnusedPropertyIvar]>,
>> +UnusedPrivateField, UnusedLambdaCapture,
>> +UnusedLocalTypedef, UnusedValue, UnusedVariable,
>> +UnusedPropertyIvar]>,
>>  DiagCategory<"Unused Entity Issue">;
>>
>>  // Format settings.
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Basic/DiagnosticSemaKinds.td?rev=291905=291904=291905=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 13
>> 09:01:06 2017
>> @@ -316,6 +316,9 @@ def 

Re: r291905 - [Sema] Add warning for unused lambda captures

2017-01-15 Thread Daniel Jasper via cfe-commits
This patch seems to break on some of our code. Reproducer:

$ cat /tmp/ctor.cc
template 
struct A {
  A() {}
};

template 
class B : T {
  using T::T;
};

struct C {
  B d;
  C(A b) : d(b) {}
};

djasper@dj:~/llvm/release$ bin/clang -cc1 -std=c++11 /tmp/ctor.cc
/tmp/ctor.cc:13:17: error: no matching constructor for initialization of
'B'
  C(A b) : d(b) {}
^ ~
/tmp/ctor.cc:7:7: note: candidate constructor (the implicit copy
constructor) not viable: no known conversion from 'A' to 'const
B' for 1st argument
class B : T {
  ^
/tmp/ctor.cc:7:7: note: candidate constructor (the implicit move
constructor) not viable: no known conversion from 'A' to 'B'
for 1st argument
class B : T {
  ^
/tmp/ctor.cc:7:7: note: candidate constructor (the implicit default
constructor) not viable: requires 0 arguments, but 1 was provided
1 error generated.

As far as I can tell, the copy constructor of class A does not get
forwarded with the "using T::T". I am not an expert on this parts of the
language, but this does seem like an unwanted side-effect. It builds find
with a version of Clang prior to this patch.

On Fri, Jan 13, 2017 at 4:01 PM, Malcolm Parsons via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: malcolm.parsons
> Date: Fri Jan 13 09:01:06 2017
> New Revision: 291905
>
> URL: http://llvm.org/viewvc/llvm-project?rev=291905=rev
> Log:
> [Sema] Add warning for unused lambda captures
>
> Summary:
> Warn when a lambda explicitly captures something that is not used in its
> body.
>
> The warning is part of -Wunused and can be enabled with
> -Wunused-lambda-capture.
>
> Reviewers: rsmith, arphaman, jbcoe, aaron.ballman
>
> Subscribers: Quuxplusone, arphaman, cfe-commits
>
> Differential Revision: https://reviews.llvm.org/D28467
>
> Added:
> cfe/trunk/test/SemaCXX/warn-unused-lambda-capture.cpp
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/include/clang/Sema/ScopeInfo.h
> cfe/trunk/include/clang/Sema/Sema.h
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/lib/Sema/SemaLambda.cpp
> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p12.cpp
> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p13.cpp
> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p18.cpp
> cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p19.cpp
> cfe/trunk/test/SemaCXX/uninitialized.cpp
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Basic/DiagnosticGroups.td?rev=291905=291904=291905=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Fri Jan 13 09:01:06
> 2017
> @@ -480,6 +480,7 @@ def UnusedFunction : DiagGroup<"unused-f
>  def UnusedMemberFunction : DiagGroup<"unused-member-function",
>   [UnneededMemberFunction]>;
>  def UnusedLabel : DiagGroup<"unused-label">;
> +def UnusedLambdaCapture : DiagGroup<"unused-lambda-capture">;
>  def UnusedParameter : DiagGroup<"unused-parameter">;
>  def UnusedResult : DiagGroup<"unused-result">;
>  def PotentiallyEvaluatedExpression : DiagGroup<"potentially-
> evaluated-expression">;
> @@ -617,8 +618,9 @@ def Unused : DiagGroup<"unused",
> [UnusedArgument, UnusedFunction, UnusedLabel,
>  // UnusedParameter, (matches GCC's behavior)
>  // UnusedMemberFunction, (clean-up llvm before
> enabling)
> -UnusedPrivateField, UnusedLocalTypedef,
> -UnusedValue, UnusedVariable, UnusedPropertyIvar]>,
> +UnusedPrivateField, UnusedLambdaCapture,
> +UnusedLocalTypedef, UnusedValue, UnusedVariable,
> +UnusedPropertyIvar]>,
>  DiagCategory<"Unused Entity Issue">;
>
>  // Format settings.
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/
> DiagnosticSemaKinds.td?rev=291905=291904=291905=diff
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jan 13
> 09:01:06 2017
> @@ -316,6 +316,9 @@ def warn_unneeded_member_function : Warn
>InGroup, DefaultIgnore;
>  def warn_unused_private_field: Warning<"private field %0 is not used">,
>InGroup, DefaultIgnore;
> +def warn_unused_lambda_capture: Warning<"lambda capture %0 is not "
> +  "%select{used|required to be captured for use in an unevaluated
> context}1">,
> 

r291807 - clang-format: Fix regression introduced by r291801.

2017-01-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Jan 12 14:06:28 2017
New Revision: 291807

URL: http://llvm.org/viewvc/llvm-project?rev=291807=rev
Log:
clang-format: Fix regression introduced by r291801.

Uncovered by polly tests.

Before:
  aa(aaa,
 {}, aaa);

After:
  aa(aaa, {},
 aaa);

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=291807=291806=291807=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Jan 12 14:06:28 2017
@@ -930,13 +930,6 @@ void ContinuationIndenter::moveStatePast
 return;
   }
 
-  const FormatToken *Previous = Current.getPreviousNonComment();
-  if (Previous && Previous->is(tok::comma) &&
-  !Previous->is(TT_OverloadedOperator)) {
-if (!Newline)
-  State.Stack.back().NoLineBreak = true;
-  }
-
   unsigned NewIndent;
   unsigned NewIndentLevel = State.Stack.back().IndentLevel;
   unsigned LastSpace = State.Stack.back().LastSpace;
@@ -1010,12 +1003,15 @@ void ContinuationIndenter::moveStatePast
   // Generally inherit NoLineBreak from the current scope to nested scope.
   // However, don't do this for non-empty nested blocks, dict literals and
   // array literals as these follow different indentation rules.
+  const FormatToken *Previous = Current.getPreviousNonComment();
   bool NoLineBreak =
   Current.Children.empty() &&
   !Current.isOneOf(TT_DictLiteral, TT_ArrayInitializerLSquare) &&
   (State.Stack.back().NoLineBreak ||
(Current.is(TT_TemplateOpener) &&
-State.Stack.back().ContainsUnwrappedBuilder));
+State.Stack.back().ContainsUnwrappedBuilder) ||
+   (Current.is(tok::l_brace) && !Newline && Previous &&
+Previous->is(tok::comma)));
   State.Stack.push_back(ParenState(NewIndent, NewIndentLevel, LastSpace,
AvoidBinPacking, NoLineBreak));
   State.Stack.back().NestedBlockIndent = NestedBlockIndent;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=291807=291806=291807=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 12 14:06:28 2017
@@ -6822,6 +6822,8 @@ TEST_F(FormatTest, FormatsBracedListsInC
" {List1, List2,\n"
"  List3});",
getLLVMStyleWithColumns(35));
+  verifyFormat("aa(aaa, {},\n"
+   "   aaa);");
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {


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


r291801 - clang-format: Treat braced lists like other complex parameters.

2017-01-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Jan 12 13:35:26 2017
New Revision: 291801

URL: http://llvm.org/viewvc/llvm-project?rev=291801=rev
Log:
clang-format: Treat braced lists like other complex parameters.

Specifically, wrap before them if they are multi-line so that we don't
create long hanging indents. This prevents having a lot of code
indented a lot in some cases.

Before:
  someFunction(Param, {List1, List2,
   List3});

After:
  someFunction(Param,
   {List1, List2,
List3});

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=291801=291800=291801=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Thu Jan 12 13:35:26 2017
@@ -930,6 +930,13 @@ void ContinuationIndenter::moveStatePast
 return;
   }
 
+  const FormatToken *Previous = Current.getPreviousNonComment();
+  if (Previous && Previous->is(tok::comma) &&
+  !Previous->is(TT_OverloadedOperator)) {
+if (!Newline)
+  State.Stack.back().NoLineBreak = true;
+  }
+
   unsigned NewIndent;
   unsigned NewIndentLevel = State.Stack.back().IndentLevel;
   unsigned LastSpace = State.Stack.back().LastSpace;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=291801=291800=291801=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jan 12 13:35:26 2017
@@ -6816,6 +6816,12 @@ TEST_F(FormatTest, FormatsBracedListsInC
"aa.aaa,\n"
"aa.aaa,\n"
"};");
+
+  // Don't create hanging lists.
+  verifyFormat("someFunction(Param,\n"
+   " {List1, List2,\n"
+   "  List3});",
+   getLLVMStyleWithColumns(35));
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {


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


r291434 - clang-format: Improve support for override/final as variable names.

2017-01-09 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jan  9 05:04:07 2017
New Revision: 291434

URL: http://llvm.org/viewvc/llvm-project?rev=291434=rev
Log:
clang-format: Improve support for override/final as variable names.

Before:
  bool a = f() &();
  bool a = f() &();
  void f(const MyOverride & override);
  void f(const MyFinal & final);

After:
  bool a = f() && override.f();
  bool a = f() && final.f();
  void f(const MyOverride );
  void f(const MyFinal );

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=291434=291433=291434=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jan  9 05:04:07 2017
@@ -1282,9 +1282,7 @@ private:
   return TT_UnaryOperator;
 
 const FormatToken *NextToken = Tok.getNextNonComment();
-if (!NextToken ||
-NextToken->isOneOf(tok::arrow, Keywords.kw_final, tok::equal,
-   Keywords.kw_override) ||
+if (!NextToken || NextToken->isOneOf(tok::arrow, tok::equal) ||
 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
   return TT_PointerOrReference;
 
@@ -2088,9 +2086,9 @@ bool TokenAnnotator::spaceRequiredBetwee
 !Line.IsMultiVariableDeclStmt)))
 return true;
   if (Left.is(TT_PointerOrReference))
-return Right.Tok.isLiteral() ||
-   Right.isOneOf(TT_BlockComment, Keywords.kw_final,
- Keywords.kw_override) ||
+return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
+   (Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
+!Right.is(TT_StartOfName)) ||
(Right.is(tok::l_brace) && Right.BlockKind == BK_Block) ||
(!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
tok::l_paren) &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=291434=291433=291434=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan  9 05:04:07 2017
@@ -5780,6 +5780,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
   verifyGoogleFormat("MACRO Constructor(const int& i) : a(a), b(b) {}");
   verifyFormat("void f() { f(a, c * d); }");
   verifyFormat("void f() { f(new a(), c * d); }");
+  verifyFormat("void f(const MyOverride );");
+  verifyFormat("void f(const MyFinal );");
+  verifyIndependentOfContext("bool a = f() && override.f();");
+  verifyIndependentOfContext("bool a = f() && final.f();");
 
   verifyIndependentOfContext("InvalidRegions[*R] = 0;");
 


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


r290842 - Remove isIgnored()-test that is more expensive than the analysis behind it

2017-01-02 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Jan  2 16:55:45 2017
New Revision: 290842

URL: http://llvm.org/viewvc/llvm-project?rev=290842=rev
Log:
Remove isIgnored()-test that is more expensive than the analysis behind it

In many translation units I have tried, the calls to isIgnored() removed
in this patch are more expensive than doing the analysis that is behind
it. The speed-up in translation units I have tried is between 10 and
20%.

Review: https://reviews.llvm.org/D28208

Modified:
cfe/trunk/lib/Sema/SemaTemplate.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=290842=290841=290842=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Mon Jan  2 16:55:45 2017
@@ -4244,7 +4244,7 @@ namespace {
 UnnamedLocalNoLinkageFinder(Sema , SourceRange SR) : S(S), SR(SR) { }
 
 bool Visit(QualType T) {
-  return inherited::Visit(T.getTypePtr());
+  return T.isNull() ? false : inherited::Visit(T.getTypePtr());
 }
 
 #define TYPE(Class, Parent) \
@@ -4497,17 +4497,7 @@ bool Sema::CheckTemplateArgument(Templat
   //
   // C++11 allows these, and even in C++03 we allow them as an extension with
   // a warning.
-  bool NeedsCheck;
-  if (LangOpts.CPlusPlus11)
-NeedsCheck =
-!Diags.isIgnored(diag::warn_cxx98_compat_template_arg_unnamed_type,
- SR.getBegin()) ||
-!Diags.isIgnored(diag::warn_cxx98_compat_template_arg_local_type,
- SR.getBegin());
-  else
-NeedsCheck = Arg->hasUnnamedOrLocalType();
-
-  if (NeedsCheck) {
+  if (LangOpts.CPlusPlus11 || Arg->hasUnnamedOrLocalType()) {
 UnnamedLocalNoLinkageFinder Finder(*this, SR);
 (void)Finder.Visit(Context.getCanonicalType(Arg));
   }


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


r290337 - clang-format: Less eagerly try to keep label-value pairs on a line.

2016-12-22 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Thu Dec 22 06:37:06 2016
New Revision: 290337

URL: http://llvm.org/viewvc/llvm-project?rev=290337=rev
Log:
clang-format: Less eagerly try to keep label-value pairs on a line.

Before:
  string v =
  StrCat("aaa: ", SomeFunction(,
   aaa),
 bbb);

After:
  string v = StrCat("aaa: ",
SomeFunction(, aaa),
bbb);

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=290337=290336=290337=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Dec 22 06:37:06 2016
@@ -2001,7 +2001,7 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
   (Left.NextOperator || Left.OperatorIndex != 0))
-return 100;
+return 45;
   if (Right.is(tok::plus) && Left.isLabelString() &&
   (Right.NextOperator || Right.OperatorIndex != 0))
 return 25;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290337=290336=290337=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Dec 22 06:37:06 2016
@@ -5220,6 +5220,10 @@ TEST_F(FormatTest, KeepStringLabelValueP
   verifyFormat("string v = StrCat(\": \" +\n"
"  (aaa + a));",
getLLVMStyleWithColumns(40));
+  verifyFormat(
+  "string v = StrCat(\"aaa: \",\n"
+  "  SomeFunction(, .aaa),\n"
+  "  bbb);");
 }
 
 TEST_F(FormatTest, UnderstandsEquals) {


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


r290259 - clang-format: Fix bug in handling of single-column lists.

2016-12-21 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Dec 21 11:02:06 2016
New Revision: 290259

URL: http://llvm.org/viewvc/llvm-project?rev=290259=rev
Log:
clang-format: Fix bug in handling of single-column lists.

Members that are themselves wrapped in fake parentheses would lead to
AvoidBinPacking be set on the wrong ParenState.

After:
  vector  = {
  aa.aaa,
  aa.aaa,
  aa.aaa,
  aa.aaa,
  aa.aaa,
  aa.aaa,
  };

Before we were falling back to bin-packing these.

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

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=290259=290258=290259=diff
==
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Wed Dec 21 11:02:06 2016
@@ -77,6 +77,9 @@ unsigned CommaSeparatedList::formatAfter
   if (State.NextToken == nullptr || !State.NextToken->Previous)
 return 0;
 
+  if (Formats.size() == 1)
+return 0; // Handled by formatFromToken
+
   // Ensure that we start on the opening brace.
   const FormatToken *LBrace =
   State.NextToken->Previous->getPreviousNonComment();
@@ -93,13 +96,6 @@ unsigned CommaSeparatedList::formatAfter
   // Find the best ColumnFormat, i.e. the best number of columns to use.
   const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
 
-  // Formatting with 1 Column isn't really a column layout, so we don't need 
the
-  // special logic here. We can just avoid bin packing any of the parameters.
-  if (Format && Format->Columns == 1) {
-State.Stack.back().AvoidBinPacking = true;
-return 0;
-  }
-
   // If no ColumnFormat can be used, the braced list would generally be
   // bin-packed. Add a severe penalty to this so that column layouts are
   // preferred if possible.
@@ -137,7 +133,9 @@ unsigned CommaSeparatedList::formatAfter
 unsigned CommaSeparatedList::formatFromToken(LineState ,
  ContinuationIndenter *Indenter,
  bool DryRun) {
-  if (HasNestedBracedList)
+  // Formatting with 1 Column isn't really a column layout, so we don't need 
the
+  // special logic here. We can just avoid bin packing any of the parameters.
+  if (Formats.size() == 1 || HasNestedBracedList)
 State.Stack.back().AvoidBinPacking = true;
   return 0;
 }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290259=290258=290259=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Dec 21 11:02:06 2016
@@ -6800,6 +6800,14 @@ TEST_F(FormatTest, FormatsBracedListsInC
",\n"
"aaa};",
getLLVMStyleWithColumns(30));
+  verifyFormat("vector  = {\n"
+   "aa.aaa,\n"
+   "aa.aaa,\n"
+   "aa.aaa,\n"
+   "aa.aaa,\n"
+   "aa.aaa,\n"
+   "aa.aaa,\n"
+   "};");
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {


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


r290177 - clang-format: Fix bug in understanding string-label analysis.

2016-12-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Dec 20 09:27:46 2016
New Revision: 290177

URL: http://llvm.org/viewvc/llvm-project?rev=290177=rev
Log:
clang-format: Fix bug in understanding string-label analysis.

While for <<-operators often used in log statments, a single key value
pair is always on the second operator, e.g.

  llvm::errs() << "a=" << a;

It is on the first operator for plus- or comma-concatenated strings:

  string s = "aa: " + ;

(the "=" not counting because that's a different operator precedence)

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=290177=290176=290177=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Dec 20 09:27:46 2016
@@ -2000,11 +2000,14 @@ unsigned TokenAnnotator::splitPenalty(co
 
   if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
   Left.Previous->isLabelString() &&
-  (Left.NextOperator || Left.OperatorIndex != 1))
+  (Left.NextOperator || Left.OperatorIndex != 0))
 return 100;
+  if (Right.is(tok::plus) && Left.isLabelString() &&
+  (Right.NextOperator || Right.OperatorIndex != 0))
+return 25;
   if (Left.is(tok::comma))
 return 1;
-  if (Right.isOneOf(tok::lessless, tok::plus) && Left.isLabelString() &&
+  if (Right.is(tok::lessless) && Left.isLabelString() &&
   (Right.NextOperator || Right.OperatorIndex != 1))
 return 25;
   if (Right.is(tok::lessless)) {

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290177=290176=290177=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 20 09:27:46 2016
@@ -5214,6 +5214,12 @@ TEST_F(FormatTest, KeepStringLabelValueP
   verifyFormat("string v = StrCat(\": \", ,\n"
"  \": \", ,\n"
"  \": \", );");
+  verifyFormat("string v = \": \" +\n"
+   "   ( + );",
+   getLLVMStyleWithColumns(40));
+  verifyFormat("string v = StrCat(\": \" +\n"
+   "  (aaa + a));",
+   getLLVMStyleWithColumns(40));
 }
 
 TEST_F(FormatTest, UnderstandsEquals) {


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


Re: r290171 - [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.

2016-12-20 Thread Daniel Jasper via cfe-commits
Reverted in rL290173.

On Tue, Dec 20, 2016 at 11:02 AM, Daniel Jasper  wrote:

> This triggers a bunch of warnings:
>
>   lib/AST/Expr.cpp:1519:11: error: enumeration value 'CK_ZeroToOCLQueue'
> not handled in switch [-Werror,-Wswitch]
>   lib/CodeGen/CGExprConstant.cpp:654:13: error: enumeration value
> 'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]
>   lib/Edit/RewriteObjCFoundationAPI.cpp:1000:13: error: enumeration value
> 'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]
>   lib/StaticAnalyzer/Core/ExprEngineC.cpp:314:13: error: enumeration
> value 'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]
>
> Can you please fix or roll back quickly?
>
> On Tue, Dec 20, 2016 at 10:15 AM, Egor Churaev via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: echuraev
>> Date: Tue Dec 20 03:15:21 2016
>> New Revision: 290171
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=290171=rev
>> Log:
>> [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.
>>
>> Summary: Enabling the compression of CLK_NULL_QUEUE to variable of type
>> queue_t.
>>
>> Reviewers: Anastasia
>>
>> Subscribers: cfe-commits, yaxunl, bader
>>
>> Differential Revision: https://reviews.llvm.org/D27569
>>
>> Added:
>> cfe/trunk/test/CodeGenOpenCL/null_queue.cl
>> cfe/trunk/test/SemaOpenCL/null_queue.cl
>> cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
>> Modified:
>> cfe/trunk/include/clang/AST/OperationKinds.def
>> cfe/trunk/include/clang/Sema/Initialization.h
>> cfe/trunk/include/clang/Sema/Overload.h
>> cfe/trunk/lib/AST/ExprConstant.cpp
>> cfe/trunk/lib/CodeGen/CGExprAgg.cpp
>> cfe/trunk/lib/CodeGen/CGExprComplex.cpp
>> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/lib/Sema/SemaInit.cpp
>> cfe/trunk/lib/Sema/SemaOverload.cpp
>>
>> Modified: cfe/trunk/include/clang/AST/OperationKinds.def
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> AST/OperationKinds.def?rev=290171=290170=290171=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/AST/OperationKinds.def (original)
>> +++ cfe/trunk/include/clang/AST/OperationKinds.def Tue Dec 20 03:15:21
>> 2016
>> @@ -321,6 +321,9 @@ CAST_OPERATION(BuiltinFnToFnPtr)
>>  // Convert a zero value for OpenCL event_t initialization.
>>  CAST_OPERATION(ZeroToOCLEvent)
>>
>> +// Convert a zero value for OpenCL queue_t initialization.
>> +CAST_OPERATION(ZeroToOCLQueue)
>> +
>>  // Convert a pointer to a different address space.
>>  CAST_OPERATION(AddressSpaceConversion)
>>
>>
>> Modified: cfe/trunk/include/clang/Sema/Initialization.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Sema/Initialization.h?rev=290171=290170=290171=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Sema/Initialization.h (original)
>> +++ cfe/trunk/include/clang/Sema/Initialization.h Tue Dec 20 03:15:21
>> 2016
>> @@ -751,6 +751,8 @@ public:
>>  SK_StdInitializerListConstructorCall,
>>  /// \brief Initialize an OpenCL sampler from an integer.
>>  SK_OCLSamplerInit,
>> +/// \brief Initialize queue_t from 0.
>> +SK_OCLZeroQueue,
>>  /// \brief Passing zero to a function where OpenCL event_t is
>> expected.
>>  SK_OCLZeroEvent
>>};
>> @@ -1148,6 +1150,9 @@ public:
>>/// constant.
>>void AddOCLZeroEventStep(QualType T);
>>
>> +  /// \brief Add a step to initialize an OpenCL queue_t from 0.
>> +  void AddOCLZeroQueueStep(QualType T);
>> +
>>/// \brief Add steps to unwrap a initializer list for a reference
>> around a
>>/// single element and rewrap it at the end.
>>void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
>>
>> Modified: cfe/trunk/include/clang/Sema/Overload.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Sema/Overload.h?rev=290171=290170=290171=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Sema/Overload.h (original)
>> +++ cfe/trunk/include/clang/Sema/Overload.h Tue Dec 20 03:15:21 2016
>> @@ -83,6 +83,7 @@ namespace clang {
>>  ICK_TransparentUnionConversion, ///< Transparent Union Conversions
>>  ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
>>  ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2
>> 6.12.10)
>> +ICK_Zero_Queue_Conversion, ///< Zero constant to queue
>>  ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++
>>  ICK_Incompatible_Pointer_Conversion, ///< C-only conversion between
>> pointers
>>   ///  with incompatible types
>>
>> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
>> URL: 

r290173 - Revert "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand."

2016-12-20 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Dec 20 04:05:04 2016
New Revision: 290173

URL: http://llvm.org/viewvc/llvm-project?rev=290173=rev
Log:
Revert "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand."

This reverts commit r290171. It triggers a bunch of warnings, because
the new enumerator isn't handled in all switches. We want a warning-free
build.

Replied on the commit with more details.

Removed:
cfe/trunk/test/CodeGenOpenCL/null_queue.cl
cfe/trunk/test/SemaOpenCL/null_queue.cl
cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
Modified:
cfe/trunk/include/clang/AST/OperationKinds.def
cfe/trunk/include/clang/Sema/Initialization.h
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/AST/OperationKinds.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OperationKinds.def?rev=290173=290172=290173=diff
==
--- cfe/trunk/include/clang/AST/OperationKinds.def (original)
+++ cfe/trunk/include/clang/AST/OperationKinds.def Tue Dec 20 04:05:04 2016
@@ -321,9 +321,6 @@ CAST_OPERATION(BuiltinFnToFnPtr)
 // Convert a zero value for OpenCL event_t initialization.
 CAST_OPERATION(ZeroToOCLEvent)
 
-// Convert a zero value for OpenCL queue_t initialization.
-CAST_OPERATION(ZeroToOCLQueue)
-
 // Convert a pointer to a different address space.
 CAST_OPERATION(AddressSpaceConversion)
 

Modified: cfe/trunk/include/clang/Sema/Initialization.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Initialization.h?rev=290173=290172=290173=diff
==
--- cfe/trunk/include/clang/Sema/Initialization.h (original)
+++ cfe/trunk/include/clang/Sema/Initialization.h Tue Dec 20 04:05:04 2016
@@ -751,8 +751,6 @@ public:
 SK_StdInitializerListConstructorCall,
 /// \brief Initialize an OpenCL sampler from an integer.
 SK_OCLSamplerInit,
-/// \brief Initialize queue_t from 0.
-SK_OCLZeroQueue,
 /// \brief Passing zero to a function where OpenCL event_t is expected.
 SK_OCLZeroEvent
   };
@@ -1150,9 +1148,6 @@ public:
   /// constant.
   void AddOCLZeroEventStep(QualType T);
 
-  /// \brief Add a step to initialize an OpenCL queue_t from 0.
-  void AddOCLZeroQueueStep(QualType T);
-
   /// \brief Add steps to unwrap a initializer list for a reference around a
   /// single element and rewrap it at the end.
   void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=290173=290172=290173=diff
==
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Tue Dec 20 04:05:04 2016
@@ -83,7 +83,6 @@ namespace clang {
 ICK_TransparentUnionConversion, ///< Transparent Union Conversions
 ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
 ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2 6.12.10)
-ICK_Zero_Queue_Conversion, ///< Zero constant to queue
 ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++
 ICK_Incompatible_Pointer_Conversion, ///< C-only conversion between 
pointers
  ///  with incompatible types

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=290173=290172=290173=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Dec 20 04:05:04 2016
@@ -8340,7 +8340,6 @@ bool IntExprEvaluator::VisitCastExpr(con
   case CK_IntegralComplexToFloatingComplex:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLEvent:
-  case CK_ZeroToOCLQueue:
   case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:
@@ -8838,7 +8837,6 @@ bool ComplexExprEvaluator::VisitCastExpr
   case CK_CopyAndAutoreleaseBlockObject:
   case CK_BuiltinFnToFnPtr:
   case CK_ZeroToOCLEvent:
-  case CK_ZeroToOCLQueue:
   case CK_NonAtomicToAtomic:
   case CK_AddressSpaceConversion:
   case CK_IntToOCLSampler:

Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=290173=290172=290173=diff
==
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ 

Re: r290171 - [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.

2016-12-20 Thread Daniel Jasper via cfe-commits
This triggers a bunch of warnings:

  lib/AST/Expr.cpp:1519:11: error: enumeration value 'CK_ZeroToOCLQueue'
not handled in switch [-Werror,-Wswitch]
  lib/CodeGen/CGExprConstant.cpp:654:13: error: enumeration value
'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]
  lib/Edit/RewriteObjCFoundationAPI.cpp:1000:13: error: enumeration value
'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]
  lib/StaticAnalyzer/Core/ExprEngineC.cpp:314:13: error: enumeration value
'CK_ZeroToOCLQueue' not handled in switch [-Werror,-Wswitch]

Can you please fix or roll back quickly?

On Tue, Dec 20, 2016 at 10:15 AM, Egor Churaev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: echuraev
> Date: Tue Dec 20 03:15:21 2016
> New Revision: 290171
>
> URL: http://llvm.org/viewvc/llvm-project?rev=290171=rev
> Log:
> [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.
>
> Summary: Enabling the compression of CLK_NULL_QUEUE to variable of type
> queue_t.
>
> Reviewers: Anastasia
>
> Subscribers: cfe-commits, yaxunl, bader
>
> Differential Revision: https://reviews.llvm.org/D27569
>
> Added:
> cfe/trunk/test/CodeGenOpenCL/null_queue.cl
> cfe/trunk/test/SemaOpenCL/null_queue.cl
> cfe/trunk/test/SemaOpenCL/queue_t_overload.cl
> Modified:
> cfe/trunk/include/clang/AST/OperationKinds.def
> cfe/trunk/include/clang/Sema/Initialization.h
> cfe/trunk/include/clang/Sema/Overload.h
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/lib/CodeGen/CGExprAgg.cpp
> cfe/trunk/lib/CodeGen/CGExprComplex.cpp
> cfe/trunk/lib/CodeGen/CGExprScalar.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaExprCXX.cpp
> cfe/trunk/lib/Sema/SemaInit.cpp
> cfe/trunk/lib/Sema/SemaOverload.cpp
>
> Modified: cfe/trunk/include/clang/AST/OperationKinds.def
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/AST/OperationKinds.def?rev=290171=290170=290171=diff
> 
> ==
> --- cfe/trunk/include/clang/AST/OperationKinds.def (original)
> +++ cfe/trunk/include/clang/AST/OperationKinds.def Tue Dec 20 03:15:21
> 2016
> @@ -321,6 +321,9 @@ CAST_OPERATION(BuiltinFnToFnPtr)
>  // Convert a zero value for OpenCL event_t initialization.
>  CAST_OPERATION(ZeroToOCLEvent)
>
> +// Convert a zero value for OpenCL queue_t initialization.
> +CAST_OPERATION(ZeroToOCLQueue)
> +
>  // Convert a pointer to a different address space.
>  CAST_OPERATION(AddressSpaceConversion)
>
>
> Modified: cfe/trunk/include/clang/Sema/Initialization.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Initialization.h?rev=290171=290170=290171=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Initialization.h (original)
> +++ cfe/trunk/include/clang/Sema/Initialization.h Tue Dec 20 03:15:21 2016
> @@ -751,6 +751,8 @@ public:
>  SK_StdInitializerListConstructorCall,
>  /// \brief Initialize an OpenCL sampler from an integer.
>  SK_OCLSamplerInit,
> +/// \brief Initialize queue_t from 0.
> +SK_OCLZeroQueue,
>  /// \brief Passing zero to a function where OpenCL event_t is
> expected.
>  SK_OCLZeroEvent
>};
> @@ -1148,6 +1150,9 @@ public:
>/// constant.
>void AddOCLZeroEventStep(QualType T);
>
> +  /// \brief Add a step to initialize an OpenCL queue_t from 0.
> +  void AddOCLZeroQueueStep(QualType T);
> +
>/// \brief Add steps to unwrap a initializer list for a reference
> around a
>/// single element and rewrap it at the end.
>void RewrapReferenceInitList(QualType T, InitListExpr *Syntactic);
>
> Modified: cfe/trunk/include/clang/Sema/Overload.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Sema/Overload.h?rev=290171=290170=290171=diff
> 
> ==
> --- cfe/trunk/include/clang/Sema/Overload.h (original)
> +++ cfe/trunk/include/clang/Sema/Overload.h Tue Dec 20 03:15:21 2016
> @@ -83,6 +83,7 @@ namespace clang {
>  ICK_TransparentUnionConversion, ///< Transparent Union Conversions
>  ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
>  ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2
> 6.12.10)
> +ICK_Zero_Queue_Conversion, ///< Zero constant to queue
>  ICK_C_Only_Conversion, ///< Conversions allowed in C, but not C++
>  ICK_Incompatible_Pointer_Conversion, ///< C-only conversion between
> pointers
>   ///  with incompatible types
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/
> ExprConstant.cpp?rev=290171=290170=290171=diff
> 
> ==
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Dec 

Re: r290080 - [c++1z] P0195R2: Support pack-expansion of using-declarations.

2016-12-19 Thread Daniel Jasper via cfe-commits
Oh, I completely understand, I am doing the same here :)

On Mon, Dec 19, 2016 at 1:38 PM, Renato Golin 
wrote:

> On 19 December 2016 at 12:27, Daniel Jasper  wrote:
> > I don't understand. This *is* a revert of the whole patch.
>
> My bad, your revert hadn't gone through:
>
> http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/1361
>
> Now it's green.
>
> Sorry, we're dealing with 4 different cluster-plucks today.
>
> I hate Mondays.
>
> --renato
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r290080 - [c++1z] P0195R2: Support pack-expansion of using-declarations.

2016-12-19 Thread Daniel Jasper via cfe-commits
I don't understand. This *is* a revert of the whole patch.

On Mon, Dec 19, 2016 at 1:26 PM, Renato Golin <renato.go...@linaro.org>
wrote:

> On 19 December 2016 at 11:28, Daniel Jasper via cfe-commits
> <cfe-commits@lists.llvm.org> wrote:
> > I have reverted this in r290092 as it was leading to Clang crashes on the
> > bots and elsewhere, e.g.:
> > http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/1814
>
> Hi Daniel, Richard,
>
> This is will red on our LNT bot, which started with this commit:
>
> http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/1354
>
> and still has the same failures on the last build:
>
> http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/1360
>
> this is one of the 5 different failures we have in all our bots...
> After so many fix-patches and reverts, I'm not surprised we got into
> this corner of mayhem.
>
> I'd like to ask people a bit more care and worry about the bots.
>
> Most of the time, reverting the whole patch and talking to the bot
> owners is a much better strategy than push-fix a bunch of trail and
> errors.
>
> cheers,
> --renato
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r290094 - clang-format: Slightly tweak the behavior of <<-wrapping.

2016-12-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 19 05:14:23 2016
New Revision: 290094

URL: http://llvm.org/viewvc/llvm-project?rev=290094=rev
Log:
clang-format: Slightly tweak the behavior of <<-wrapping.

Before:
  SomeLongLoggingStatementOrMacro() << "Some long text "
<< some_variable << "\n";

Before:
  SomeLongLoggingStatementOrMacro()
  << "Some long text " << some_variable << "\n";

Short logging statements are already special cased in a different part
of the code.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=290094=290093=290094=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Dec 19 05:14:23 2016
@@ -460,7 +460,7 @@ unsigned ContinuationIndenter::addTokenO
   Penalty += State.NextToken->SplitPenalty;
 
   // Breaking before the first "<<" is generally not desirable if the LHS is
-  // short. Also always add the penalty if the LHS is split over mutliple lines
+  // short. Also always add the penalty if the LHS is split over multiple lines
   // to avoid unnecessary line breaks that just work around this penalty.
   if (NextNonComment->is(tok::lessless) &&
   State.Stack.back().FirstLessLess == 0 &&

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=290094=290093=290094=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Dec 19 05:14:23 2016
@@ -2007,8 +2007,13 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Right.isOneOf(tok::lessless, tok::plus) && Left.isLabelString() &&
   (Right.NextOperator || Right.OperatorIndex != 1))
 return 25;
-  if (Right.is(tok::lessless))
-return 1; // Breaking at a << is really cheap.
+  if (Right.is(tok::lessless)) {
+// Breaking at a << is really cheap.
+if (!Left.is(tok::r_paren) || Right.OperatorIndex > 0)
+  // Slightly prefer to break before the first one in log-like statements.
+  return 2;
+return 1;
+  }
   if (Left.is(TT_ConditionalExpr))
 return prec::Conditional;
   prec::Level Level = Left.getPrecedence();

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290094=290093=290094=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 19 05:14:23 2016
@@ -5092,6 +5092,9 @@ TEST_F(FormatTest, AlignsPipes) {
   " << \n"
   " << ;");
   verifyFormat(
+  "()\n"
+  "<<  << ;");
+  verifyFormat(
   "llvm::outs() << \"a\"\n"
   "\"b\"\n"
   " << 
\"c\";");


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


r290092 - Revert "[c++1z] P0195R2: Support pack-expansion of using-declarations."

2016-12-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 19 04:09:25 2016
New Revision: 290092

URL: http://llvm.org/viewvc/llvm-project?rev=290092=rev
Log:
Revert "[c++1z] P0195R2: Support pack-expansion of using-declarations."

This reverts commit r290080 as it leads to many Clang crashes, e.g.:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/1814

Removed:
cfe/trunk/test/PCH/cxx1z-using-declaration.cpp
cfe/trunk/test/SemaTemplate/cxx1z-using-declaration.cpp
Modified:
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/Basic/DeclNodes.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Sema/Template.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTCommon.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/Parser/cxx1z-using-declaration.cpp
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=290092=290091=290092=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Dec 19 04:09:25 2016
@@ -3140,77 +3140,6 @@ public:
   friend class ASTDeclWriter;
 };
 
-/// Represents a pack of using declarations that a single
-/// using-declarator pack-expanded into.
-///
-/// \code
-/// template struct X : T... {
-///   using T::operator()...;
-///   using T::operator T...;
-/// };
-/// \endcode
-///
-/// In the second case above, the UsingPackDecl will have the name
-/// 'operator T' (which contains an unexpanded pack), but the individual
-/// UsingDecls and UsingShadowDecls will have more reasonable names.
-class UsingPackDecl final
-: public NamedDecl, public Mergeable,
-  private llvm::TrailingObjects {
-  void anchor() override;
-
-  /// The UnresolvedUsingValueDecl or UnresolvedUsingTypenameDecl from
-  /// which this waas instantiated.
-  NamedDecl *InstantiatedFrom;
-
-  /// The number of using-declarations created by this pack expansion.
-  unsigned NumExpansions;
-
-  UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
-ArrayRef UsingDecls)
-  : NamedDecl(UsingPack, DC,
-  InstantiatedFrom ? InstantiatedFrom->getLocation()
-   : SourceLocation(),
-  InstantiatedFrom ? InstantiatedFrom->getDeclName()
-   : DeclarationName()),
-InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
-std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
-getTrailingObjects());
-  }
-
-public:
-  /// Get the using declaration from which this was instantiated. This will
-  /// always be an UnresolvedUsingValueDecl or an UnresolvedUsingTypenameDecl
-  /// that is a pack expansion.
-  NamedDecl *getInstantiatedFromUsingDecl() { return InstantiatedFrom; }
-
-  /// Get the set of using declarations that this pack expanded into. Note that
-  /// some of these may still be unresolved.
-  ArrayRef expansions() const {
-return llvm::makeArrayRef(getTrailingObjects(), 
NumExpansions);
-  }
-
-  static UsingPackDecl *Create(ASTContext , DeclContext *DC,
-   NamedDecl *InstantiatedFrom,
-   ArrayRef UsingDecls);
-
-  static UsingPackDecl *CreateDeserialized(ASTContext , unsigned ID,
-   unsigned NumExpansions);
-
-  SourceRange getSourceRange() const override LLVM_READONLY {
-return InstantiatedFrom->getSourceRange();
-  }
-
-  UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
-  const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
-
-  static bool classof(const Decl *D) { return classofKind(D->getKind()); }
-  static bool classofKind(Kind K) { return K == UsingPack; }
-
-  friend class ASTDeclReader;
-  friend class ASTDeclWriter;
-  friend TrailingObjects;
-};
-
 /// \brief Represents a dependent using declaration which was not marked with
 /// \c typename.
 ///
@@ -3229,9 +3158,6 @@ class UnresolvedUsingValueDecl : public
   /// \brief The source location of the 'using' 

r290090 - clang-format: Fix regression introduced in r290084.

2016-12-19 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 19 02:40:56 2016
New Revision: 290090

URL: http://llvm.org/viewvc/llvm-project?rev=290090=rev
Log:
clang-format: Fix regression introduced in r290084.

We still want to try in linewrap within single elements of a 1-column
list.

After:
  Type *Params[] = {PointerType::getUnqual(FunctionType::get(
Builder.getVoidTy(), Builder.getInt8PtrTy(), false)),
Builder.getInt8PtrTy(),
Builder.getInt32Ty(),
LongType,
LongType,
LongType};

Before:
  No line break in the first element, so column limit violation.

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

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=290090=290089=290090=diff
==
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Mon Dec 19 02:40:56 2016
@@ -92,6 +92,14 @@ unsigned CommaSeparatedList::formatAfter
 
   // Find the best ColumnFormat, i.e. the best number of columns to use.
   const ColumnFormat *Format = getColumnFormat(RemainingCodePoints);
+
+  // Formatting with 1 Column isn't really a column layout, so we don't need 
the
+  // special logic here. We can just avoid bin packing any of the parameters.
+  if (Format && Format->Columns == 1) {
+State.Stack.back().AvoidBinPacking = true;
+return 0;
+  }
+
   // If no ColumnFormat can be used, the braced list would generally be
   // bin-packed. Add a severe penalty to this so that column layouts are
   // preferred if possible.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290090=290089=290090=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 19 02:40:56 2016
@@ -6641,7 +6641,7 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
   "std::this_thread::sleep_for(\n"
   "std::chrono::nanoseconds{ std::chrono::seconds{ 1 } } / 5);",
   ExtraSpaces);
-  verifyFormat("std::vector aaa{\n"
+  verifyFormat("std::vector 
aa{\n"
"aaa,\n"
"aa,\n"
"a,\n"


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


Re: r290084 - clang-format: Allow "single column" list layout even if that violates the

2016-12-19 Thread Daniel Jasper via cfe-commits
Yeah, I just saw that when fixing polly format. I'll take a look.

On Mon, Dec 19, 2016 at 9:05 AM, Tobias Grosser <tob...@grosser.es> wrote:

> Hi Daniel,
>
> this commit introduce an unnecessary string split, which does not seem
> to be an intended result of the formatting style change this commit
> introduced:
>
> BEFORE:
>
> #define SCOP_STAT(NAME, DESC)
>
> llvm::Statistic RejectStatistics[] = {
> SCOP_STAT(CFG, ""),
> SCOP_STAT(InvalidTerminator, "Unsupported terminator instruction"),
> SCOP_STAT(IrreducibleRegion, "Irreducible loops"),
> SCOP_STAT(UndefCond, "Undefined branch condition"),
> SCOP_STAT(NonSimpleMemoryAccess,
>   "Compilated access semantics (volatile or atomic)"),
> };
>
> AFTER:
>
> #define SCOP_STAT(NAME, DESC)
>
> llvm::Statistic RejectStatistics[] = {
> SCOP_STAT(CFG, ""),
> SCOP_STAT(InvalidTerminator, "Unsupported terminator instruction"),
> SCOP_STAT(IrreducibleRegion, "Irreducible loops"),
> SCOP_STAT(UndefCond, "Undefined branch condition"),
> SCOP_STAT(NonSimpleMemoryAccess, "Compilated access semantics
> (volatile or "
>  "atomic)"
>
> As this worked before, this seems to be a regression.
>
> Best,
> Tobias
>
> On Mon, Dec 19, 2016, at 08:26 AM, Daniel Jasper via cfe-commits wrote:
> > Author: djasper
> > Date: Mon Dec 19 01:26:11 2016
> > New Revision: 290084
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=290084=rev
> > Log:
> > clang-format: Allow "single column" list layout even if that violates the
> > column limit.
> >
> > Single-column layout basically means that we format the list with one
> > element per line. Not doing that when there is a column limit violation
> > doesn't change the fact that there is an item that doesn't fit within
> > the column limit.
> >
> > Before (with a column limit of 30):
> >   std::vector a = {
> >   , ,
> >   , ,
> >   aa, ,
> >   aaa};
> >
> > After:
> >   std::vector a = {
> >   ,
> >   ,
> >   ,
> >   ,
> >   aa,
> >   ,
> >   aaa};
> >
> > (and previously we would have formatted like "After" it wasn't for the
> > one
> > item that is too long)
> >
> > Modified:
> > cfe/trunk/lib/Format/FormatToken.cpp
> > cfe/trunk/unittests/Format/FormatTest.cpp
> >
> > Modified: cfe/trunk/lib/Format/FormatToken.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/
> FormatToken.cpp?rev=290084=290083=290084=diff
> > 
> ==
> > --- cfe/trunk/lib/Format/FormatToken.cpp (original)
> > +++ cfe/trunk/lib/Format/FormatToken.cpp Mon Dec 19 01:26:11 2016
> > @@ -273,7 +273,7 @@ void CommaSeparatedList::precomputeForma
> >continue;
> >
> >  // Ignore layouts that are bound to violate the column limit.
> > -if (Format.TotalWidth > Style.ColumnLimit)
> > +if (Format.TotalWidth > Style.ColumnLimit && Columns > 1)
> >continue;
> >
> >  Formats.push_back(Format);
> > @@ -287,7 +287,7 @@ CommaSeparatedList::getColumnFormat(unsi
> > I = Formats.rbegin(),
> > E = Formats.rend();
> > I != E; ++I) {
> > -if (I->TotalWidth <= RemainingCharacters) {
> > +if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) {
> >if (BestFormat && I->LineCount > BestFormat->LineCount)
> >  break;
> >BestFormat = &*I;
> >
> > Modified: cfe/trunk/unittests/Format/FormatTest.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/
> Format/FormatTest.cpp?rev=290084=290083=290084=diff
> > 
> ==
> > --- cfe/trunk/unittests/Format/FormatTest.cpp (original)
> > +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 19 01:26:11 2016
> > @@ -6779,6 +6779,18 @@ TEST_F(FormatTest, FormatsBracedListsInC
> >"  1, 22, 333, , 5, 66,
> >777,\n"
> >"

r290084 - clang-format: Allow "single column" list layout even if that violates the

2016-12-18 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 19 01:26:11 2016
New Revision: 290084

URL: http://llvm.org/viewvc/llvm-project?rev=290084=rev
Log:
clang-format: Allow "single column" list layout even if that violates the
column limit.

Single-column layout basically means that we format the list with one
element per line. Not doing that when there is a column limit violation
doesn't change the fact that there is an item that doesn't fit within
the column limit.

Before (with a column limit of 30):
  std::vector a = {
  , ,
  , ,
  aa, ,
  aaa};

After:
  std::vector a = {
  ,
  ,
  ,
  ,
  aa,
  ,
  aaa};

(and previously we would have formatted like "After" it wasn't for the one
item that is too long)

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

Modified: cfe/trunk/lib/Format/FormatToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.cpp?rev=290084=290083=290084=diff
==
--- cfe/trunk/lib/Format/FormatToken.cpp (original)
+++ cfe/trunk/lib/Format/FormatToken.cpp Mon Dec 19 01:26:11 2016
@@ -273,7 +273,7 @@ void CommaSeparatedList::precomputeForma
   continue;
 
 // Ignore layouts that are bound to violate the column limit.
-if (Format.TotalWidth > Style.ColumnLimit)
+if (Format.TotalWidth > Style.ColumnLimit && Columns > 1)
   continue;
 
 Formats.push_back(Format);
@@ -287,7 +287,7 @@ CommaSeparatedList::getColumnFormat(unsi
I = Formats.rbegin(),
E = Formats.rend();
I != E; ++I) {
-if (I->TotalWidth <= RemainingCharacters) {
+if (I->TotalWidth <= RemainingCharacters || I->Columns == 1) {
   if (BestFormat && I->LineCount > BestFormat->LineCount)
 break;
   BestFormat = &*I;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=290084=290083=290084=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Dec 19 01:26:11 2016
@@ -6779,6 +6779,18 @@ TEST_F(FormatTest, FormatsBracedListsInC
   "  1, 22, 333, , 5, 66, 777,\n"
   "  1, 22, 333, , 5, 66, 777,\n"
   "  1, 22, 333, , 5, 66, 777});");
+
+  // Allow "single-column" layout even if that violates the column limit. There
+  // isn't going to be a better way.
+  verifyFormat("std::vector a = {\n"
+   ",\n"
+   ",\n"
+   ",\n"
+   ",\n"
+   "aa,\n"
+   ",\n"
+   "aaa};",
+   getLLVMStyleWithColumns(30));
 }
 
 TEST_F(FormatTest, PullTrivialFunctionDefinitionsIntoSingleLine) {


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


r289531 - clang-format: Keep string-literal-label + value pairs on a line.

2016-12-13 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Dec 13 05:16:42 2016
New Revision: 289531

URL: http://llvm.org/viewvc/llvm-project?rev=289531=rev
Log:
clang-format: Keep string-literal-label + value pairs on a line.

We have previously done that for <<-operators. This patch also adds
this logic for "," and "+".

Before:
  string v = ": " +  + ": " +
  + ": " + ;
  string v = StrCat(": ", , ": 
",
, ": ", );

After:
  string v = ": " +  +
 ": " +  +
 ": " + ;
  string v = StrCat(": ", ,
": ", ,
": ", );

Modified:
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=289531=289530=289531=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Dec 13 05:16:42 2016
@@ -396,6 +396,21 @@ struct FormatToken {
 }
   }
 
+  /// \brief Returns \c true if this is a string literal that's like a label,
+  /// e.g. ends with "=" or ":".
+  bool isLabelString() const {
+if (!is(tok::string_literal))
+  return false;
+StringRef Content = TokenText;
+if (Content.startswith("\"") || Content.startswith("'"))
+  Content = Content.drop_front(1);
+if (Content.endswith("\"") || Content.endswith("'"))
+  Content = Content.drop_back(1);
+Content = Content.trim();
+return Content.size() > 1 &&
+   (Content.back() == ':' || Content.back() == '=');
+  }
+
   /// \brief Returns actual token start location without leading escaped
   /// newlines and whitespace.
   ///

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=289531=289530=289531=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Dec 13 05:16:42 2016
@@ -1882,8 +1882,7 @@ unsigned TokenAnnotator::splitPenalty(co
   return 100;
   }
 
-  if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next &&
-  Right.Next->is(TT_DictLiteral)))
+  if (Right.is(tok::identifier) && Right.Next && 
Right.Next->is(TT_DictLiteral))
 return 1;
   if (Right.is(tok::l_square)) {
 if (Style.Language == FormatStyle::LK_Proto)
@@ -1999,21 +1998,17 @@ unsigned TokenAnnotator::splitPenalty(co
   if (Left.is(TT_JavaAnnotation))
 return 50;
 
-  if (Right.is(tok::lessless)) {
-if (Left.is(tok::string_literal) &&
-(Right.NextOperator || Right.OperatorIndex != 1)) {
-  StringRef Content = Left.TokenText;
-  if (Content.startswith("\""))
-Content = Content.drop_front(1);
-  if (Content.endswith("\""))
-Content = Content.drop_back(1);
-  Content = Content.trim();
-  if (Content.size() > 1 &&
-  (Content.back() == ':' || Content.back() == '='))
-return 25;
-}
+  if (Left.isOneOf(tok::plus, tok::comma) && Left.Previous &&
+  Left.Previous->isLabelString() &&
+  (Left.NextOperator || Left.OperatorIndex != 1))
+return 100;
+  if (Left.is(tok::comma))
+return 1;
+  if (Right.isOneOf(tok::lessless, tok::plus) && Left.isLabelString() &&
+  (Right.NextOperator || Right.OperatorIndex != 1))
+return 25;
+  if (Right.is(tok::lessless))
 return 1; // Breaking at a << is really cheap.
-  }
   if (Left.is(TT_ConditionalExpr))
 return prec::Conditional;
   prec::Level Level = Left.getPrecedence();
@@ -2631,7 +2626,8 @@ void TokenAnnotator::printDebugInfo(cons
  << " FakeLParens=";
 for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
   llvm::errs() << Tok->FakeLParens[i] << "/";
-llvm::errs() << " FakeRParens=" << Tok->FakeRParens << "\n";
+llvm::errs() << " FakeRParens=" << Tok->FakeRParens;
+llvm::errs() << " Text='" << Tok->TokenText << "'\n";
 if (!Tok->Next)
   assert(Tok == Line.Last);
 Tok = Tok->Next;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=289531=289530=289531=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 13 05:16:42 2016
@@ 

r289525 - clang-format: Improve braced-list detection.

2016-12-13 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Dec 13 04:05:03 2016
New Revision: 289525

URL: http://llvm.org/viewvc/llvm-project?rev=289525=rev
Log:
clang-format: Improve braced-list detection.

Before:
  vector v { 12 }
  GUARDED_BY(mutex);

After:
  vector v{12} GUARDED_BY(mutex);

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

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=289525=289524=289525=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Dec 13 04:05:03 2016
@@ -360,8 +360,6 @@ void UnwrappedLineParser::calculateBrace
   // BlockKind later if we parse a braced list (where all blocks
   // inside are by default braced lists), or when we explicitly detect
   // blocks (for example while parsing lambdas).
-  //
-  // We exclude + and - as they can be ObjC visibility modifiers.
   ProbablyBracedList =
   (Style.Language == FormatStyle::LK_JavaScript &&
NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in,
@@ -369,6 +367,8 @@ void UnwrappedLineParser::calculateBrace
   NextTok->isOneOf(tok::comma, tok::period, tok::colon,
tok::r_paren, tok::r_square, tok::l_brace,
tok::l_square, tok::l_paren, tok::ellipsis) ||
+  (NextTok->is(tok::identifier) &&
+   !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) ||
   (NextTok->is(tok::semi) &&
(!ExpectClassBody || LBraceStack.size() != 1)) ||
   (NextTok->isBinaryOperator() && !NextIsObjCMethod);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=289525=289524=289525=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 13 04:05:03 2016
@@ -6504,6 +6504,19 @@ TEST_F(FormatTest, LayoutCxx11BraceIniti
"};");
   verifyFormat("#define A {a, a},");
 
+  // Cases where distinguising braced lists and blocks is hard.
+  verifyFormat("vector v{12} GUARDED_BY(mutex);");
+  verifyFormat("void f() {\n"
+   "  return; // comment\n"
+   "}\n"
+   "SomeType t;");
+  verifyFormat("void f() {\n"
+   "  if (a) {\n"
+   "f();\n"
+   "  }\n"
+   "}\n"
+   "SomeType t;");
+
   // In combination with BinPackArguments = false.
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackArguments = false;


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


r289428 - clang-format: Separate out a language kind for ObjC.

2016-12-12 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Mon Dec 12 06:42:29 2016
New Revision: 289428

URL: http://llvm.org/viewvc/llvm-project?rev=289428=rev
Log:
clang-format: Separate out a language kind for ObjC.

While C(++) and ObjC are generally formatted the same way and can be
mixed, people might want to choose different styles based on the
language. This patch recognizes .m and .mm files as ObjC and also
implements a very crude detection of whether or not a .h file contains
ObjC code. This can be improved over time.

Also move most of the ObjC tests into their own test file to keep file
size maintainable.

Added:
cfe/trunk/unittests/Format/FormatTestObjC.cpp
Modified:
cfe/trunk/include/clang/Format/Format.h
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/FormatTokenLexer.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/tools/clang-format/ClangFormat.cpp
cfe/trunk/unittests/Format/CMakeLists.txt
cfe/trunk/unittests/Format/FormatTest.cpp
cfe/trunk/unittests/Tooling/ReplacementTest.h

Modified: cfe/trunk/include/clang/Format/Format.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=289428=289427=289428=diff
==
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Mon Dec 12 06:42:29 2016
@@ -465,6 +465,8 @@ struct FormatStyle {
 LK_Java,
 /// Should be used for JavaScript.
 LK_JavaScript,
+/// Should be used for ObjC code.
+LK_ObjC,
 /// Should be used for Protocol Buffers
 /// (https://developers.google.com/protocol-buffers/).
 LK_Proto,
@@ -852,13 +854,16 @@ extern const char *StyleOptionHelpDescri
 /// == "file".
 /// \param[in] FallbackStyle The name of a predefined style used to fallback to
 /// in case the style can't be determined from \p StyleName.
+/// \param[in] Code The actual code to be formatted. Used to determine the
+/// language if the filename isn't sufficient.
 /// \param[in] FS The underlying file system, in which the file resides. By
 /// default, the file system is the real file system.
 ///
 /// \returns FormatStyle as specified by ``StyleName``. If no style could be
 /// determined, the default is LLVM Style (see ``getLLVMStyle()``).
 FormatStyle getStyle(StringRef StyleName, StringRef FileName,
- StringRef FallbackStyle, vfs::FileSystem *FS = nullptr);
+ StringRef FallbackStyle, StringRef Code = "",
+ vfs::FileSystem *FS = nullptr);
 
 // \brief Returns a string representation of ``Language``.
 inline StringRef getLanguageName(FormatStyle::LanguageKind Language) {

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=289428=289427=289428=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Dec 12 06:42:29 2016
@@ -560,6 +560,7 @@ unsigned ContinuationIndenter::addTokenO
   // and we need to avoid bin packing there.
   bool NestedBlockSpecialCase =
   Style.Language != FormatStyle::LK_Cpp &&
+  Style.Language != FormatStyle::LK_ObjC &&
   Current.is(tok::r_brace) && State.Stack.size() > 1 &&
   State.Stack[State.Stack.size() - 2].NestedBlockInlined;
   if (!NestedBlockSpecialCase)

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=289428=289427=289428=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon Dec 12 06:42:29 2016
@@ -52,6 +52,7 @@ template <> struct ScalarEnumerationTrai
 IO.enumCase(Value, "Cpp", FormatStyle::LK_Cpp);
 IO.enumCase(Value, "Java", FormatStyle::LK_Java);
 IO.enumCase(Value, "JavaScript", FormatStyle::LK_JavaScript);
+IO.enumCase(Value, "ObjC", FormatStyle::LK_ObjC);
 IO.enumCase(Value, "Proto", FormatStyle::LK_Proto);
 IO.enumCase(Value, "TableGen", FormatStyle::LK_TableGen);
   }
@@ -623,6 +624,8 @@ FormatStyle getGoogleStyle(FormatStyle::
   } else if (Language == FormatStyle::LK_Proto) {
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
+  } else if (Language == FormatStyle::LK_ObjC) {
+GoogleStyle.ColumnLimit = 100;
   }
 
   return GoogleStyle;
@@ -1861,6 +1864,8 @@ static FormatStyle::LanguageKind getLang
 return FormatStyle::LK_Java;
   if (FileName.endswith_lower(".js") || FileName.endswith_lower(".ts"))
 return FormatStyle::LK_JavaScript; // JavaScript or TypeScript.
+  if (FileName.endswith(".m") || FileName.endswith(".mm"))
+return FormatStyle::LK_ObjC;
   if 

Re: r288449 - Recover better from an incompatible .pcm file being provided by -fmodule-file=.

2016-12-04 Thread Daniel Jasper via cfe-commits
This is unfortunately causing problems as is, as it can change the
diagnostic that's created when the include of a module with config-mismatch
is inside a namespace. I have tried to fix this for a bit, but I am not
sure what the right solution is. For now, I have reverted this in r288626
and left the details of my investigation on that patch description.

On Fri, Dec 2, 2016 at 2:52 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rsmith
> Date: Thu Dec  1 19:52:28 2016
> New Revision: 288449
>
> URL: http://llvm.org/viewvc/llvm-project?rev=288449=rev
> Log:
> Recover better from an incompatible .pcm file being provided by
> -fmodule-file=.
> We try to include the headers of the module textually in this case, still
> enforcing the modules semantic rules. In order to make that work, we need
> to
> still track that we're entering and leaving the module. Also, if the
> module was
> also marked as unavailable (perhaps because it was missing a file), we
> shouldn't mark the module unavailable -- we don't need the module to be
> complete if we're going to enter it textually.
>
> Added:
> cfe/trunk/test/Modules/config-mismatch.cpp
> Modified:
> cfe/trunk/include/clang/Lex/ModuleLoader.h
> cfe/trunk/lib/Frontend/CompilerInstance.cpp
> cfe/trunk/lib/Lex/PPDirectives.cpp
>
> Modified: cfe/trunk/include/clang/Lex/ModuleLoader.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/
> clang/Lex/ModuleLoader.h?rev=288449=288448=288449=diff
> 
> ==
> --- cfe/trunk/include/clang/Lex/ModuleLoader.h (original)
> +++ cfe/trunk/include/clang/Lex/ModuleLoader.h Thu Dec  1 19:52:28 2016
> @@ -31,13 +31,22 @@ typedef ArrayRef  /// \brief Describes the result of attempting to load a module.
>  class ModuleLoadResult {
> -  llvm::PointerIntPair Storage;
> -
>  public:
> -  ModuleLoadResult() : Storage() { }
> +  enum LoadResultKind {
> +// We either succeeded or failed to load the named module.
> +Normal,
> +// The module exists, but does not actually contain the named
> submodule.
> +// This should only happen if the named submodule was inferred from an
> +// umbrella directory, but not actually part of the umbrella header.
> +MissingExpected,
> +// The module exists but cannot be imported due to a configuration
> mismatch.
> +ConfigMismatch
> +  };
> +  llvm::PointerIntPair Storage;
>
> -  ModuleLoadResult(Module *module, bool missingExpected)
> -: Storage(module, missingExpected) { }
> +  ModuleLoadResult() : Storage() { }
> +  ModuleLoadResult(Module *M) : Storage(M, Normal) {}
> +  ModuleLoadResult(LoadResultKind Kind) : Storage(nullptr, Kind) {}
>
>operator Module *() const { return Storage.getPointer(); }
>
> @@ -45,7 +54,11 @@ public:
>/// actually a submodule that we expected to see (based on implying the
>/// submodule from header structure), but didn't materialize in the
> actual
>/// module.
> -  bool isMissingExpected() const { return Storage.getInt(); }
> +  bool isMissingExpected() const { return Storage.getInt() ==
> MissingExpected; }
> +
> +  /// \brief Determines whether the module failed to load due to a
> configuration
> +  /// mismatch with an explicitly-named .pcm file from the command line.
> +  bool isConfigMismatch() const { return Storage.getInt() ==
> ConfigMismatch; }
>  };
>
>  /// \brief Abstract interface for a module loader.
>
> Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Frontend/CompilerInstance.cpp?rev=288449=288448=288449=diff
> 
> ==
> --- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Dec  1 19:52:28 2016
> @@ -1393,8 +1393,21 @@ bool CompilerInstance::loadModuleFile(St
>  if (Module *M = CI.getPreprocessor()
>  .getHeaderSearchInfo()
>  .getModuleMap()
> -.findModule(II->getName()))
> +.findModule(II->getName())) {
>M->HasIncompatibleModuleFile = true;
> +
> +  // Mark module as available if the only reason it was
> unavailable
> +  // was missing headers.
> +  SmallVector Stack;
> +  Stack.push_back(M);
> +  while (!Stack.empty()) {
> +Module *Current = Stack.pop_back_val();
> +if (Current->IsMissingRequirement) continue;
> +Current->IsAvailable = true;
> +Stack.insert(Stack.end(),
> + Current->submodule_begin(),
> Current->submodule_end());
> +  }
> +}
>}
>LoadedModules.clear();
>  }
> @@ -1498,7 +1511,7 @@ CompilerInstance::loadModule(SourceLocat
>if (Module && Module->HasIncompatibleModuleFile) {
>  

r288626 - Revert "Recover better from an incompatible .pcm file being provided by -fmodule-file=. We try to include the headers of the module textually in this case, still enforcing the modules semant

2016-12-04 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sun Dec  4 16:34:37 2016
New Revision: 288626

URL: http://llvm.org/viewvc/llvm-project?rev=288626=rev
Log:
Revert "Recover better from an incompatible .pcm file being provided by 
-fmodule-file=. We try to include the headers of the module textually in this 
case, still enforcing the modules semantic rules. In order to make that work, 
we need to still track that we're entering and leaving the module. Also, if the 
module was also marked as unavailable (perhaps because it was missing a file), 
we shouldn't mark the module unavailable -- we don't need the module to be 
complete if we're going to enter it textually."

This reverts commit r288449.

I believe that this is currently faulty wrt. modules being imported
inside namespaces. Adding these lines to the new test:

  namespace n {
  #include "foo.h"
  }

Makes it break with

  fatal error: import of module 'M' appears within namespace 'n'

However, I believe it should fail with

  error: redundant #include of module 'M' appears within namespace 'n'

I have tracked this down to us now inserting a tok::annot_module_begin
instead of a tok::annot_module_include in
Preprocessor::HandleIncludeDirective() and then later in
Parser::parseMisplacedModuleImport(), we hit the code path for
tok::annot_module_begin, which doesn't set FromInclude of
checkModuleImportContext to true (thus leading to the "wrong"
diagnostic).

Removed:
cfe/trunk/test/Modules/config-mismatch.cpp
Modified:
cfe/trunk/include/clang/Lex/ModuleLoader.h
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/include/clang/Lex/ModuleLoader.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleLoader.h?rev=288626=288625=288626=diff
==
--- cfe/trunk/include/clang/Lex/ModuleLoader.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleLoader.h Sun Dec  4 16:34:37 2016
@@ -31,22 +31,13 @@ typedef ArrayRefgetName())) {
+.findModule(II->getName()))
   M->HasIncompatibleModuleFile = true;
-
-  // Mark module as available if the only reason it was unavailable
-  // was missing headers.
-  SmallVector Stack;
-  Stack.push_back(M);
-  while (!Stack.empty()) {
-Module *Current = Stack.pop_back_val();
-if (Current->IsMissingRequirement) continue;
-Current->IsAvailable = true;
-Stack.insert(Stack.end(),
- Current->submodule_begin(), Current->submodule_end());
-  }
-}
   }
   LoadedModules.clear();
 }
@@ -1511,7 +1498,7 @@ CompilerInstance::loadModule(SourceLocat
   if (Module && Module->HasIncompatibleModuleFile) {
 // We tried and failed to load a module file for this module. Fall
 // back to textual inclusion for its headers.
-return ModuleLoadResult::ConfigMismatch;
+return ModuleLoadResult(nullptr, /*missingExpected*/true);
   }
 
   getDiagnostics().Report(ModuleNameLoc, diag::err_module_build_disabled)
@@ -1718,7 +1705,7 @@ CompilerInstance::loadModule(SourceLocat
 << Module->getFullModuleName()
 << SourceRange(Path.front().second, Path.back().second);
 
- 

r288120 - clang-format: Wrap complex binary expressions on the RHS of a comma.

2016-11-29 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Nov 29 03:40:32 2016
New Revision: 288120

URL: http://llvm.org/viewvc/llvm-project?rev=288120=rev
Log:
clang-format: Wrap complex binary expressions on the RHS of a comma.

Specifically, if the RHS of a comma is a complex binary expression and
spans multiple lines, insert a line break before it. This usually is
often more readable compared to producing a hanging indent. See changes
in FormatTest.cpp for examples.

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=288120=288119=288120=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Nov 29 03:40:32 2016
@@ -866,7 +866,7 @@ void ContinuationIndenter::moveStatePast
 // Exclude relational operators, as there, it is always more desirable to
 // have the LHS 'left' of the RHS.
 if (Previous && Previous->getPrecedence() != prec::Assignment &&
-Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr) &&
+Previous->isOneOf(TT_BinaryOperator, TT_ConditionalExpr, tok::comma) &&
 Previous->getPrecedence() != prec::Relational) {
   bool BreakBeforeOperator =
   Previous->is(tok::lessless) ||

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=288120=288119=288120=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Nov 29 03:40:32 2016
@@ -4577,12 +4577,13 @@ TEST_F(FormatTest, ParenthesesAndOperand
 
 TEST_F(FormatTest, BreaksConditionalExpressions) {
   verifyFormat(
-  "(, aa\n"
-  "   ? a\n"
-  "   : aa);");
-  verifyFormat(
-  "(, aaa ? 
a\n"
-  "   : 
aaa);");
+  "(,\n"
+  " aa ? a\n"
+  ": 
aa);");
+  verifyFormat(
+  "(,\n"
+  " aaa ? a\n"
+  " : aaa);");
   verifyFormat(
   "aa( ? (aa)\n"
   ": a);");
@@ -4632,11 +4633,12 @@ TEST_F(FormatTest, BreaksConditionalExpr
"   ? \n"
"   : ;");
   verifyFormat("unsigned Indent =\n"
-   "format(TheLine.First, IndentForLevel[TheLine.Level] >= 0\n"
-   "  ? 
IndentForLevel[TheLine.Level]\n"
-   "  : TheLine * 2,\n"
+   "format(TheLine.First,\n"
+   "   IndentForLevel[TheLine.Level] >= 0\n"
+   "   ? IndentForLevel[TheLine.Level]\n"
+   "   : TheLine * 2,\n"
"   TheLine.InPPDirective, PreviousEndOfLineColumn);",
-   getLLVMStyleWithColumns(70));
+   getLLVMStyleWithColumns(60));
   verifyFormat("bool aa = a //\n"
"  ? aaa\n"
"  : bbb //\n"
@@ -4711,13 +4713,14 @@ TEST_F(FormatTest, BreaksConditionalExpr
   Style.BreakBeforeTernaryOperators = false;
   Style.ColumnLimit = 70;
   verifyFormat(
-  "(, aa ?\n"
-  "   a :\n"
-  "   aa);",
+  "(,\n"
+  " aa ? a :\n"
+  "  aa);",
   Style);
   verifyFormat(
-  "(, aaa ? aaa 
:\n"
-  " aaa);",
+  "(,\n"
+  " aaa ? aaa :\n"
+  "   aaa);",
   Style);
   verifyFormat(
   "aa( ? (aa) :\n"
@@ -4773,13 +4776,13 @@ 

r288121 - clang-format: [JS] Properly format dict literals that skip labels.

2016-11-29 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Nov 29 03:40:36 2016
New Revision: 288121

URL: http://llvm.org/viewvc/llvm-project?rev=288121=rev
Log:
clang-format: [JS] Properly format dict literals that skip labels.

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=288121=288120=288121=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Nov 29 03:40:36 2016
@@ -442,6 +442,9 @@ private:
   Style.Language == FormatStyle::LK_JavaScript)
 Left->Type = TT_DictLiteral;
 }
+if (CurrentToken->is(tok::comma) &&
+Style.Language == FormatStyle::LK_JavaScript)
+  Left->Type = TT_DictLiteral;
 if (!consumeToken())
   return false;
   }

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=288121=288120=288121=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Nov 29 03:40:36 2016
@@ -259,6 +259,13 @@ TEST_F(FormatTestJS, ContainerLiterals)
"  b: b,\n"
"  'c': c,\n"
"};");
+
+  // Dict literals can skip the label names.
+  verifyFormat("var x = {\n"
+   "  aaa,\n"
+   "  aaa,\n"
+   "  aaa,\n"
+   "};");
 }
 
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {


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


r288119 - clang-format: Fix unnnecessary line break.

2016-11-29 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Tue Nov 29 03:40:01 2016
New Revision: 288119

URL: http://llvm.org/viewvc/llvm-project?rev=288119=rev
Log:
clang-format: Fix unnnecessary line break.

Before:
  aa((,
  ), //
 ,
 a);

After:
  aa((,
  ), //
 , a);

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=288119=288118=288119=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Nov 29 03:40:01 2016
@@ -523,7 +523,8 @@ unsigned ContinuationIndenter::addTokenO
   Style.ContinuationIndentWidth;
   }
 
-  if ((Previous.isOneOf(tok::comma, tok::semi) &&
+  if ((PreviousNonComment &&
+   PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
!State.Stack.back().AvoidBinPacking) ||
   Previous.is(TT_BinaryOperator))
 State.Stack.back().BreakBeforeParameter = false;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=288119=288118=288119=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Nov 29 03:40:01 2016
@@ -1137,6 +1137,12 @@ TEST_F(FormatTest, KeepsParameterWithTra
 format("SomeFunction(a, // comment\n"
"  b,\n"
"  c); // comment"));
+  EXPECT_EQ("aa((,\n"
+"), //\n"
+"   , b);",
+format("aa((,\n"
+   "), //\n"
+   ", b);"));
 }
 
 TEST_F(FormatTest, RemovesTrailingWhitespaceOfComments) {


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


r286715 - clang-format: Support ObjC selectors with unnamed parameters.

2016-11-11 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Sat Nov 12 01:38:22 2016
New Revision: 286715

URL: http://llvm.org/viewvc/llvm-project?rev=286715=rev
Log:
clang-format: Support ObjC selectors with unnamed parameters.

This fixes llvm.org/PR28063.

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=286715=286714=286715=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Sat Nov 12 01:38:22 2016
@@ -177,6 +177,9 @@ bool ContinuationIndenter::mustBreak(con
   ((Style.AllowShortFunctionsOnASingleLine != FormatStyle::SFS_All) ||
Style.BreakConstructorInitializersBeforeComma || Style.ColumnLimit != 
0))
 return true;
+  if (Current.is(TT_ObjCMethodExpr) && !Previous.is(TT_SelectorName) &&
+  State.Line->startsWith(TT_ObjCMethodSpecifier))
+return true;
   if (Current.is(TT_SelectorName) && State.Stack.back().ObjCSelectorNameFound 
&&
   State.Stack.back().BreakBeforeParameter)
 return true;
@@ -671,6 +674,8 @@ unsigned ContinuationIndenter::getNewLin
   return State.Stack.back().ColonPos - NextNonComment->ColumnWidth;
 return State.Stack.back().Indent;
   }
+  if (NextNonComment->is(tok::colon) && NextNonComment->is(TT_ObjCMethodExpr))
+return State.Stack.back().ColonPos;
   if (NextNonComment->is(TT_ArraySubscriptLSquare)) {
 if (State.Stack.back().StartOfArraySubscripts != 0)
   return State.Stack.back().StartOfArraySubscripts;

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=286715=286714=286715=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Nov 12 01:38:22 2016
@@ -316,8 +316,8 @@ private:
 (Contexts.back().CanBeExpression || Contexts.back().IsExpression ||
  Contexts.back().InTemplateArgument);
 
-bool StartsObjCMethodExpr = !CppArrayTemplates &&
-Style.Language == FormatStyle::LK_Cpp &&
+bool StartsObjCMethodExpr =
+!CppArrayTemplates && Style.Language == FormatStyle::LK_Cpp &&
 Contexts.back().CanBeExpression && Left->isNot(TT_LambdaLSquare) &&
 CurrentToken->isNot(tok::l_brace) &&
 (!Parent ||
@@ -519,12 +519,21 @@ private:
   } else if (Contexts.back().ColonIsObjCMethodExpr ||
  Line.startsWith(TT_ObjCMethodSpecifier)) {
 Tok->Type = TT_ObjCMethodExpr;
-Tok->Previous->Type = TT_SelectorName;
-if (Tok->Previous->ColumnWidth >
-Contexts.back().LongestObjCSelectorName)
-  Contexts.back().LongestObjCSelectorName = Tok->Previous->ColumnWidth;
-if (!Contexts.back().FirstObjCSelectorName)
-  Contexts.back().FirstObjCSelectorName = Tok->Previous;
+const FormatToken *BeforePrevious = Tok->Previous->Previous;
+if (!BeforePrevious ||
+!(BeforePrevious->is(TT_CastRParen) ||
+  (BeforePrevious->is(TT_ObjCMethodExpr) &&
+   BeforePrevious->is(tok::colon))) ||
+BeforePrevious->is(tok::r_square) ||
+Contexts.back().LongestObjCSelectorName == 0) {
+  Tok->Previous->Type = TT_SelectorName;
+  if (Tok->Previous->ColumnWidth >
+  Contexts.back().LongestObjCSelectorName)
+Contexts.back().LongestObjCSelectorName =
+Tok->Previous->ColumnWidth;
+  if (!Contexts.back().FirstObjCSelectorName)
+Contexts.back().FirstObjCSelectorName = Tok->Previous;
+}
   } else if (Contexts.back().ColonIsForRangeExpr) {
 Tok->Type = TT_RangeBasedForLoopColon;
   } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
@@ -1224,6 +1233,13 @@ private:
 if (!LeftOfParens)
   return false;
 
+// Certain token types inside the parentheses mean that this can't be a
+// cast.
+for (const FormatToken *Token = Tok.MatchingParen->Next; Token != 
+ Token = Token->Next)
+  if (Token->is(TT_BinaryOperator))
+return false;
+
 // If the following token is an identifier or 'this', this is a cast. All
 // cases where this can be something else are handled above.
 if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
@@ -2497,10 +2513,13 @@ bool TokenAnnotator::canBreakBefore(cons
 return !Style.BreakBeforeTernaryOperators;
   if (Right.is(TT_InheritanceColon))
 return true;
+  if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
+  Left.isNot(TT_SelectorName))
+return true;
   if (Right.is(tok::colon) &&
   

[PATCH] D26274: clang-format: [JS] do not break after declare namespace.

2016-11-10 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D26274



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


[PATCH] D26163: [clang-format] Fix PR30527: Regression when clang-format insert spaces in [] when in template

2016-11-10 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you!


https://reviews.llvm.org/D26163



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


r286367 - clang-format: [TypeScript] Fix bug in handling of non-null operator.

2016-11-09 Thread Daniel Jasper via cfe-commits
Author: djasper
Date: Wed Nov  9 08:12:55 2016
New Revision: 286367

URL: http://llvm.org/viewvc/llvm-project?rev=286367=rev
Log:
clang-format: [TypeScript] Fix bug in handling of non-null operator.

Before:
  var i = x!-1;

After:
  var i = x! - 1;

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=286367=286366=286367=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Nov  9 08:12:55 2016
@@ -1311,7 +1311,13 @@ private:
 
   TokenType determinePlusMinusCaretUsage(const FormatToken ) {
 const FormatToken *PrevToken = Tok.getPreviousNonComment();
-if (!PrevToken || PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
+if (!PrevToken)
+  return TT_UnaryOperator;
+
+if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator) &&
+!PrevToken->is(tok::exclaim))
+  // There aren't any trailing unary operators except for TypeScript's
+  // non-null operator (!). Thus, this must be squence of leading 
operators.
   return TT_UnaryOperator;
 
 // Use heuristics to recognize unary operators.

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=286367=286366=286367=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Nov  9 08:12:55 2016
@@ -1462,6 +1462,7 @@ TEST_F(FormatTestJS, NonNullAssertionOpe
   verifyFormat("let x = !foo;\n");
   verifyFormat("let x = foo[0]!;\n");
   verifyFormat("let x = (foo)!;\n");
+  verifyFormat("let x = foo! - 1;\n");
   verifyFormat("let x = {foo: 1}!;\n");
 }
 


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


Re: r286243 - [clang-format] Remove (SourceManager, FileID) variants

2016-11-08 Thread Daniel Jasper via cfe-commits
Fixed in r286279.

On Tue, Nov 8, 2016 at 10:45 AM, Galina Kistanova <gkistan...@gmail.com>
wrote:

> Hello Daniel,
>
> This commit broke at least one of our builders:
> http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/234
>
> Please have a look at this?
>
> Thanks
>
> Galina
>
> On Tue, Nov 8, 2016 at 8:11 AM, Daniel Jasper via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: djasper
>> Date: Tue Nov  8 10:11:33 2016
>> New Revision: 286243
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=286243=rev
>> Log:
>> [clang-format] Remove (SourceManager, FileID) variants
>>
>> In Format, remove the reformat() and clean() functions taking a
>> SourceManager
>> and a FileID. Keep the versions taking StringRef Code.
>>
>> - there was duplicated functionality
>> - the FileID versions were harder to use
>> - the clean() version is dead code anyways
>>
>> Patch by Krasimir Georgiev. Thank you.
>>
>> Modified:
>> cfe/trunk/include/clang/Format/Format.h
>> cfe/trunk/lib/Format/Format.cpp
>> cfe/trunk/lib/Index/CommentToXML.cpp
>>
>> Modified: cfe/trunk/include/clang/Format/Format.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
>> Format/Format.h?rev=286243=286242=286243=diff
>> 
>> ==
>> --- cfe/trunk/include/clang/Format/Format.h (original)
>> +++ cfe/trunk/include/clang/Format/Format.h Tue Nov  8 10:11:33 2016
>> @@ -794,7 +794,7 @@ llvm::Expected
>>  cleanupAroundReplacements(StringRef Code, const tooling::Replacements
>> ,
>>const FormatStyle );
>>
>> -/// \brief Reformats the given \p Ranges in the file \p ID.
>> +/// \brief Reformats the given \p Ranges in \p Code.
>>  ///
>>  /// Each range is extended on either end to its next bigger logic unit,
>> i.e.
>>  /// everything that might influence its formatting or might be
>> influenced by its
>> @@ -806,31 +806,15 @@ cleanupAroundReplacements(StringRef Code
>>  /// If ``IncompleteFormat`` is non-null, its value will be set to true
>> if any
>>  /// of the affected ranges were not formatted due to a non-recoverable
>> syntax
>>  /// error.
>> -tooling::Replacements reformat(const FormatStyle ,
>> -   SourceManager , FileID ID,
>> -   ArrayRef Ranges,
>> -   bool *IncompleteFormat = nullptr);
>> -
>> -/// \brief Reformats the given \p Ranges in \p Code.
>> -///
>> -/// Otherwise identical to the reformat() function using a file ID.
>>  tooling::Replacements reformat(const FormatStyle , StringRef Code,
>> ArrayRef Ranges,
>> StringRef FileName = "",
>> bool *IncompleteFormat = nullptr);
>>
>> -/// \brief Clean up any erroneous/redundant code in the given \p Ranges
>> in the
>> -/// file \p ID.
>> -///
>> -/// Returns the ``Replacements`` that clean up all \p Ranges in the file
>> \p ID.
>> -tooling::Replacements cleanup(const FormatStyle ,
>> -  SourceManager , FileID ID,
>> -  ArrayRef Ranges);
>> -
>>  /// \brief Clean up any erroneous/redundant code in the given \p Ranges
>> in \p
>>  /// Code.
>>  ///
>> -/// Otherwise identical to the cleanup() function using a file ID.
>> +/// Returns the ``Replacements`` that clean up all \p Ranges in \p Code.
>>  tooling::Replacements cleanup(const FormatStyle , StringRef Code,
>>ArrayRef Ranges,
>>StringRef FileName = "");
>>
>> Modified: cfe/trunk/lib/Format/Format.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/For
>> mat.cpp?rev=286243=286242=286243=diff
>> 
>> ==
>> --- cfe/trunk/lib/Format/Format.cpp (original)
>> +++ cfe/trunk/lib/Format/Format.cpp Tue Nov  8 10:11:33 2016
>> @@ -1719,18 +1719,6 @@ cleanupAroundReplacements(StringRef Code
>>return processReplacements(Cleanup, Code, NewReplaces, Style);
>>  }
>>
>> -tooling::Replacements reformat(const FormatStyle , SourceManager
>> ,
>> -   FileID ID, ArrayRef
>> Ranges,
>> -   bool *IncompleteFor

  1   2   3   4   5   6   7   >