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&view=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&r1=303036&r2=303037&view=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&r1=303036&r2=303037&view=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&r1=303036&r2=303037&view=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&r1=303036&r2=303037&view=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&r1=303036&r2=303037&view=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();
+e

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&view=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&r1=302964&r2=302965&view=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&r1=302964&r2=302965&view=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&r1=302964&r2=302965&view=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&r1=302964&r2=302965&view=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/llv

r303038 - clang-format: [JS] fix non-null assertion operator recognition.

2017-05-15 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Mon May 15 03:15:53 2017
New Revision: 303038

URL: http://llvm.org/viewvc/llvm-project?rev=303038&view=rev
Log:
clang-format: [JS] fix non-null assertion operator recognition.

Summary:
`getIdentifierInfo()` includes all keywords, whereas non-null assertion
operators should only be recognized after non-keywords or pseudo keywords.
Ideally this should list all tokens that clang-format recognizes as a keyword,
but that are pseudo or no keywords in JS. For the time being, just recognize
the specific bits users ran into (`namespace` in this case).

Reviewers: djasper

Subscribers: klimek

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

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=303038&r1=303037&r2=303038&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 15 03:15:53 2017
@@ -1034,9 +1034,9 @@ private:
 if (Style.Language == FormatStyle::LK_JavaScript) {
   if (Current.is(tok::exclaim)) {
 if (Current.Previous &&
-(Current.Previous->Tok.getIdentifierInfo() ||
- Current.Previous->isOneOf(tok::identifier, tok::r_paren,
-   tok::r_square, tok::r_brace) ||
+(Current.Previous->isOneOf(tok::identifier, tok::kw_namespace,
+   tok::r_paren, tok::r_square,
+   tok::r_brace) ||
  Current.Previous->Tok.isLiteral())) {
   Current.Type = TT_JsNonNullAssertion;
   return;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=303038&r1=303037&r2=303038&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon May 15 03:15:53 2017
@@ -1800,6 +1800,7 @@ TEST_F(FormatTestJS, NonNullAssertionOpe
   ".foo()!;\n",
   getGoogleJSStyleWithColumns(20));
   verifyFormat("let x = namespace!;\n");
+  verifyFormat("return !!x;\n");
 }
 
 TEST_F(FormatTestJS, Conditional) {


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


[PATCH] D31745: [OpenCL] Added diagnostic for implicit declaration of function in OpenCL

2017-05-15 Thread Egor Churaev via Phabricator via cfe-commits
echuraev updated this revision to Diff 98958.
echuraev added a comment.

I disabled adding note diagnostic for OpenCL. Addition function to dictionary 
occurs in function CurrectTypo. In this function take place creation of 
consumer by calling function makeTypoCorrectionConsumer. The function do some 
checks and next create consumer by the following code:

  auto Consumer = llvm::make_unique(
   *this, TypoName, LookupKind, S, SS, std::move(CCC), MemberContext,
   EnteringContext);

In constructor TypoCorrectionConsumer occurs adding correction to dictionary 
(ValidatedCorrections).


https://reviews.llvm.org/D31745

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaDecl.cpp
  test/SemaOpenCL/clang-builtin-version.cl
  test/SemaOpenCL/to_addr_builtin.cl

Index: test/SemaOpenCL/to_addr_builtin.cl
===
--- test/SemaOpenCL/to_addr_builtin.cl
+++ test/SemaOpenCL/to_addr_builtin.cl
@@ -10,7 +10,7 @@
 
   glob = to_global(glob, loc);
 #if __OPENCL_C_VERSION__ < CL_VERSION_2_0
-  // expected-warning@-2{{implicit declaration of function 'to_global' is invalid in C99}}
+  // expected-error@-2{{implicit declaration of function 'to_global' is invalid in OpenCL}}
   // expected-warning@-3{{incompatible integer to pointer conversion assigning to '__global int *' from 'int'}}
 #else
   // expected-error@-5{{invalid number of arguments to function: 'to_global'}}
Index: test/SemaOpenCL/clang-builtin-version.cl
===
--- test/SemaOpenCL/clang-builtin-version.cl
+++ test/SemaOpenCL/clang-builtin-version.cl
@@ -4,41 +4,45 @@
 
 kernel void dse_builtins() {
   int tmp;
-  enqueue_kernel(tmp, tmp, tmp, ^(void) { // expected-warning{{implicit declaration of function 'enqueue_kernel' is invalid in C99}}
+  enqueue_kernel(tmp, tmp, tmp, ^(void) { // expected-error{{implicit declaration of function 'enqueue_kernel' is invalid in OpenCL}}
 return;
   });
-  unsigned size = get_kernel_work_group_size(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_work_group_size' is invalid in C99}}
+  unsigned size = get_kernel_work_group_size(^(void) { // expected-error{{implicit declaration of function 'get_kernel_work_group_size' is invalid in OpenCL}}
 return;
   });
-  size = get_kernel_preferred_work_group_size_multiple(^(void) { // expected-warning{{implicit declaration of function 'get_kernel_preferred_work_group_size_multiple' is invalid in C99}}
+  size = get_kernel_preferred_work_group_size_multiple(^(void) { // expected-error{{implicit declaration of function 'get_kernel_preferred_work_group_size_multiple' is invalid in OpenCL}}
 return;
   });
 }
 
 void pipe_builtins() {
   int tmp;
 
-  read_pipe(tmp, tmp);  // expected-warning{{implicit declaration of function 'read_pipe' is invalid in C99}}
-  write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'write_pipe' is invalid in C99}}
+  foo(void); // expected-error{{implicit declaration of function 'foo' is invalid in OpenCL}}
+  // expected-error@-1{{expected expression}}
+  boo(); // expected-error{{implicit declaration of function 'boo' is invalid in OpenCL}}
 
-  reserve_read_pipe(tmp, tmp);  // expected-warning{{implicit declaration of function 'reserve_read_pipe' is invalid in C99}}
-  reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'reserve_write_pipe' is invalid in C99}}
+  read_pipe(tmp, tmp);  // expected-error{{implicit declaration of function 'read_pipe' is invalid in OpenCL}}
+  write_pipe(tmp, tmp); // expected-error{{implicit declaration of function 'write_pipe' is invalid in OpenCL}}
 
-  work_group_reserve_read_pipe(tmp, tmp);  // expected-warning{{implicit declaration of function 'work_group_reserve_read_pipe' is invalid in C99}}
-  work_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'work_group_reserve_write_pipe' is invalid in C99}}
+  reserve_read_pipe(tmp, tmp);  // expected-error{{implicit declaration of function 'reserve_read_pipe' is invalid in OpenCL}}
+  reserve_write_pipe(tmp, tmp); // expected-error{{implicit declaration of function 'reserve_write_pipe' is invalid in OpenCL}}
 
-  sub_group_reserve_write_pipe(tmp, tmp); // expected-warning{{implicit declaration of function 'sub_group_reserve_write_pipe' is invalid in C99}}
-  sub_group_reserve_read_pipe(tmp, tmp);  // expected-warning{{implicit declaration of function 'sub_group_reserve_read_pipe' is invalid in C99}}
+  work_group_reserve_read_pipe(tmp, tmp);  // expected-error{{implicit declaration of function 'work_group_reserve_read_pipe' is invalid in OpenCL}}
+  work_group_reserve_write_pipe(tmp, tmp); // expected-error{{implicit declaration of function 'work_group_reserve_write_pipe' is invalid in OpenCL}}
 
-  commit_read_pipe(tmp, tmp);  // expected-warning{{implicit declaration of function 'commit_read_pipe' is 

[PATCH] D33023: clang-format: [JS] wrap params with trailing commas.

2017-05-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1043
 
+bool EndsInComma =
+Current.MatchingParen &&

Please make this specific to JavaScript for now. C++ doesn't allow trailing 
commas here and a trailing comma is more likely to represent "not done yet". In 
those cases, we don't want to reformat the whole call.

The part above (changing the indentation of a ")" wrapped to a new line is fine 
to be used for all languages).



Comment at: unittests/Format/FormatTest.cpp:5505
+  verifyFormat(
+  "void aa(\n"
+  "int level,\n"

Don't add this line break? I suspect your clang-format isn't set to LLVM style?



Comment at: unittests/Format/FormatTest.cpp:9645
+   "  bar(\n"
+   "  []() {} // Did not respect 
SpacesBeforeTrailingComments\n"
+   "  );\n"

What caused this change?


https://reviews.llvm.org/D33023



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


[PATCH] D33023: clang-format: [JS] wrap params with trailing commas.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 98969.
mprobst marked 2 inline comments as done.
mprobst added a comment.

- only trigger wrapping in js mode, revert appropriate tests


https://reviews.llvm.org/D33023

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -550,6 +550,31 @@
"}\n");
 }
 
+TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
+  verifyFormat("function trailingComma(\n"
+   "p1,\n"
+   "p2,\n"
+   "p3,\n"
+   ") {\n"
+   "  a;  //\n"
+   "}\n",
+   "function trailingComma(p1, p2, p3,) {\n"
+   "  a;  //\n"
+   "}\n");
+  verifyFormat("trailingComma(\n"
+   "p1,\n"
+   "p2,\n"
+   "p3,\n"
+   ");\n",
+   "trailingComma(p1, p2, p3,);\n");
+  verifyFormat(
+  "trailingComma(\n"
+  "p1  // hello\n"
+  ");\n",
+  "trailingComma(p1 // hello\n"
+  ");\n");
+}
+
 TEST_F(FormatTestJS, ArrayLiterals) {
   verifyFormat("var a: List =\n"
"[new SomeThing(), new SomeThingB()];");
@@ -691,7 +716,7 @@
"})\n"
".doSomethingElse(\n"
"// break\n"
-   ");");
+   ");");
 
   Style.ColumnLimit = 33;
   verifyFormat("f({a: function() { return 1; }});", Style);
@@ -858,7 +883,7 @@
"})\n"
".doSomethingElse(\n"
"// break\n"
-   ");");
+   ");");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2106,7 +2106,7 @@
 
   verifyIncompleteFormat("void f(\n"
  "#if A\n"
- ");\n"
+ ");\n"
  "#else\n"
  "#endif");
 }
@@ -4475,7 +4475,7 @@
   EXPECT_EQ("static_cast *>(\n"
 "\n"
-");",
+");",
 format("static_cast*>(\n"
"\n"
@@ -6567,7 +6567,7 @@
 "#if !TEST\n"
 "_T(\"Xn\")\n"
 "#endif\n"
-");",
+");",
 format("f(\n"
"#if !TEST\n"
"_T(\"Xn\")\n"
@@ -9639,7 +9639,7 @@
   // Other corner cases.
   verifyFormat("void f() {\n"
"  bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
-   "  );\n"
+   "  );\n"
"}");
 
   // Lambdas created through weird macros.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2463,16 +2463,20 @@
   return true;
   }
 
-  // If the last token before a '}' is a comma or a trailing comment, the
-  // intention is to insert a line break after it in order to make shuffling
-  // around entries easier.
+  // If the last token before a '}', ']', or ')' is a comma or a trailing
+  // comment, the intention is to insert a line break after it in order to make
+  // shuffling around entries easier.
   const FormatToken *BeforeClosingBrace = nullptr;
-  if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
+  if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+   (Style.Language == FormatStyle::LK_JavaScript &&
+Left.is(tok::l_paren))) &&
   Left.BlockKind != BK_Block && Left.MatchingParen)
 BeforeClosingBrace = Left.MatchingParen->Previous;
   else if (Right.MatchingParen &&
-   Right.MatchingParen->isOneOf(tok::l_brace,
-TT_ArrayInitializerLSquare))
+   (Right.MatchingParen->isOneOf(tok::l_brace,
+ TT_ArrayInitializerLSquare) ||
+(Style.Language == FormatStyle::LK_JavaScript &&
+ Right.MatchingParen->is(tok::l_paren
 BeforeClosingBrace = &Left;
   if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
  BeforeClosingBrace->isTrailingComment()))
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -674,6 +674,8 @@
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.

[PATCH] D33023: clang-format: [JS] wrap params with trailing commas.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst marked an inline comment as done.
mprobst added inline comments.



Comment at: unittests/Format/FormatTest.cpp:5505
+  verifyFormat(
+  "void aa(\n"
+  "int level,\n"

djasper wrote:
> Don't add this line break? I suspect your clang-format isn't set to LLVM 
> style?
Yeah, something is amiss. Not sure what yet, but formatted manually for the 
time being.



Comment at: unittests/Format/FormatTest.cpp:9645
+   "  bar(\n"
+   "  []() {} // Did not respect 
SpacesBeforeTrailingComments\n"
+   "  );\n"

djasper wrote:
> What caused this change?
The trailing comma triggers a break, and then the code in TokenAnnotator causes 
the wrapping logic (on trailing comma and trailing comment).

Only triggering the wrapping in JS mode, this now just unindents the closing 
paren, which I think is sensible.


https://reviews.llvm.org/D33023



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-05-15 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 98970.
danielmarjamaki added a comment.

minor tweak


Repository:
  rL LLVM

https://reviews.llvm.org/D30295

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
  lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  test/Analysis/bitwise-ops.c

Index: test/Analysis/bitwise-ops.c
===
--- test/Analysis/bitwise-ops.c
+++ test/Analysis/bitwise-ops.c
@@ -29,4 +29,18 @@
   default:
 return 0;
   }
-}
\ No newline at end of file
+}
+
+int testOverflowShift(int a) {
+  if (a == 323) {
+return 1 << a; // expected-warning{{The result of the '<<' expression is undefined due to shift count >= width of type}}
+  }
+  return 0;
+}
+
+int testNegativeShift(int a) {
+  if (a == -5) {
+return 1 << a; // expected-warning{{The result of the '<<' expression is undefined due to negative value on the right side of operand}}
+  }
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -94,3 +94,40 @@
 
   return std::make_pair(VD, RHS);
 }
+
+bool clang::ento::exprComparesTo(SVal LHSVal, BinaryOperatorKind ComparisonOp,
+ SVal RHSVal, ProgramStateRef State) {
+
+  if (LHSVal.isUnknownOrUndef())
+return false;
+  ProgramStateManager &Mgr = State->getStateManager();
+  if (!LHSVal.getAs() && LHSVal.getAs()) {
+LHSVal = Mgr.getStoreManager().getBinding(State->getStore(),
+  LHSVal.castAs());
+  }
+  if (LHSVal.isUnknownOrUndef() || !LHSVal.getAs())
+return false;
+
+  SValBuilder &Bldr = Mgr.getSValBuilder();
+  SVal Eval = Bldr.evalBinOp(State, ComparisonOp, LHSVal, RHSVal,
+ Bldr.getConditionType());
+  if (Eval.isUnknownOrUndef())
+return false;
+  ProgramStateRef StTrue, StFalse;
+  std::tie(StTrue, StFalse) = State->assume(Eval.castAs());
+  return StTrue && !StFalse;
+}
+
+// Is E value greater or equal than Val?
+bool clang::ento::isGreaterOrEqual(const Expr *E, unsigned long long Val,
+   CheckerContext &C) {
+  DefinedSVal V =
+  C.getSValBuilder().makeIntVal(Val, C.getASTContext().LongLongTy);
+  return exprComparesTo(C.getSVal(E), BO_GE, V, C.getState());
+}
+
+// Is E value negative?
+bool clang::ento::isNegative(const Expr *E, CheckerContext &C) {
+  DefinedSVal V = C.getSValBuilder().makeIntVal(0, false);
+  return exprComparesTo(C.getSVal(E), BO_LT, V, C.getState());
+}
Index: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
@@ -59,6 +60,11 @@
   return StOutBound && !StInBound;
 }
 
+static bool isShiftOverflow(const BinaryOperator *B, CheckerContext &C) {
+  return isGreaterOrEqual(
+  B->getRHS(), C.getASTContext().getIntWidth(B->getLHS()->getType()), C);
+}
+
 void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
CheckerContext &C) const {
   ProgramStateRef state = C.getState();
@@ -106,9 +112,24 @@
 }
 else {
   // Neither operand was undefined, but the result is undefined.
-  OS << "The result of the '"
- << BinaryOperator::getOpcodeStr(B->getOpcode())
- << "' expression is undefined";
+  if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
+   B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
+  isNegative(B->getRHS(), C)) {
+OS << "The result of the '"
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to negative value on the right "
+  "side of operand";
+  } else if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
+  B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
+ isShiftOverflow(B, C)) {
+OS << "The result of the '"
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to shift count >= width of type";
+  } else {
+OS << "The result of the '"
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined";
+  }
 }
 auto report = llvm::mak

[PATCH] D33023: clang-format: [JS] wrap params with trailing commas.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 98971.
mprobst marked an inline comment as done.
mprobst added a comment.

fix formatting a bit


https://reviews.llvm.org/D33023

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -550,6 +550,30 @@
"}\n");
 }
 
+TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
+  verifyFormat("function trailingComma(\n"
+   "p1,\n"
+   "p2,\n"
+   "p3,\n"
+   ") {\n"
+   "  a;  //\n"
+   "}\n",
+   "function trailingComma(p1, p2, p3,) {\n"
+   "  a;  //\n"
+   "}\n");
+  verifyFormat("trailingComma(\n"
+   "p1,\n"
+   "p2,\n"
+   "p3,\n"
+   ");\n",
+   "trailingComma(p1, p2, p3,);\n");
+  verifyFormat("trailingComma(\n"
+   "p1  // hello\n"
+   ");\n",
+   "trailingComma(p1 // hello\n"
+   ");\n");
+}
+
 TEST_F(FormatTestJS, ArrayLiterals) {
   verifyFormat("var a: List =\n"
"[new SomeThing(), new SomeThingB()];");
@@ -691,7 +715,7 @@
"})\n"
".doSomethingElse(\n"
"// break\n"
-   ");");
+   ");");
 
   Style.ColumnLimit = 33;
   verifyFormat("f({a: function() { return 1; }});", Style);
@@ -858,7 +882,7 @@
"})\n"
".doSomethingElse(\n"
"// break\n"
-   ");");
+   ");");
 }
 
 TEST_F(FormatTestJS, ReturnStatements) {
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2106,7 +2106,7 @@
 
   verifyIncompleteFormat("void f(\n"
  "#if A\n"
- ");\n"
+ ");\n"
  "#else\n"
  "#endif");
 }
@@ -4475,7 +4475,7 @@
   EXPECT_EQ("static_cast *>(\n"
 "\n"
-");",
+");",
 format("static_cast*>(\n"
"\n"
@@ -6567,7 +6567,7 @@
 "#if !TEST\n"
 "_T(\"Xn\")\n"
 "#endif\n"
-");",
+");",
 format("f(\n"
"#if !TEST\n"
"_T(\"Xn\")\n"
@@ -9639,7 +9639,7 @@
   // Other corner cases.
   verifyFormat("void f() {\n"
"  bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
-   "  );\n"
+   "  );\n"
"}");
 
   // Lambdas created through weird macros.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2463,16 +2463,20 @@
   return true;
   }
 
-  // If the last token before a '}' is a comma or a trailing comment, the
-  // intention is to insert a line break after it in order to make shuffling
-  // around entries easier.
+  // If the last token before a '}', ']', or ')' is a comma or a trailing
+  // comment, the intention is to insert a line break after it in order to make
+  // shuffling around entries easier.
   const FormatToken *BeforeClosingBrace = nullptr;
-  if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
+  if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+   (Style.Language == FormatStyle::LK_JavaScript &&
+Left.is(tok::l_paren))) &&
   Left.BlockKind != BK_Block && Left.MatchingParen)
 BeforeClosingBrace = Left.MatchingParen->Previous;
   else if (Right.MatchingParen &&
-   Right.MatchingParen->isOneOf(tok::l_brace,
-TT_ArrayInitializerLSquare))
+   (Right.MatchingParen->isOneOf(tok::l_brace,
+ TT_ArrayInitializerLSquare) ||
+(Style.Language == FormatStyle::LK_JavaScript &&
+ Right.MatchingParen->is(tok::l_paren
 BeforeClosingBrace = &Left;
   if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
  BeforeClosingBrace->isTrailingComment()))
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -674,6 +674,8 @@
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;

r303045 - [index] Avoid a crash that happens when looking up a dependent name

2017-05-15 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon May 15 05:20:39 2017
New Revision: 303045

URL: http://llvm.org/viewvc/llvm-project?rev=303045&view=rev
Log:
[index] Avoid a crash that happens when looking up a dependent name
in a record that has no definition

rdar://32194921

Modified:
cfe/trunk/lib/Index/IndexBody.cpp
cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
cfe/trunk/test/Index/Core/index-dependent-source.cpp

Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=303045&r1=303044&r2=303045&view=diff
==
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Mon May 15 05:20:39 2017
@@ -165,6 +165,9 @@ public:
 if (!TD)
   return true;
 CXXRecordDecl *RD = TD->getTemplatedDecl();
+if (!RD->hasDefinition())
+  return true;
+RD = RD->getDefinition();
 std::vector Symbols =
 RD->lookupDependentName(NameInfo.getName(), Filter);
 // FIXME: Improve overload handling.

Modified: cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp?rev=303045&r1=303044&r2=303045&view=diff
==
--- cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp Mon May 15 05:20:39 2017
@@ -157,6 +157,9 @@ public:
 if (!TD)
   return true;
 CXXRecordDecl *RD = TD->getTemplatedDecl();
+if (!RD->hasDefinition())
+  return true;
+RD = RD->getDefinition();
 DeclarationName Name(DNT->getIdentifier());
 std::vector Symbols = RD->lookupDependentName(
 Name, [](const NamedDecl *ND) { return isa(ND); });

Modified: cfe/trunk/test/Index/Core/index-dependent-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-dependent-source.cpp?rev=303045&r1=303044&r2=303045&view=diff
==
--- cfe/trunk/test/Index/Core/index-dependent-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-dependent-source.cpp Mon May 15 05:20:39 
2017
@@ -122,3 +122,12 @@ void indexDependentOverloads(const Templ
   object.overload1(Y());
 // CHECK-NOT: [[@LINE-1]]
 }
+
+template struct UndefinedTemplateClass;
+
+template
+void undefinedTemplateLookup(UndefinedTemplateClass &x) {
+// Shouldn't crash!
+  x.lookup;
+  typename UndefinedTemplateClass::Type y;
+}


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


r303046 - [index] Store correct location for namespace nested name qualifiers

2017-05-15 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon May 15 05:41:04 2017
New Revision: 303046

URL: http://llvm.org/viewvc/llvm-project?rev=303046&view=rev
Log:
[index] Store correct location for namespace nested name qualifiers

rdar://32195200

Modified:
cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp?rev=303046&r1=303045&r2=303046&view=diff
==
--- cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp (original)
+++ cfe/trunk/lib/Index/IndexTypeSourceInfo.cpp Mon May 15 05:41:04 2017
@@ -212,7 +212,7 @@ void IndexingContext::indexNestedNameSpe
 
   if (!DC)
 DC = Parent->getLexicalDeclContext();
-  SourceLocation Loc = NNS.getSourceRange().getBegin();
+  SourceLocation Loc = NNS.getLocalBeginLoc();
 
   switch (NNS.getNestedNameSpecifier()->getKind()) {
   case NestedNameSpecifier::Identifier:

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=303046&r1=303045&r2=303046&view=diff
==
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Mon May 15 05:41:04 2017
@@ -314,3 +314,21 @@ class ClassWithCorrectSpecialization | Ref | 
rel: 0
 // CHECK: [[@LINE-3]]:71 | static-property/C++ | C | c:@S@Record@C | 
__ZN6Record1CE | Ref,Read | rel: 0
 // CHECK: [[@LINE-4]]:63 | struct/C++ | Record | c:@S@Record |  | 
Ref | rel: 0
+
+namespace ns {
+// CHECK: [[@LINE-1]]:11 | namespace/C++ | ns | c:@N@ns |  | Decl | 
rel: 0
+namespace inner {
+// CHECK: [[@LINE-1]]:11 | namespace/C++ | inner | c:@N@ns@N@inner | 
 | Decl,RelChild | rel: 1
+void func();
+
+}
+namespace innerAlias = inner;
+}
+
+void ::ns::inner::func() {
+// CHECK: [[@LINE-1]]:8 | namespace/C++ | ns | c:@N@ns |  | 
Ref,RelCont | rel: 1
+// CHECK: [[@LINE-2]]:12 | namespace/C++ | inner | c:@N@ns@N@inner | 
 | Ref,RelCont | rel: 1
+  ns::innerAlias::func();
+// CHECK: [[@LINE-1]]:3 | namespace/C++ | ns | c:@N@ns |  | 
Ref,RelCont | rel: 1
+// CHECK: [[@LINE-2]]:7 | namespace-alias/C++ | innerAlias | 
c:@N@ns@NA@innerAlias |  | Ref,RelCont | rel: 1
+}


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


r303048 - [index] Visit and store information about namespace alias declarations

2017-05-15 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon May 15 05:56:31 2017
New Revision: 303048

URL: http://llvm.org/viewvc/llvm-project?rev=303048&view=rev
Log:
[index] Visit and store information about namespace alias declarations

rdar://32195226

Modified:
cfe/trunk/lib/Index/IndexDecl.cpp
cfe/trunk/test/Index/Core/index-source.cpp

Modified: cfe/trunk/lib/Index/IndexDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexDecl.cpp?rev=303048&r1=303047&r2=303048&view=diff
==
--- cfe/trunk/lib/Index/IndexDecl.cpp (original)
+++ cfe/trunk/lib/Index/IndexDecl.cpp Mon May 15 05:56:31 2017
@@ -544,6 +544,14 @@ public:
 return true;
   }
 
+  bool VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
+TRY_DECL(D, IndexCtx.handleDecl(D));
+IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), D);
+IndexCtx.handleReference(D->getAliasedNamespace(), D->getTargetNameLoc(), 
D,
+ D->getLexicalDeclContext());
+return true;
+  }
+
   bool VisitUsingDecl(const UsingDecl *D) {
 const DeclContext *DC = D->getDeclContext()->getRedeclContext();
 const NamedDecl *Parent = dyn_cast(DC);

Modified: cfe/trunk/test/Index/Core/index-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.cpp?rev=303048&r1=303047&r2=303048&view=diff
==
--- cfe/trunk/test/Index/Core/index-source.cpp (original)
+++ cfe/trunk/test/Index/Core/index-source.cpp Mon May 15 05:56:31 2017
@@ -323,8 +323,15 @@ void func();
 
 }
 namespace innerAlias = inner;
+// CHECK: [[@LINE-1]]:11 | namespace-alias/C++ | innerAlias | 
c:@N@ns@NA@innerAlias |  | Decl,RelChild | rel: 1
+// CHECK: [[@LINE-2]]:24 | namespace/C++ | inner | c:@N@ns@N@inner | 
 | Ref,RelCont | rel: 1
 }
 
+namespace namespaceAlias = ::ns::innerAlias;
+// CHECK: [[@LINE-1]]:11 | namespace-alias/C++ | namespaceAlias | 
c:@NA@namespaceAlias |  | Decl | rel: 0
+// CHECK: [[@LINE-2]]:30 | namespace/C++ | ns | c:@N@ns |  | 
Ref,RelCont | rel: 1
+// CHECK: [[@LINE-3]]:34 | namespace-alias/C++ | innerAlias | 
c:@N@ns@NA@innerAlias |  | Ref,RelCont | rel: 1
+
 void ::ns::inner::func() {
 // CHECK: [[@LINE-1]]:8 | namespace/C++ | ns | c:@N@ns |  | 
Ref,RelCont | rel: 1
 // CHECK: [[@LINE-2]]:12 | namespace/C++ | inner | c:@N@ns@N@inner | 
 | Ref,RelCont | rel: 1


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


[PATCH] D33023: clang-format: [JS] wrap params with trailing commas.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303049: JavaScript allows parameter lists to include 
trailing commas: (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D33023?vs=98971&id=98979#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33023

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

Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -674,6 +674,8 @@
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;
   }
+  if (Current.is(tok::r_paren) && State.Stack.size() > 1)
+return State.Stack[State.Stack.size() - 2].LastSpace;
   if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
 return State.Stack[State.Stack.size() - 2].LastSpace;
   if (Current.is(tok::identifier) && Current.Next &&
@@ -1038,13 +1040,20 @@
   NestedBlockIndent = Column;
 }
 
+bool EndsInComma =
+Current.MatchingParen &&
+Current.MatchingParen->getPreviousNonComment() &&
+Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
+
 AvoidBinPacking =
+(Style.Language == FormatStyle::LK_JavaScript && EndsInComma) ||
 (State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
 (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
 (Style.ExperimentalAutoDetectBinPacking &&
  (Current.PackingKind == PPK_OnePerLine ||
   (!BinPackInconclusiveFunctions &&
Current.PackingKind == PPK_Inconclusive)));
+
 if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen) {
   if (Style.ColumnLimit) {
 // If this '[' opens an ObjC call, determine whether all parameters fit
@@ -1065,6 +1074,9 @@
 }
   }
 }
+
+if (Style.Language == FormatStyle::LK_JavaScript && EndsInComma)
+  BreakBeforeParameter = true;
   }
   // Generally inherit NoLineBreak from the current scope to nested scope.
   // However, don't do this for non-empty nested blocks, dict literals and
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2463,16 +2463,20 @@
   return true;
   }
 
-  // If the last token before a '}' is a comma or a trailing comment, the
-  // intention is to insert a line break after it in order to make shuffling
-  // around entries easier.
+  // If the last token before a '}', ']', or ')' is a comma or a trailing
+  // comment, the intention is to insert a line break after it in order to make
+  // shuffling around entries easier.
   const FormatToken *BeforeClosingBrace = nullptr;
-  if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
+  if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+   (Style.Language == FormatStyle::LK_JavaScript &&
+Left.is(tok::l_paren))) &&
   Left.BlockKind != BK_Block && Left.MatchingParen)
 BeforeClosingBrace = Left.MatchingParen->Previous;
   else if (Right.MatchingParen &&
-   Right.MatchingParen->isOneOf(tok::l_brace,
-TT_ArrayInitializerLSquare))
+   (Right.MatchingParen->isOneOf(tok::l_brace,
+ TT_ArrayInitializerLSquare) ||
+(Style.Language == FormatStyle::LK_JavaScript &&
+ Right.MatchingParen->is(tok::l_paren
 BeforeClosingBrace = &Left;
   if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
  BeforeClosingBrace->isTrailingComment()))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -2106,7 +2106,7 @@
 
   verifyIncompleteFormat("void f(\n"
  "#if A\n"
- ");\n"
+ ");\n"
  "#else\n"
  "#endif");
 }
@@ -4475,7 +4475,7 @@
   EXPECT_EQ("static_cast *>(\n"
 "\n"
-");",
+");",
 format("static_cast*>(\n"
"\n"
@@ -6567,7 +6567,7 @@
 "#if !TEST\n"
 "_T(\"Xn\")\n"
 "#endif\n"
-");",
+");",
 format("f(\n"
"#if !TEST\n"
"_T(\"Xn\")\n"
@@ -9639,7 +9639,7 @@
   // Other corner cases.
   verifyFormat("void f() {\n"
"  bar([](

r303049 - JavaScript allows parameter lists to include trailing commas:

2017-05-15 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Mon May 15 06:15:29 2017
New Revision: 303049

URL: http://llvm.org/viewvc/llvm-project?rev=303049&view=rev
Log:
JavaScript allows parameter lists to include trailing commas:

myFunction(param1, param2,);

For symmetry with other parenthesized lists ([...], {...}), clang-format should
wrap parenthesized lists one-per-line if they contain a trailing comma:

myFunction(
param1,
param2,
);

This is particularly useful in function declarations or calls with many
arguments, e.g. commonly in constructors.

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.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=303049&r1=303048&r2=303049&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon May 15 06:15:29 2017
@@ -674,6 +674,8 @@ unsigned ContinuationIndenter::getNewLin
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;
   }
+  if (Current.is(tok::r_paren) && State.Stack.size() > 1)
+return State.Stack[State.Stack.size() - 2].LastSpace;
   if (NextNonComment->is(TT_TemplateString) && NextNonComment->closesScope())
 return State.Stack[State.Stack.size() - 2].LastSpace;
   if (Current.is(tok::identifier) && Current.Next &&
@@ -1038,13 +1040,20 @@ void ContinuationIndenter::moveStatePast
   NestedBlockIndent = Column;
 }
 
+bool EndsInComma =
+Current.MatchingParen &&
+Current.MatchingParen->getPreviousNonComment() &&
+Current.MatchingParen->getPreviousNonComment()->is(tok::comma);
+
 AvoidBinPacking =
+(Style.Language == FormatStyle::LK_JavaScript && EndsInComma) ||
 (State.Line->MustBeDeclaration && !Style.BinPackParameters) ||
 (!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
 (Style.ExperimentalAutoDetectBinPacking &&
  (Current.PackingKind == PPK_OnePerLine ||
   (!BinPackInconclusiveFunctions &&
Current.PackingKind == PPK_Inconclusive)));
+
 if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen) {
   if (Style.ColumnLimit) {
 // If this '[' opens an ObjC call, determine whether all parameters fit
@@ -1065,6 +1074,9 @@ void ContinuationIndenter::moveStatePast
 }
   }
 }
+
+if (Style.Language == FormatStyle::LK_JavaScript && EndsInComma)
+  BreakBeforeParameter = true;
   }
   // Generally inherit NoLineBreak from the current scope to nested scope.
   // However, don't do this for non-empty nested blocks, dict literals and

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=303049&r1=303048&r2=303049&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 15 06:15:29 2017
@@ -2463,16 +2463,20 @@ bool TokenAnnotator::mustBreakBefore(con
   return true;
   }
 
-  // If the last token before a '}' is a comma or a trailing comment, the
-  // intention is to insert a line break after it in order to make shuffling
-  // around entries easier.
+  // If the last token before a '}', ']', or ')' is a comma or a trailing
+  // comment, the intention is to insert a line break after it in order to make
+  // shuffling around entries easier.
   const FormatToken *BeforeClosingBrace = nullptr;
-  if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
+  if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+   (Style.Language == FormatStyle::LK_JavaScript &&
+Left.is(tok::l_paren))) &&
   Left.BlockKind != BK_Block && Left.MatchingParen)
 BeforeClosingBrace = Left.MatchingParen->Previous;
   else if (Right.MatchingParen &&
-   Right.MatchingParen->isOneOf(tok::l_brace,
-TT_ArrayInitializerLSquare))
+   (Right.MatchingParen->isOneOf(tok::l_brace,
+ TT_ArrayInitializerLSquare) ||
+(Style.Language == FormatStyle::LK_JavaScript &&
+ Right.MatchingParen->is(tok::l_paren
 BeforeClosingBrace = &Left;
   if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
  BeforeClosingBrace->isTrailingComment()))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=303049&r1=303048&r2=303049&view=diff

[PATCH] D32896: [OpenCL] Make CLK_NULL_RESERVE_ID invalid reserve id.

2017-05-15 Thread Egor Churaev via Phabricator via cfe-commits
echuraev added inline comments.



Comment at: lib/Headers/opencl-c.h:16020
+// The macro CLK_NULL_RESERVE_ID refers to an invalid reservation ID.
+#define CLK_NULL_RESERVE_ID (__builtin_astype((void *)0, reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);

yaxunl wrote:
> Anastasia wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > Looks good from my side.
> > > > 
> > > > @yaxunl , since you originally committed this. Could you please verify 
> > > > that changing from `SIZE_MAX` to `0` would be fine.
> > > > 
> > > > Btw, we have a similar definition for `CLK_NULL_EVENT`.
> > > `__PIPE_RESERVE_ID_VALID_BIT` is implementation detail and not part of 
> > > the spec. I would suggest to remove it from this header file.
> > > 
> > > The spec only requires CLK_NULL_RESERVE_ID to be defined but does not 
> > > define its value. Naturally a valid id starts from 0 and increases. I 
> > > don't see significant advantage to change CLK_NULL_RESERVE_ID from 
> > > __SIZE_MAX to 0.
> > > 
> > > Is there any reason that this change is needed?
> > I don't see issues to commit things outside of spec as soon as they 
> > prefixed properly with "__".  But I agree it would be nice to see if it's 
> > any useful and what the motivation is for having different implementation.
> For `__PIPE_RESERVE_ID_VALID_BIT`, it assumes that the implementation uses 
> one specific bit of a reserve id to indicate that the reserve id is valid. 
> Not all implementations assume that. Actually I am curious why that is needed 
> too.
About `CLK_NULL_RESERVE_ID`: we check that reserve id is valid if significant 
bit equal to one. `CLK_NULL_RESERVE_ID refers to an invalid reservation, so if 
`CLK_NULL_RESERVE_ID equal to 0, we can be sure that significant bit doesn't 
equal to 1 and it is invalid reserve id. Also it is more obviously if 
CLK_**NULL**_RESERVE_ID is equal to 0.

What about `__PIPE_RESERVE_ID_VALID_BIT`: As I understand previous 
implementation also assumes that one specific bit was of a reverse id was used 
to indicate that the reserve id is valid. So, we just increased reserve id size 
by one bit on 32-bit platforms and by 33 bits on 64-bit platforms. 


https://reviews.llvm.org/D32896



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


[PATCH] D33173: Modify test to look for patterns in stderr as well

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

Feel free to commit this to fix buildbots, however the underlying 
https://reviews.llvm.org/D33013 raises some questions.

Clang-tidy is also used as a library, in which case it should capture all 
compiler diagnostics and pass them to the caller. This test verifies that 
clang-tidy actually captures the compilation error, and with 
https://reviews.llvm.org/D33013 this seems to have broken for the diagnostics 
related to command line parsing. Modifying the driver to directly output these 
errors to stderr instead of using `DiagnosticConsumer` seems like a wrong thing 
to do.


https://reviews.llvm.org/D33173



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


[PATCH] D33013: Driver must return non-zero code on errors in command line

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: lib/Tooling/CompilationDatabase.cpp:208
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-  UnusedInputDiagConsumer DiagClient;
+  TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);
+  UnusedInputDiagConsumer DiagClient(DiagnosticPrinter);

This code is used as a library not only for command-line tools. Directly using 
stderr is wrong in many use cases of the Tooling library. It should instead 
somehow let the user of the library get these errors via a provided 
DiagnosticConsumer. Not sure how to do this here without a more careful reading 
of the code, but wanted to let you know that this change causes a regression at 
least for clang-tidy (and likely for many other Clang tools).


https://reviews.llvm.org/D33013



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


[PATCH] D25866: [Sema] Support implicit scalar to vector conversions

2017-05-15 Thread Simon Dardis via Phabricator via cfe-commits
sdardis added a comment.

Thanks for the review.


Repository:
  rL LLVM

https://reviews.llvm.org/D25866



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


[PATCH] D33191: [analyzer] ObjCGenerics: account for __kindof specifiers met along a chain of casts.

2017-05-15 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
Herald added a subscriber: xazax.hun.

`__kindof` type specifiers allow the developers to express their intent in 
discriminating between generic type arguments being matched exactly or allowing 
sub-types. When generics were introduced, it was already too late to add 
`__kindof` specifiers consistently across all the code. So for now in most code 
we believe it's all right not to have them, but we need to expect to have them 
at least in some places (which would normally be API declarations) and pick 
them up when they're present by loosening our dynamic type information from 
non-`__kindof` to `__kindof`, which would suppress some of the false "invalid 
cast" warnings.

In the test provided, the `__kindof` is only present on the API return value; 
direct cast from the object created within the callee function is an error, 
however casting indirectly through a `__kindof` type should be possible, 
because just one `__kindof` annotation at the API declaration is considered to 
be enough to express the intent of "it was `__kindof` from the start but we 
didn't bother adding it".

For now, we discard the original type information when we find `__kindof` 
specifiers in a chain of casts.


https://reviews.llvm.org/D33191

Files:
  lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  test/Analysis/generics.m

Index: test/Analysis/generics.m
===
--- test/Analysis/generics.m
+++ test/Analysis/generics.m
@@ -390,6 +390,25 @@
   [arrayOfStrings containsObject:someString]; // no-warning
 }
 
+NSArray *getStringMutableArray() {
+  NSMutableArray *arr =
+  [[NSMutableArray alloc] init];
+  return arr;
+}
+
+NSArray<__kindof NSString *> *getKindofStringMutableArray() {
+  NSMutableArray *arr =
+  [[NSMutableArray alloc] init];
+  return arr;
+}
+
+void testKindofPropagation() {
+  NSArray *arr1 =
+  (NSArray *)getKindofStringMutableArray(); // no-warning
+  NSArray *arr2 =
+  (NSArray *)getStringMutableArray(); // expected-warning{{Conversion from value of type 'NSMutableArray *' to incompatible type 'NSArray *'}}
+}
+
 // CHECK:  diagnostics
 // CHECK-NEXT:  
 // CHECK-NEXT:   
@@ -7140,4 +7159,324 @@
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:path
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line406
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line406
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line408
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line408
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindcontrol
+// CHECK-NEXT:  edges
+// CHECK-NEXT:   
+// CHECK-NEXT:
+// CHECK-NEXT: start
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line408
+// CHECK-NEXT:col3
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line408
+// CHECK-NEXT:col9
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT: end
+// CHECK-NEXT:  
+// CHECK-NEXT:   
+// CHECK-NEXT:line409
+// CHECK-NEXT:col37
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:   
+// CHECK-NEXT:line409
+// CHECK-NEXT:col57
+// CHECK-NEXT:file0
+// CHECK-NEXT:   
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT:   
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  kindevent
+// CHECK-NEXT:  location
+// CHECK-NEXT:  
+// CHECK-NEXT:   line409
+// CHECK-NEXT:   col37
+// CHECK-NEXT:   file0
+// CHECK-NEXT:  
+// CHECK-NEXT:  ranges
+// CHECK-NEXT:  
+// CHECK-NEXT:
+// CHECK-NEXT: 
+// CHECK-NEXT:  line409
+// CHECK-NEXT:  col37
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT: 
+// CHECK-NEXT:  line409
+// CHECK-NEXT:  col59
+// CHECK-NEXT:  file0
+// CHECK-NEXT: 
+// CHECK-NEXT:
+// CHECK-NEXT:  
+// CHECK-NEXT:  depth0
+// CHECK-NEXT:  extended_messag

[PATCH] D33193: clang-format: [JS] for async loops.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst created this revision.
Herald added a subscriber: klimek.

JavaScript supports asynchronous loop iteration in async functions:

  for async (const x of y) ...


https://reviews.llvm.org/D33193

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1635,6 +1635,8 @@
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  if (FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -580,7 +580,11 @@
   Tok->Previous->is(tok::period))
 break;
   Contexts.back().ColonIsForRangeExpr = true;
+  // for async ( ...
+  if (CurrentToken->is(Keywords.kw_async))
+next();
   next();
+
   if (!parseParens())
 return false;
   break;
@@ -2249,6 +2253,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1635,6 +1635,8 @@
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  if (FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -580,7 +580,11 @@
   Tok->Previous->is(tok::period))
 break;
   Contexts.back().ColonIsForRangeExpr = true;
+  // for async ( ...
+  if (CurrentToken->is(Keywords.kw_async))
+next();
   next();
+
   if (!parseParens())
 return false;
   break;
@@ -2249,6 +2253,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33010: Make google-build-using-namespace skip std::.*literals

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG with one nit. Thank you for addressing this! Do you need me to commit the 
patch for you?




Comment at: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp:48
 
+bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
+const NamespaceDecl *NS) {

Please make this a static free function instead, since it doesn't need access 
to the check's members.


https://reviews.llvm.org/D33010



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


[PATCH] D33193: clang-format: [JS] for async loops.

2017-05-15 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Format/TokenAnnotator.cpp:583
   Contexts.back().ColonIsForRangeExpr = true;
+  // for async ( ...
+  if (CurrentToken->is(Keywords.kw_async))

Can we make this JS specific, e.g. by turning l. 579 into:

  if (Style.Language == FormatStyle::LK_JavaScript) {
if (Tok->Previous && Tok->Previous->is(tok::period))
  break;
if (CurrentToken->is(Keywords.kw_async))
  next();
  }

Alternatively, leave a comment that this is JavaScript's "async"



Comment at: lib/Format/UnwrappedLineParser.cpp:1638
   nextToken();
+  if (FormatTok->is(Keywords.kw_async))
+nextToken();

Same here.. Make this JS specific or at least leave a comment.


https://reviews.llvm.org/D33193



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


[PATCH] D33193: clang-format: [JS] for async loops.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 98997.
mprobst marked an inline comment as done.
mprobst added a comment.

- make parsing JS specific


https://reviews.llvm.org/D33193

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1635,6 +1635,10 @@
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  // JS' for async ( ...
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+  FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -576,9 +576,12 @@
   }
   break;
 case tok::kw_for:
-  if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
-  Tok->Previous->is(tok::period))
-break;
+  if (Style.Language == FormatStyle::LK_JavaScript)
+if (Tok->Previous && Tok->Previous->is(tok::period))
+  break;
+// JS' for async ( ...
+if (CurrentToken->is(Keywords.kw_async))
+  next();
   Contexts.back().ColonIsForRangeExpr = true;
   next();
   if (!parseParens())
@@ -2249,6 +2252,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1635,6 +1635,10 @@
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  // JS' for async ( ...
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+  FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -576,9 +576,12 @@
   }
   break;
 case tok::kw_for:
-  if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
-  Tok->Previous->is(tok::period))
-break;
+  if (Style.Language == FormatStyle::LK_JavaScript)
+if (Tok->Previous && Tok->Previous->is(tok::period))
+  break;
+// JS' for async ( ...
+if (CurrentToken->is(Keywords.kw_async))
+  next();
   Contexts.back().ColonIsForRangeExpr = true;
   next();
   if (!parseParens())
@@ -2249,6 +2252,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  retur

[PATCH] D33193: clang-format: [JS] for async loops.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
mprobst marked an inline comment as done.
mprobst added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:583
   Contexts.back().ColonIsForRangeExpr = true;
+  // for async ( ...
+  if (CurrentToken->is(Keywords.kw_async))

djasper wrote:
> Can we make this JS specific, e.g. by turning l. 579 into:
> 
>   if (Style.Language == FormatStyle::LK_JavaScript) {
> if (Tok->Previous && Tok->Previous->is(tok::period))
>   break;
> if (CurrentToken->is(Keywords.kw_async))
>   next();
>   }
> 
> Alternatively, leave a comment that this is JavaScript's "async"
My reasoning was that this would at best be a syntax error in other languages, 
so it's fine to parse. But changed to be JS specific, that might be cleaner.


https://reviews.llvm.org/D33193



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


[PATCH] D33047: [ClangD] Refactor clangd into separate components

2017-05-15 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.
This revision is now accepted and ready to land.

I believe this is good enough now.


https://reviews.llvm.org/D33047



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


[clang-tools-extra] r303063 - Test commit(changed comment)

2017-05-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 15 08:50:46 2017
New Revision: 303063

URL: http://llvm.org/viewvc/llvm-project?rev=303063&view=rev
Log:
Test commit(changed comment)

Modified:
clang-tools-extra/trunk/clangd/ASTManager.h

Modified: clang-tools-extra/trunk/clangd/ASTManager.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.h?rev=303063&r1=303062&r2=303063&view=diff
==
--- clang-tools-extra/trunk/clangd/ASTManager.h (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.h Mon May 15 08:50:46 2017
@@ -32,7 +32,7 @@ namespace clangd {
 /// Using 'unsigned' here to avoid undefined behaviour on overflow.
 typedef unsigned DocVersion;
 
-/// Stores ASTUnit and FixIts map for an opened document
+/// Stores ASTUnit and FixIts map for an opened document.
 class DocData {
 public:
   typedef std::map>


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


[PATCH] D33197: [libclang] [OpenCL] Expose more OpenCL CIndex types

2017-05-15 Thread Sven van Haastregt via Phabricator via cfe-commits
svenvh created this revision.

Expose pipe, sampler_t, clk_event_t, queue_t, reserve_id_t, and all
image types.

  

Update the opencl-types.cl test RUN line such that we can test the
OpenCL 2.0 types.

  

Patch by Simon Perretta.


https://reviews.llvm.org/D33197

Files:
  bindings/python/clang/cindex.py
  include/clang-c/Index.h
  test/Index/opencl-types.cl
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -59,6 +59,13 @@
 BTCASE(ObjCId);
 BTCASE(ObjCClass);
 BTCASE(ObjCSel);
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) BTCASE(Id);
+#include "clang/Basic/OpenCLImageTypes.def"
+#undef IMAGE_TYPE
+BTCASE(OCLSampler);
+BTCASE(OCLEvent);
+BTCASE(OCLQueue);
+BTCASE(OCLReserveID);
   default:
 return CXType_Unexposed;
   }
@@ -94,6 +101,7 @@
 TKCASE(MemberPointer);
 TKCASE(Auto);
 TKCASE(Elaborated);
+TKCASE(Pipe);
 default:
   return CXType_Unexposed;
   }
@@ -535,6 +543,14 @@
 TKIND(MemberPointer);
 TKIND(Auto);
 TKIND(Elaborated);
+TKIND(Pipe);
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) TKIND(Id);
+#include "clang/Basic/OpenCLImageTypes.def"
+#undef IMAGE_TYPE
+TKIND(OCLSampler);
+TKIND(OCLEvent);
+TKIND(OCLQueue);
+TKIND(OCLReserveID);
   }
 #undef TKIND
   return cxstring::createRef(s);
Index: test/Index/opencl-types.cl
===
--- test/Index/opencl-types.cl
+++ test/Index/opencl-types.cl
@@ -1,4 +1,4 @@
-// RUN: c-index-test -test-print-type %s | FileCheck %s
+// RUN: c-index-test -test-print-type %s -cl-std=CL2.0 | FileCheck %s
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -22,3 +22,105 @@
 // CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] [typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
 // CHECK: VarDecl=scalarDouble:15:10 (Definition) [type=double] [typekind=Double] [isPOD=1]
 // CHECK: VarDecl=vectorDouble:16:11 (Definition) [type=double4] [typekind=Typedef] [canonicaltype=double __attribute__((ext_vector_type(4)))] [canonicaltypekind=Unexposed] [isPOD=1]
+
+#pragma OPENCL EXTENSION cl_khr_gl_msaa_sharing : enable
+
+void kernel OCLImage1dROTest(read_only image1d_t scalarOCLImage1dRO);
+void kernel OCLImage1dArrayROTest(read_only image1d_array_t scalarOCLImage1dArrayRO);
+void kernel OCLImage1dBufferROTest(read_only image1d_buffer_t scalarOCLImage1dBufferRO);
+void kernel OCLImage2dROTest(read_only image2d_t scalarOCLImage2dRO);
+void kernel OCLImage2dArrayROTest(read_only image2d_array_t scalarOCLImage2dArrayRO);
+void kernel OCLImage2dDepthROTest(read_only image2d_depth_t scalarOCLImage2dDepthRO);
+void kernel OCLImage2dArrayDepthROTest(read_only image2d_array_depth_t scalarOCLImage2dArrayDepthRO);
+void kernel OCLImage2dMSAAROTest(read_only image2d_msaa_t scalarOCLImage2dMSAARO);
+void kernel OCLImage2dArrayMSAAROTest(read_only image2d_array_msaa_t scalarOCLImage2dArrayMSAARO);
+void kernel OCLImage2dMSAADepthROTest(read_only image2d_msaa_depth_t scalarOCLImage2dMSAADepthRO);
+void kernel OCLImage2dArrayMSAADepthROTest(read_only image2d_array_msaa_depth_t scalarOCLImage2dArrayMSAADepthRO);
+void kernel OCLImage3dROTest(read_only image3d_t scalarOCLImage3dRO);
+
+// CHECK: ParmDecl=scalarOCLImage1dRO:28:50 (Definition) [type=__read_only image1d_t] [typekind=OCLImage1dRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage1dArrayRO:29:61 (Definition) [type=__read_only image1d_array_t] [typekind=OCLImage1dArrayRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage1dBufferRO:30:63 (Definition) [type=__read_only image1d_buffer_t] [typekind=OCLImage1dBufferRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dRO:31:50 (Definition) [type=__read_only image2d_t] [typekind=OCLImage2dRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dArrayRO:32:61 (Definition) [type=__read_only image2d_array_t] [typekind=OCLImage2dArrayRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dDepthRO:33:61 (Definition) [type=__read_only image2d_depth_t] [typekind=OCLImage2dDepthRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dArrayDepthRO:34:72 (Definition) [type=__read_only image2d_array_depth_t] [typekind=OCLImage2dArrayDepthRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dMSAARO:35:59 (Definition) [type=__read_only image2d_msaa_t] [typekind=OCLImage2dMSAARO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dArrayMSAARO:36:70 (Definition) [type=__read_only image2d_array_msaa_t] [typekind=OCLImage2dArrayMSAARO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dMSAADepthRO:37:70 (Definition) [type=__read_only image2d_msaa_depth_t] [typekind=OCLImage2dMSAADepthRO] [isPOD=1]
+// CHECK: ParmDecl=scalarOCLImage2dArrayMSAADepthRO:38:81 (Definition) [type=__read_only image2d_array_msaa_depth_t] [type

[clang-tools-extra] r303067 - [ClangD] Refactor clangd into separate components

2017-05-15 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Mon May 15 09:17:35 2017
New Revision: 303067

URL: http://llvm.org/viewvc/llvm-project?rev=303067&view=rev
Log:
[ClangD] Refactor clangd into separate components

Summary: Major refactoring to split LSP implementation, Clang API calls and 
threading(mostly synchronization)

Reviewers: bkramer, krasimir

Reviewed By: bkramer

Subscribers: cfe-commits, mgorny, klimek

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
  - copied, changed from r303060, 
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
  - copied, changed from r303063, 
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
  - copied, changed from r303060, 
clang-tools-extra/trunk/clangd/DocumentStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/Path.h
Removed:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/DocumentStore.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdMain.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h

Removed: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=303066&view=auto
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (original)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp (removed)
@@ -1,440 +0,0 @@
-//===--- ASTManager.cpp - Clang AST manager 
---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-
-#include "ASTManager.h"
-#include "JSONRPCDispatcher.h"
-#include "Protocol.h"
-#include "clang/Frontend/ASTUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
-#include "clang/Tooling/CompilationDatabase.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/Path.h"
-#include 
-#include 
-using namespace clang;
-using namespace clangd;
-
-void DocData::setAST(std::unique_ptr AST) {
-  this->AST = std::move(AST);
-}
-
-ASTUnit *DocData::getAST() const { return AST.get(); }
-
-void DocData::cacheFixIts(DiagnosticToReplacementMap FixIts) {
-  this->FixIts = std::move(FixIts);
-}
-
-std::vector
-DocData::getFixIts(const clangd::Diagnostic &D) const {
-  auto it = FixIts.find(D);
-  if (it != FixIts.end())
-return it->second;
-  return {};
-}
-
-ASTManagerRequest::ASTManagerRequest(ASTManagerRequestType Type,
- std::string File,
- DocVersion Version)
-: Type(Type), File(File), Version(Version) {}
-
-/// Retrieve a copy of the contents of every file in the store, for feeding 
into
-/// ASTUnit.
-static std::vector
-getRemappedFiles(const DocumentStore &Docs) {
-  // FIXME: Use VFS instead. This would allow us to get rid of the chdir below.
-  std::vector RemappedFiles;
-  for (const auto &P : Docs.getAllDocuments()) {
-StringRef FileName = P.first;
-RemappedFiles.push_back(ASTUnit::RemappedFile(
-FileName,
-llvm::MemoryBuffer::getMemBufferCopy(P.second, FileName).release()));
-  }
-  return RemappedFiles;
-}
-
-/// Convert from clang diagnostic level to LSP severity.
-static int getSeverity(DiagnosticsEngine::Level L) {
-  switch (L) {
-  case DiagnosticsEngine::Remark:
-return 4;
-  case DiagnosticsEngine::Note:
-return 3;
-  case DiagnosticsEngine::Warning:
-return 2;
-  case DiagnosticsEngine::Fatal:
-  case DiagnosticsEngine::Error:
-return 1;
-  case DiagnosticsEngine::Ignored:
-return 0;
-  }
-  llvm_unreachable("Unknown diagnostic level!");
-}
-
-static CompletionItemKind getKind(CXCursorKind K) {
-  switch (K) {
-  case CXCursor_MacroInstantiation:
-  case CXCursor_MacroDefinition:
-return CompletionItemKind::Text;
-  case CXCursor_CXXMethod:
-return CompletionItemKind::Method;
-  case CXCursor_FunctionDecl:
-  case CXCursor_FunctionTemplate:
-return CompletionItemKind::Function;
-  case CXCursor_Constructor:
-  case CXCursor_Destructor:
-return CompletionItemKind::Constru

r303068 - [index] References to fields from template instantiations should refer to

2017-05-15 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Mon May 15 09:26:22 2017
New Revision: 303068

URL: http://llvm.org/viewvc/llvm-project?rev=303068&view=rev
Log:
[index] References to fields from template instantiations should refer to
fields in base templates

rdar://32197158

Added:
cfe/trunk/test/Index/Core/index-instantiated-source.cpp
Modified:
cfe/trunk/lib/Index/IndexingContext.cpp

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=303068&r1=303067&r2=303068&view=diff
==
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Mon May 15 09:26:22 2017
@@ -124,6 +124,10 @@ bool IndexingContext::isTemplateImplicit
 TKind = FD->getTemplateSpecializationKind();
   } else if (auto *VD = dyn_cast(D)) {
 TKind = VD->getTemplateSpecializationKind();
+  } else if (isa(D)) {
+if (const auto *Parent =
+dyn_cast(D->getDeclContext()))
+  TKind = Parent->getSpecializationKind();
   }
   switch (TKind) {
 case TSK_Undeclared:
@@ -159,6 +163,17 @@ static const Decl *adjustTemplateImplici
 return FD->getTemplateInstantiationPattern();
   } else if (auto *VD = dyn_cast(D)) {
 return VD->getTemplateInstantiationPattern();
+  } else if (const auto *FD = dyn_cast(D)) {
+if (const auto *Parent =
+dyn_cast(D->getDeclContext())) {
+  const CXXRecordDecl *Pattern = Parent->getTemplateInstantiationPattern();
+  for (const NamedDecl *ND : Pattern->lookup(FD->getDeclName())) {
+if (ND->isImplicit())
+  continue;
+if (isa(ND))
+  return ND;
+  }
+}
   }
   return nullptr;
 }

Added: cfe/trunk/test/Index/Core/index-instantiated-source.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-instantiated-source.cpp?rev=303068&view=auto
==
--- cfe/trunk/test/Index/Core/index-instantiated-source.cpp (added)
+++ cfe/trunk/test/Index/Core/index-instantiated-source.cpp Mon May 15 09:26:22 
2017
@@ -0,0 +1,39 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++14 -target 
x86_64-apple-macosx10.7 | FileCheck %s
+// References to declarations in instantiations should be canonicalized:
+
+template
+class BaseTemplate {
+public:
+  T baseTemplateFunction();
+// CHECK: [[@LINE-1]]:5 | instance-method/C++ | baseTemplateFunction | 
c:@ST>1#T@BaseTemplate@F@baseTemplateFunction#
+
+  T baseTemplateField;
+// CHECK: [[@LINE-1]]:5 | field/C++ | baseTemplateField | 
c:@ST>1#T@BaseTemplate@FI@baseTemplateField
+};
+
+template
+class TemplateClass: public BaseTemplate {
+public:
+  T function() { return T(); }
+// CHECK: [[@LINE-1]]:5 | instance-method/C++ | function | 
c:@ST>2#T#T@TemplateClass@F@function#
+
+  static void staticFunction() { }
+// CHECK: [[@LINE-1]]:15 | static-method/C++ | staticFunction | 
c:@ST>2#T#T@TemplateClass@F@staticFunction#S
+
+  T field;
+// CHECK: [[@LINE-1]]:5 | field/C++ | field | 
c:@ST>2#T#T@TemplateClass@FI@field
+};
+
+void canonicalizeInstaniationReferences(TemplateClass &object) {
+  (void)object.function();
+// CHECK: [[@LINE-1]]:16 | instance-method/C++ | function | 
c:@ST>2#T#T@TemplateClass@F@function# | 
+  (void)object.field;
+// CHECK: [[@LINE-1]]:16 | field/C++ | field | 
c:@ST>2#T#T@TemplateClass@FI@field |  | Ref,RelCont | rel: 1
+  (void)object.baseTemplateFunction();
+// CHECK: [[@LINE-1]]:16 | instance-method/C++ | baseTemplateFunction | 
c:@ST>1#T@BaseTemplate@F@baseTemplateFunction# | 
+  (void)object.baseTemplateField;
+// CHECK: [[@LINE-1]]:16 | field/C++ | baseTemplateField | 
c:@ST>1#T@BaseTemplate@FI@baseTemplateField |  | Ref,RelCont | rel: 1
+
+  TemplateClass::staticFunction();
+// CHECK: [[@LINE-1]]:30 | static-method/C++ | staticFunction | 
c:@ST>2#T#T@TemplateClass@F@staticFunction#S | http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r303072 - [OpenCL] Emit function-scope variable in constant address space as static variable

2017-05-15 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Mon May 15 09:47:47 2017
New Revision: 303072

URL: http://llvm.org/viewvc/llvm-project?rev=303072&view=rev
Log:
[OpenCL] Emit function-scope variable in constant address space as static 
variable

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

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl
cfe/trunk/test/SemaOpenCL/storageclass.cl

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=303072&r1=303071&r2=303072&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon May 15 09:47:47 2017
@@ -966,9 +966,16 @@ public:
   /// hasLocalStorage - Returns true if a variable with function scope
   ///  is a non-static local variable.
   bool hasLocalStorage() const {
-if (getStorageClass() == SC_None)
+if (getStorageClass() == SC_None) {
+  // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
+  // used to describe variables allocated in global memory and which are
+  // accessed inside a kernel(s) as read-only variables. As such, variables
+  // in constant address space cannot have local storage.
+  if (getType().getAddressSpace() == LangAS::opencl_constant)
+return false;
   // Second check is for C++11 [dcl.stc]p4.
   return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
+}
 
 // Global Named Register (GNU extension)
 if (getStorageClass() == SC_Register && !isLocalVarDeclOrParm())

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=303072&r1=303071&r2=303072&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon May 15 09:47:47 2017
@@ -152,7 +152,14 @@ void CodeGenFunction::EmitDecl(const Dec
 /// EmitVarDecl - This method handles emission of any variable declaration
 /// inside a function, including static vars etc.
 void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
-  if (D.isStaticLocal()) {
+  if (D.hasExternalStorage())
+// Don't emit it now, allow it to be emitted lazily on its first use.
+return;
+
+  // Some function-scope variable does not have static storage but still
+  // needs to be emitted like a static variable, e.g. a function-scope
+  // variable in constant address space in OpenCL.
+  if (D.getStorageDuration() != SD_Automatic) {
 llvm::GlobalValue::LinkageTypes Linkage =
 CGM.getLLVMLinkageVarDefinition(&D, /*isConstant=*/false);
 
@@ -163,10 +170,6 @@ void CodeGenFunction::EmitVarDecl(const
 return EmitStaticVarDecl(D, Linkage);
   }
 
-  if (D.hasExternalStorage())
-// Don't emit it now, allow it to be emitted lazily on its first use.
-return;
-
   if (D.getType().getAddressSpace() == LangAS::opencl_local)
 return CGM.getOpenCLRuntime().EmitWorkGroupLocalVarDecl(*this, D);
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=303072&r1=303071&r2=303072&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Mon May 15 09:47:47 2017
@@ -10394,23 +10394,36 @@ void Sema::AddInitializerToDecl(Decl *Re
   VDecl->setInit(Init);
 
   if (VDecl->isLocalVarDecl()) {
+// Don't check the initializer if the declaration is malformed.
+if (VDecl->isInvalidDecl()) {
+  // do nothing
+
+// OpenCL v1.2 s6.5.3: __constant locals must be constant-initialized.
+// This is true even in OpenCL C++.
+} else if (VDecl->getType().getAddressSpace() == LangAS::opencl_constant) {
+  CheckForConstantInitializer(Init, DclT);
+
+// Otherwise, C++ does not restrict the initializer.
+} else if (getLangOpts().CPlusPlus) {
+  // do nothing
+
 // C99 6.7.8p4: All the expressions in an initializer for an object that 
has
 // static storage duration shall be constant expressions or string 
literals.
-// C++ does not have this restriction.
-if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl()) {
+} else if (VDecl->getStorageClass() == SC_Static) {
+  CheckForConstantInitializer(Init, DclT);
+
+// C89 is stricter than C99 for aggregate initializers.
+// C89 6.5.7p3: All the expressions [...] in an initializer list
+// for an object that has aggregate or union type shall be
+// constant expressions.
+} else if (!getLangOpts().C99 && VDecl->

[PATCH] D32977: [OpenCL] Emit function-scope variable in constant address space as static variable

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303072: [OpenCL] Emit function-scope variable in constant 
address space as static… (authored by yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D32977?vs=98510&id=99007#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32977

Files:
  cfe/trunk/include/clang/AST/Decl.h
  cfe/trunk/lib/CodeGen/CGDecl.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-pointer-address-space.cl
  cfe/trunk/test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
  cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl
  cfe/trunk/test/SemaOpenCL/storageclass.cl

Index: cfe/trunk/lib/CodeGen/CGDecl.cpp
===
--- cfe/trunk/lib/CodeGen/CGDecl.cpp
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp
@@ -152,7 +152,14 @@
 /// EmitVarDecl - This method handles emission of any variable declaration
 /// inside a function, including static vars etc.
 void CodeGenFunction::EmitVarDecl(const VarDecl &D) {
-  if (D.isStaticLocal()) {
+  if (D.hasExternalStorage())
+// Don't emit it now, allow it to be emitted lazily on its first use.
+return;
+
+  // Some function-scope variable does not have static storage but still
+  // needs to be emitted like a static variable, e.g. a function-scope
+  // variable in constant address space in OpenCL.
+  if (D.getStorageDuration() != SD_Automatic) {
 llvm::GlobalValue::LinkageTypes Linkage =
 CGM.getLLVMLinkageVarDefinition(&D, /*isConstant=*/false);
 
@@ -163,10 +170,6 @@
 return EmitStaticVarDecl(D, Linkage);
   }
 
-  if (D.hasExternalStorage())
-// Don't emit it now, allow it to be emitted lazily on its first use.
-return;
-
   if (D.getType().getAddressSpace() == LangAS::opencl_local)
 return CGM.getOpenCLRuntime().EmitWorkGroupLocalVarDecl(*this, D);
 
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -10394,23 +10394,36 @@
   VDecl->setInit(Init);
 
   if (VDecl->isLocalVarDecl()) {
+// Don't check the initializer if the declaration is malformed.
+if (VDecl->isInvalidDecl()) {
+  // do nothing
+
+// OpenCL v1.2 s6.5.3: __constant locals must be constant-initialized.
+// This is true even in OpenCL C++.
+} else if (VDecl->getType().getAddressSpace() == LangAS::opencl_constant) {
+  CheckForConstantInitializer(Init, DclT);
+
+// Otherwise, C++ does not restrict the initializer.
+} else if (getLangOpts().CPlusPlus) {
+  // do nothing
+
 // C99 6.7.8p4: All the expressions in an initializer for an object that has
 // static storage duration shall be constant expressions or string literals.
-// C++ does not have this restriction.
-if (!getLangOpts().CPlusPlus && !VDecl->isInvalidDecl()) {
+} else if (VDecl->getStorageClass() == SC_Static) {
+  CheckForConstantInitializer(Init, DclT);
+
+// C89 is stricter than C99 for aggregate initializers.
+// C89 6.5.7p3: All the expressions [...] in an initializer list
+// for an object that has aggregate or union type shall be
+// constant expressions.
+} else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() &&
+   isa(Init)) {
   const Expr *Culprit;
-  if (VDecl->getStorageClass() == SC_Static)
-CheckForConstantInitializer(Init, DclT);
-  // C89 is stricter than C99 for non-static aggregate types.
-  // C89 6.5.7p3: All the expressions [...] in an initializer list
-  // for an object that has aggregate or union type shall be
-  // constant expressions.
-  else if (!getLangOpts().C99 && VDecl->getType()->isAggregateType() &&
-   isa(Init) &&
-   !Init->isConstantInitializer(Context, false, &Culprit))
+  if (!Init->isConstantInitializer(Context, false, &Culprit)) {
 Diag(Culprit->getExprLoc(),
  diag::ext_aggregate_init_not_constant)
   << Culprit->getSourceRange();
+  }
 }
   } else if (VDecl->isStaticDataMember() && !VDecl->isInline() &&
  VDecl->getLexicalDeclContext()->isRecord()) {
Index: cfe/trunk/include/clang/AST/Decl.h
===
--- cfe/trunk/include/clang/AST/Decl.h
+++ cfe/trunk/include/clang/AST/Decl.h
@@ -966,9 +966,16 @@
   /// hasLocalStorage - Returns true if a variable with function scope
   ///  is a non-static local variable.
   bool hasLocalStorage() const {
-if (getStorageClass() == SC_None)
+if (getStorageClass() == SC_None) {
+  // OpenCL v1.2 s6.5.3: The __constant or constant address space name is
+  // used to describe variables allocated in global memory and which are
+  // accessed inside a kernel(s) as read-only variables. As such, variables
+  // in constant address space

[PATCH] D33201: [ClangD] Refactor ProtocolHandlers to decouple them from ClangdLSPServer

2017-05-15 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov updated this revision to Diff 99009.
ilya-biryukov added a comment.

Fixed a typo in a comment


https://reviews.llvm.org/D33201

Files:
  clangd/ClangdLSPServer.cpp
  clangd/ClangdLSPServer.h
  clangd/ClangdMain.cpp
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/JSONRPCDispatcher.cpp
  clangd/JSONRPCDispatcher.h
  clangd/ProtocolHandlers.cpp
  clangd/ProtocolHandlers.h

Index: clangd/ProtocolHandlers.h
===
--- clangd/ProtocolHandlers.h
+++ clangd/ProtocolHandlers.h
@@ -22,118 +22,34 @@
 
 namespace clang {
 namespace clangd {
-class ClangdLSPServer;
-class ClangdLSPServer;
 
-struct InitializeHandler : Handler {
-  InitializeHandler(JSONOutput &Output) : Handler(Output) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
-writeMessage(
-R"({"jsonrpc":"2.0","id":)" + ID +
-R"(,"result":{"capabilities":{
-  "textDocumentSync": 1,
-  "documentFormattingProvider": true,
-  "documentRangeFormattingProvider": true,
-  "documentOnTypeFormattingProvider": {"firstTriggerCharacter":"}","moreTriggerCharacter":[]},
-  "codeActionProvider": true,
-  "completionProvider": {"resolveProvider": false, "triggerCharacters": [".",">"]}
-}}})");
-  }
-};
-
-struct ShutdownHandler : Handler {
-  ShutdownHandler(JSONOutput &Output) : Handler(Output) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override {
-IsDone = true;
-  }
-
-  bool isDone() const { return IsDone; }
-
-private:
-  bool IsDone = false;
-};
-
-struct TextDocumentDidOpenHandler : Handler {
-  TextDocumentDidOpenHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer &AST;
+class ProtocolCallbacks {
+public:
+  virtual ~ProtocolCallbacks() = default;
+
+  virtual void onInitialize(StringRef ID, JSONOutput &Out) = 0;
+  virtual void onShutdown(JSONOutput &Out) = 0;
+  virtual void onDocumentDidOpen(DidOpenTextDocumentParams Params,
+ JSONOutput &Out) = 0;
+  virtual void onDocumentDidChange(DidChangeTextDocumentParams Params,
+   JSONOutput &Out) = 0;
+
+  virtual void onDocumentDidClose(DidCloseTextDocumentParams Params,
+  JSONOutput &Out) = 0;
+  virtual void onDocumentFormatting(DocumentFormattingParams Params,
+StringRef ID, JSONOutput &Out) = 0;
+  virtual void onDocumentOnTypeFormatting(DocumentOnTypeFormattingParams Params,
+  StringRef ID, JSONOutput &Out) = 0;
+  virtual void onDocumentRangeFormatting(DocumentRangeFormattingParams Params,
+ StringRef ID, JSONOutput &Out) = 0;
+  virtual void onCodeAction(CodeActionParams Params, StringRef ID,
+JSONOutput &Out) = 0;
+  virtual void onCompletion(TextDocumentPositionParams Params, StringRef ID,
+JSONOutput &Out) = 0;
 };
 
-struct TextDocumentDidChangeHandler : Handler {
-  TextDocumentDidChangeHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct TextDocumentDidCloseHandler : Handler {
-  TextDocumentDidCloseHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleNotification(llvm::yaml::MappingNode *Params) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct TextDocumentOnTypeFormattingHandler : Handler {
-  TextDocumentOnTypeFormattingHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct TextDocumentRangeFormattingHandler : Handler {
-  TextDocumentRangeFormattingHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct TextDocumentFormattingHandler : Handler {
-  TextDocumentFormattingHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct CodeActionHandler : Handler {
-  CodeActionHandler(JSONOutput &Output, ClangdLSPServer &AST)
-  : Handler(Output), AST(AST) {}
-
-  void handleMethod(llvm::yaml::MappingNode *Params, StringRef ID) override;
-
-private:
-  ClangdLSPServer &AST;
-};
-
-struct CompletionHandler : Handler {
-  CompletionHandler(JSONOutput &Output, ClangdLSPServer &AST)
-

[PATCH] D33029: [clang-format] add option for dangling parenthesis

2017-05-15 Thread Ryan Stringham via Phabricator via cfe-commits
stringham added a comment.

> Probably all of the examples from the original patch description and later 
> comments should be turned into unit tests.

I would like to add some unit tests for this, but was not able to figure out 
how to run the unit test suite. Where can I find instructions on how to run the 
unit tests?

I found out how to build clang-format from a combination of 
https://chromium.googlesource.com/chromium/src/+/master/docs/updating_clang_format_binaries.md
 and https://github.com/angular/clang-format#compiling-clang-format

I saw step 10 on http://clang.llvm.org/get_started.html says to run `make 
check-clang` from my build directory, but when I try that I get "No rule to 
make target" errors.




Comment at: docs/ClangFormatStyleOptions.rst:953
 
+**DanglingParenthesis** (``bool``)
+  If there is a break after the opening parenthesis, also break before the 
closing parenthesis

djasper wrote:
> Have you auto-generated this with docs/tools/dump_format_style.py? There seem 
> to be subtle differences.
I was not aware the dump_format_style.py existed. I created this manually based 
on the code around it. I will try running that script.



Comment at: include/clang/Format/Format.h:793
+  /// \endcode
+  bool DanglingParenthesis;
+

djasper wrote:
> I don't think this is a name that anyone will intuitively understand. I 
> understand that the naming is hard here. One thing I am wondering is whether 
> this might ever make sense unless AlignAfterOpenBracket is set to AlwaysBreak?
> 
> Unless that option is set, we could have both in the same file:
> 
>   someFunction(,
>);
> 
> and
> 
>   someFunction(
>   , 
>   );
> 
> Is that intended, i.e. are you actively using that? Answering this is 
> important, because it influence whether or not we actually need to add 
> another style option and even how to implement this.
The name was based on the configuration option that scalafmt has for their 
automatic scala formatter, they also have an option to have the closing paren 
on its own line and they call it `danglingParentheses`. I don't love the name 
and am open to other options.

That's a good point about AlignAfterOpenBracket being set to AlwaysBreak. In 
our usage we have that option set, and I'm also unsure if it makes sense 
without AlwaysBreak.


https://reviews.llvm.org/D33029



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


[PATCH] D33029: [clang-format] add option for dangling parenthesis

2017-05-15 Thread Ryan Stringham via Phabricator via cfe-commits
stringham updated this revision to Diff 99010.
stringham added a comment.

Generated the documentation using dump_format_style.py

removed some unnecessary braces.


https://reviews.llvm.org/D33029

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -8757,6 +8757,7 @@
   CHECK_PARSE_BOOL(BreakStringLiterals);
   CHECK_PARSE_BOOL(BreakBeforeInheritanceComma)
   CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
+  CHECK_PARSE_BOOL(DanglingParenthesis);
   CHECK_PARSE_BOOL(DerivePointerAlignment);
   CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
   CHECK_PARSE_BOOL(DisableFormat);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2652,7 +2652,9 @@
   if (Right.is(TT_ImplicitStringLiteral))
 return false;
 
-  if (Right.is(tok::r_paren) || Right.is(TT_TemplateCloser))
+  if (Right.is(tok::r_paren))
+return Style.DanglingParenthesis;
+  if (Right.is(TT_TemplateCloser))
 return false;
   if (Right.is(tok::r_square) && Right.MatchingParen &&
   Right.MatchingParen->is(TT_LambdaLSquare))
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -315,6 +315,7 @@
Style.BreakBeforeInheritanceComma);
 IO.mapOptional("ConstructorInitializerAllOnOneLineOrOnePerLine",
Style.ConstructorInitializerAllOnOneLineOrOnePerLine);
+IO.mapOptional("DanglingParenthesis", Style.DanglingParenthesis);
 IO.mapOptional("ConstructorInitializerIndentWidth",
Style.ConstructorInitializerIndentWidth);
 IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
@@ -541,6 +542,7 @@
   LLVMStyle.ColumnLimit = 80;
   LLVMStyle.CommentPragmas = "^ IWYU pragma:";
   LLVMStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = false;
+  LLVMStyle.DanglingParenthesis = false;
   LLVMStyle.ConstructorInitializerIndentWidth = 4;
   LLVMStyle.ContinuationIndentWidth = 4;
   LLVMStyle.Cpp11BracedListStyle = true;
@@ -606,6 +608,7 @@
   GoogleStyle.AlwaysBreakBeforeMultilineStrings = true;
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
+  GoogleStyle.DanglingParenthesis = false;
   GoogleStyle.DerivePointerAlignment = true;
   GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -149,12 +149,13 @@
   ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking,
  bool NoLineBreak)
   : Indent(Indent), LastSpace(LastSpace), NestedBlockIndent(Indent),
-BreakBeforeClosingBrace(false), AvoidBinPacking(AvoidBinPacking),
-BreakBeforeParameter(false), NoLineBreak(NoLineBreak),
-NoLineBreakInOperand(false), LastOperatorWrapped(true),
-ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
-AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false) {}
+BreakBeforeClosingBrace(false), BreakBeforeClosingParen(false),
+AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
+NoLineBreak(NoLineBreak), NoLineBreakInOperand(false),
+LastOperatorWrapped(true), ContainsLineBreak(false),
+ContainsUnwrappedBuilder(false), AlignColons(true),
+ObjCSelectorNameFound(false), HasMultipleNestedBlocks(false),
+NestedBlockInlined(false) {}
 
   /// \brief The position to which a specific parenthesis level needs to be
   /// indented.
@@ -210,6 +211,13 @@
   /// was a newline after the beginning left brace.
   bool BreakBeforeClosingBrace : 1;
 
+  /// \brief Whether a newline needs to be inserted before the block's closing
+  /// paren.
+  ///
+  /// We only want to insert a newline before the closing paren if there also
+  /// was a newline after the beginning left paren.
+  bool BreakBeforeClosingParen : 1;
+
   /// \brief Avoid bin packing, i.e. multiple parameters/elements on multiple
   /// lines, in this context.
   bool AvoidBinPacking : 1;
@@ -275,6 +283,8 @@
   return FirstLessLess < Other.FirstLessLess;
 if (BreakBeforeClosingBrace != Other.BreakBeforeClosingBrace)
   return BreakBeforeClosingBrace;
+i

[PATCH] D33010: Make google-build-using-namespace skip std::.*literals

2017-05-15 Thread Martin Ejdestig via Phabricator via cfe-commits
marejde updated this revision to Diff 99011.
marejde added a comment.

Modified isStdLiteralsNamespace() to be a static method.


https://reviews.llvm.org/D33010

Files:
  clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
  clang-tidy/google/UsingNamespaceDirectiveCheck.h
  test/clang-tidy/google-namespaces.cpp

Index: test/clang-tidy/google-namespaces.cpp
===
--- test/clang-tidy/google-namespaces.cpp
+++ test/clang-tidy/google-namespaces.cpp
@@ -6,3 +6,47 @@
 // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
 
 using spce::core; // no-warning
+
+namespace std {
+inline namespace literals {
+inline namespace chrono_literals {
+}
+inline namespace complex_literals {
+}
+inline namespace string_literals {
+}
+}
+}
+
+using namespace std::chrono_literals;// no-warning
+using namespace std::complex_literals;   // no-warning
+using namespace std::literals;   // no-warning
+using namespace std::literals::chrono_literals;  // no-warning
+using namespace std::literals::complex_literals; // no-warning
+using namespace std::literals::string_literals;  // no-warning
+using namespace std::string_literals;// no-warning
+
+namespace literals {}
+
+using namespace literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+namespace foo {
+inline namespace literals {
+inline namespace bar_literals {}
+}
+}
+
+using namespace foo::literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+using namespace foo::bar_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+using namespace foo::literals::bar_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+namespace foo_literals {}
+
+using namespace foo_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
Index: clang-tidy/google/UsingNamespaceDirectiveCheck.h
===
--- clang-tidy/google/UsingNamespaceDirectiveCheck.h
+++ clang-tidy/google/UsingNamespaceDirectiveCheck.h
@@ -38,6 +38,9 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  static bool isStdLiteralsNamespace(const NamespaceDecl *NS);
 };
 
 } // namespace build
Index: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
===
--- clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
+++ clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
@@ -34,12 +34,32 @@
   if (U->isImplicit() || !Loc.isValid())
 return;
 
+  // Do not warn if namespace is a std namespace with user-defined literals. The
+  // user-defined literals can only be used with a using directive.
+  if (isStdLiteralsNamespace(U->getNominatedNamespace()))
+return;
+
   diag(Loc, "do not use namespace using-directives; "
 "use using-declarations instead");
   // TODO: We could suggest a list of using directives replacing the using
   //   namespace directive.
 }
 
+bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
+const NamespaceDecl *NS) {
+  if (!NS->getName().endswith("literals"))
+return false;
+
+  const auto *Parent = dyn_cast_or_null(NS->getParent());
+  if (!Parent)
+return false;
+
+  if (Parent->isStdNamespace())
+return true;
+
+  return Parent->getName() == "literals" && Parent->getParent() &&
+ Parent->getParent()->isStdNamespace();
+}
 } // namespace build
 } // namespace google
 } // namespace tidy
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33010: Make google-build-using-namespace skip std::.*literals

2017-05-15 Thread Martin Ejdestig via Phabricator via cfe-commits
marejde added a comment.

> Do you need me to commit the patch for you?

Yes please. I do not have commit access.




Comment at: clang-tidy/google/UsingNamespaceDirectiveCheck.cpp:48
 
+bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
+const NamespaceDecl *NS) {

alexfh wrote:
> Please make this a static free function instead, since it doesn't need access 
> to the check's members.
Done.


https://reviews.llvm.org/D33010



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99014.
yaxunl added a comment.

Removed adjustAddrSpaceForAutoVar and use performAddrSpaceCast instead.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/Type.h
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl

Index: test/CodeGenOpenCL/amdgcn-automatic-variable.cl
===
--- /dev/null
+++ test/CodeGenOpenCL/amdgcn-automatic-variable.cl
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL1.2 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck -check-prefixes=CHECK,CL12 %s
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck -check-prefixes=CHECK,CL20 %s
+
+// CL12-LABEL: define void @func1(i32 addrspace(5)* %x)
+// CL20-LABEL: define void @func1(i32* %x)
+void func1(int *x) {
+  // CL12: %[[x_addr:.*]] = alloca i32 addrspace(5)*{{.*}}addrspace(5)
+  // CL12: store i32 addrspace(5)* %x, i32 addrspace(5)* addrspace(5)* %[[x_addr]]
+  // CL12: %[[r0:.*]] = load i32 addrspace(5)*, i32 addrspace(5)* addrspace(5)* %[[x_addr]]
+  // CL12: store i32 1, i32 addrspace(5)* %[[r0]]
+  // CL20: %[[x_addr:.*]] = alloca i32*{{.*}}addrspace(5)
+  // CL20: store i32* %x, i32* addrspace(5)* %[[x_addr]]
+  // CL20: %[[r0:.*]] = load i32*, i32* addrspace(5)* %[[x_addr]]
+  // CL20: store i32 1, i32* %[[r0]]
+  *x = 1;
+}
+
+// CHECK-LABEL: define void @func2()
+void func2(void) {
+  // CHECK: %lv1 = alloca i32, align 4, addrspace(5)
+  // CHECK: %lv2 = alloca i32, align 4, addrspace(5)
+  // CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
+  // CL12: %lp1 = alloca i32 addrspace(5)*, align 4, addrspace(5)
+  // CL12: %lp2 = alloca i32 addrspace(5)*, align 4, addrspace(5)
+  // CL20: %lp1 = alloca i32*, align 4, addrspace(5)
+  // CL20: %lp2 = alloca i32*, align 4, addrspace(5)
+  // CHECK: %lvc = alloca i32, align 4, addrspace(5)
+
+  // CHECK: store i32 1, i32 addrspace(5)* %lv1
+  int lv1;
+  lv1 = 1;
+  // CHECK: store i32 2, i32 addrspace(5)* %lv2
+  int lv2 = 2;
+
+  // CHECK: %[[arrayidx:.*]] = getelementptr inbounds [100 x i32], [100 x i32] addrspace(5)* %la, i64 0, i64 0
+  // CHECK: store i32 3, i32 addrspace(5)* %[[arrayidx]], align 4
+  int la[100];
+  la[0] = 3;
+
+  // CL12: store i32 addrspace(5)* %lv1, i32 addrspace(5)* addrspace(5)* %lp1, align 4
+  // CL20: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
+  // CL20: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 4
+  int *lp1 = &lv1;
+
+  // CHECK: %[[arraydecay:.*]] = getelementptr inbounds [100 x i32], [100 x i32] addrspace(5)* %la, i32 0, i32 0
+  // CL12: store i32 addrspace(5)* %[[arraydecay]], i32 addrspace(5)* addrspace(5)* %lp2, align 4
+  // CL20: %[[r1:.*]] = addrspacecast i32 addrspace(5)* %[[arraydecay]] to i32*
+  // CL20: store i32* %[[r1]], i32* addrspace(5)* %lp2, align 4
+  int *lp2 = la;
+
+  // CL12: call void @func1(i32 addrspace(5)* %lv1)
+  // CL20: %[[r2:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
+  // CL20: call void @func1(i32* %[[r2]])
+  func1(&lv1);
+
+  // CHECK: store i32 4, i32 addrspace(5)* %lvc
+  // CHECK: store i32 4, i32 addrspace(5)* %lv1
+  const int lvc = 4;
+  lv1 = lvc;
+}
Index: test/CodeGenCXX/amdgcn-automatic-variable.cpp
===
--- /dev/null
+++ test/CodeGenCXX/amdgcn-automatic-variable.cpp
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -O0 -triple amdgcn---amdgiz -emit-llvm %s -o - | FileCheck %s
+
+// CHECK-LABEL: define void @_Z5func1Pi(i32* %x)
+void func1(int *x) {
+  // CHECK: %[[x_addr:.*]] = alloca i32*{{.*}}addrspace(5)
+  // CHECK: store i32* %x, i32* addrspace(5)* %[[x_addr]]
+  // CHECK: %[[r0:.*]] = load i32*, i32* addrspace(5)* %[[x_addr]]
+  // CHECK: store i32 1, i32* %[[r0]]
+  *x = 1;
+}
+
+// CHECK-LABEL: define void @_Z5func2v()
+void func2(void) {
+  // CHECK: %lv1 = alloca i32, align 4, addrspace(5)
+  // CHECK: %lv2 = alloca i32, align 4, addrspace(5)
+  // CHECK: %la = alloca [100 x i32], align 4, addrspace(5)
+  // CHECK: %lp1 = alloca i32*, align 4, addrspace(5)
+  // CHECK: %lp2 = alloca i32*, align 4, addrspace(5)
+  // CHECK: %lvc = alloca i32, align 4, addrspace(5)
+
+  // CHECK: %[[r0:.*]] = addrspacecast i32 addrspace(5)* %lv1 to i32*
+  // CHECK: store i32 1, i32* %[[r0]]
+  int lv1;
+  lv1 = 1;
+  // CHECK: store i32 2, i32 addrspace(5)* %lv2
+  int lv2 = 2;
+
+  // CHECK: %[[r2:.*]] = addrspacecast [100 x i32] addrspace(5)* %la to [100 x i32]*
+  // CHECK: %[[arrayidx:.*]] = getelementptr inbounds [100 x i32], [100 x i32]* %[[r2]], i64 0, i64 0
+  // CHECK: store i32 3, i32* %[[arrayidx]], align 4
+  int la[100];
+  la[0] = 3;
+
+  // CHECK: store i32* %[[r0]], i32* addrspace(5)* %lp1, align 4
+  int *lp1 = &lv1;
+
+  // CHECK: %[[arr

[PATCH] D32896: [OpenCL] Make CLK_NULL_RESERVE_ID invalid reserve id.

2017-05-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Headers/opencl-c.h:16020
+// The macro CLK_NULL_RESERVE_ID refers to an invalid reservation ID.
+#define CLK_NULL_RESERVE_ID (__builtin_astype((void *)0, reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);

echuraev wrote:
> yaxunl wrote:
> > Anastasia wrote:
> > > yaxunl wrote:
> > > > Anastasia wrote:
> > > > > Looks good from my side.
> > > > > 
> > > > > @yaxunl , since you originally committed this. Could you please 
> > > > > verify that changing from `SIZE_MAX` to `0` would be fine.
> > > > > 
> > > > > Btw, we have a similar definition for `CLK_NULL_EVENT`.
> > > > `__PIPE_RESERVE_ID_VALID_BIT` is implementation detail and not part of 
> > > > the spec. I would suggest to remove it from this header file.
> > > > 
> > > > The spec only requires CLK_NULL_RESERVE_ID to be defined but does not 
> > > > define its value. Naturally a valid id starts from 0 and increases. I 
> > > > don't see significant advantage to change CLK_NULL_RESERVE_ID from 
> > > > __SIZE_MAX to 0.
> > > > 
> > > > Is there any reason that this change is needed?
> > > I don't see issues to commit things outside of spec as soon as they 
> > > prefixed properly with "__".  But I agree it would be nice to see if it's 
> > > any useful and what the motivation is for having different implementation.
> > For `__PIPE_RESERVE_ID_VALID_BIT`, it assumes that the implementation uses 
> > one specific bit of a reserve id to indicate that the reserve id is valid. 
> > Not all implementations assume that. Actually I am curious why that is 
> > needed too.
> About `CLK_NULL_RESERVE_ID`: we check that reserve id is valid if significant 
> bit equal to one. `CLK_NULL_RESERVE_ID refers to an invalid reservation, so 
> if `CLK_NULL_RESERVE_ID equal to 0, we can be sure that significant bit 
> doesn't equal to 1 and it is invalid reserve id. Also it is more obviously if 
> CLK_**NULL**_RESERVE_ID is equal to 0.
> 
> What about `__PIPE_RESERVE_ID_VALID_BIT`: As I understand previous 
> implementation also assumes that one specific bit was of a reverse id was 
> used to indicate that the reserve id is valid. So, we just increased reserve 
> id size by one bit on 32-bit platforms and by 33 bits on 64-bit platforms. 
It is more logical to me that `CLK_NULL_RESERVE_ID` is 0, but spec doesn't 
define it of course.


https://reviews.llvm.org/D32896



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


r303077 - [OPENMP] Check DSA for variables captured by value.

2017-05-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon May 15 11:26:15 2017
New Revision: 303077

URL: http://llvm.org/viewvc/llvm-project?rev=303077&view=rev
Log:
[OPENMP] Check DSA for variables captured by value.

Currently clang checks for default data sharing attributes only for
variables captured in OpenMP regions by reference. Patch adds checks for
variables captured by value.

Added:
cfe/trunk/test/OpenMP/report_default_DSA.cpp
Modified:
cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=303077&r1=303076&r2=303077&view=diff
==
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Mon May 15 11:26:15 2017
@@ -1112,7 +1112,7 @@ void CapturedStmt::setCapturedRegionKind
 
 bool CapturedStmt::capturesVariable(const VarDecl *Var) const {
   for (const auto &I : captures()) {
-if (!I.capturesVariable())
+if (!I.capturesVariable() && !I.capturesVariableByCopy())
   continue;
 
 // This does not handle variable redeclarations. This should be

Added: cfe/trunk/test/OpenMP/report_default_DSA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/report_default_DSA.cpp?rev=303077&view=auto
==
--- cfe/trunk/test/OpenMP/report_default_DSA.cpp (added)
+++ cfe/trunk/test/OpenMP/report_default_DSA.cpp Mon May 15 11:26:15 2017
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 %s
+
+void foo(int x, int n) {
+  double vec[n];
+  for (int iter = 0; iter < x; iter++) {
+#pragma omp target teams distribute parallel for map( \
+from  \
+: vec [0:n]) default(none)
+// expected-error@+1 {{variable 'n' must have explicitly specified data 
sharing attributes}}
+for (int ii = 0; ii < n; ii++) {
+  // expected-error@+3 {{variable 'iter' must have explicitly specified 
data sharing attributes}}
+  // expected-error@+2 {{variable 'vec' must have explicitly specified 
data sharing attributes}}
+  // expected-error@+1 {{variable 'x' must have explicitly specified data 
sharing attributes}}
+  vec[ii] = iter + ii + x;
+}
+  }
+}
+


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


[PATCH] D32896: [OpenCL] Make CLK_NULL_RESERVE_ID invalid reserve id.

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/Headers/opencl-c.h:16020
+// The macro CLK_NULL_RESERVE_ID refers to an invalid reservation ID.
+#define CLK_NULL_RESERVE_ID (__builtin_astype((void *)0, reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);

Anastasia wrote:
> echuraev wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > yaxunl wrote:
> > > > > Anastasia wrote:
> > > > > > Looks good from my side.
> > > > > > 
> > > > > > @yaxunl , since you originally committed this. Could you please 
> > > > > > verify that changing from `SIZE_MAX` to `0` would be fine.
> > > > > > 
> > > > > > Btw, we have a similar definition for `CLK_NULL_EVENT`.
> > > > > `__PIPE_RESERVE_ID_VALID_BIT` is implementation detail and not part 
> > > > > of the spec. I would suggest to remove it from this header file.
> > > > > 
> > > > > The spec only requires CLK_NULL_RESERVE_ID to be defined but does not 
> > > > > define its value. Naturally a valid id starts from 0 and increases. I 
> > > > > don't see significant advantage to change CLK_NULL_RESERVE_ID from 
> > > > > __SIZE_MAX to 0.
> > > > > 
> > > > > Is there any reason that this change is needed?
> > > > I don't see issues to commit things outside of spec as soon as they 
> > > > prefixed properly with "__".  But I agree it would be nice to see if 
> > > > it's any useful and what the motivation is for having different 
> > > > implementation.
> > > For `__PIPE_RESERVE_ID_VALID_BIT`, it assumes that the implementation 
> > > uses one specific bit of a reserve id to indicate that the reserve id is 
> > > valid. Not all implementations assume that. Actually I am curious why 
> > > that is needed too.
> > About `CLK_NULL_RESERVE_ID`: we check that reserve id is valid if 
> > significant bit equal to one. `CLK_NULL_RESERVE_ID refers to an invalid 
> > reservation, so if `CLK_NULL_RESERVE_ID equal to 0, we can be sure that 
> > significant bit doesn't equal to 1 and it is invalid reserve id. Also it is 
> > more obviously if CLK_**NULL**_RESERVE_ID is equal to 0.
> > 
> > What about `__PIPE_RESERVE_ID_VALID_BIT`: As I understand previous 
> > implementation also assumes that one specific bit was of a reverse id was 
> > used to indicate that the reserve id is valid. So, we just increased 
> > reserve id size by one bit on 32-bit platforms and by 33 bits on 64-bit 
> > platforms. 
> It is more logical to me that `CLK_NULL_RESERVE_ID` is 0, but spec doesn't 
> define it of course.
In our implementation, valid reserve id starts at 0 and increasing linearly 
until `__SIZE_MAX-1`. This change will break our implementation.

However, we can modify our implementation to adopt this change since it brings 
about benefits overall.


https://reviews.llvm.org/D32896



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


[clang-tools-extra] r303078 - Fix windows buildbots - missing include and namespace

2017-05-15 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon May 15 11:36:11 2017
New Revision: 303078

URL: http://llvm.org/viewvc/llvm-project?rev=303078&view=rev
Log:
Fix windows buildbots - missing include and namespace

Modified:
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h

Modified: clang-tools-extra/trunk/clangd/DraftStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.cpp?rev=303078&r1=303077&r2=303078&view=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.cpp Mon May 15 11:36:11 2017
@@ -29,7 +29,7 @@ DocVersion DraftStore::getVersion(PathRe
   return It->second.Version;
 }
 
-DocVersion DraftStore::updateDraft(PathRef File, StringRef Contents) {
+DocVersion DraftStore::updateDraft(PathRef File, llvm::StringRef Contents) {
   std::lock_guard Lock(Mutex);
 
   auto &Entry = Drafts[File];

Modified: clang-tools-extra/trunk/clangd/DraftStore.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.h?rev=303078&r1=303077&r2=303078&view=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.h (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.h Mon May 15 11:36:11 2017
@@ -45,7 +45,7 @@ public:
 
   /// Replace contents of the draft for \p File with \p Contents.
   /// \return The new version of the draft for \p File.
-  DocVersion updateDraft(PathRef File, StringRef Contents);
+  DocVersion updateDraft(PathRef File, llvm::StringRef Contents);
   /// Remove the contents of the draft
   /// \return The new version of the draft for \p File.
   DocVersion removeDraft(PathRef File);

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=303078&r1=303077&r2=303078&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Mon May 15 
11:36:11 2017
@@ -14,6 +14,7 @@
 #include "llvm/ADT/StringMap.h"
 #include 
 #include 
+#include 
 
 namespace clang {
 


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


[PATCH] D31745: [OpenCL] Added diagnostic for implicit declaration of function in OpenCL

2017-05-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:12449
   // function declaration is going to be treated as an error.
-  if (Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error) {
+  if (!getLangOpts().OpenCL &&
+  Diags.getDiagnosticLevel(diag_id, Loc) >= DiagnosticsEngine::Error) {

This way prevents the typo corrections completely for OpenCL which is not very 
desirable. I was just wondering could we prevent adding the invalid builtin 
function identifiers instead to the correction candidate list.

Like when `work_group_reserve_read_pipe` was first parsed it shouldn't have 
been added to the list of valid function identifiers to appear in the 
corrections of  'work_group_reserve_write_pipe'. I am guessing the identifier 
might be added when builtins are initialized...


https://reviews.llvm.org/D31745



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


[clang-tools-extra] r303081 - [clang-tidy] Partly rewrite readability-simplify-boolean-expr using RAV

2017-05-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon May 15 12:06:51 2017
New Revision: 303081

URL: http://llvm.org/viewvc/llvm-project?rev=303081&view=rev
Log:
[clang-tidy] Partly rewrite readability-simplify-boolean-expr using RAV

The check was using AST matchers in a very inefficient manner. By rewriting the
BinaryOperator-related parts using RAV, the check was sped up by a factor of
up to 1 on some files (mostly, generated code using binary operators in
tables), but also significantly sped up for regular large files.
As a side effect, the code became clearer and more readable.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.h

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp?rev=303081&r1=303080&r2=303081&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/SimplifyBooleanExprCheck.cpp 
Mon May 15 12:06:51 2017
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "SimplifyBooleanExprCheck.h"
+#include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Lex/Lexer.h"
 
 #include 
@@ -33,10 +34,6 @@ StringRef getText(const MatchFinder::Mat
   return getText(Result, Node.getSourceRange());
 }
 
-const char RightExpressionId[] = "bool-op-expr-yields-expr";
-const char LeftExpressionId[] = "expr-op-bool-yields-expr";
-const char NegatedRightExpressionId[] = "bool-op-expr-yields-not-expr";
-const char NegatedLeftExpressionId[] = "expr-op-bool-yields-not-expr";
 const char ConditionThenStmtId[] = "if-bool-yields-then";
 const char ConditionElseStmtId[] = "if-bool-yields-else";
 const char TernaryId[] = "ternary-bool-yields-condition";
@@ -54,8 +51,6 @@ const char CompoundBoolId[] = "compound-
 const char CompoundNotBoolId[] = "compound-bool-not";
 
 const char IfStmtId[] = "if";
-const char LHSId[] = "lhs-expr";
-const char RHSId[] = "rhs-expr";
 
 const char SimplifyOperatorDiagnostic[] =
 "redundant boolean literal supplied to boolean operator";
@@ -323,6 +318,25 @@ bool containsDiscardedTokens(const Match
 
 } // namespace
 
+class SimplifyBooleanExprCheck::Visitor : public RecursiveASTVisitor {
+  using Base = RecursiveASTVisitor;
+
+ public:
+  Visitor(SimplifyBooleanExprCheck *Check,
+  const MatchFinder::MatchResult &Result)
+  : Check(Check), Result(Result) {}
+
+  bool VisitBinaryOperator(BinaryOperator *Op) {
+Check->reportBinOp(Result, Op);
+return true;
+  }
+
+ private:
+  SimplifyBooleanExprCheck *Check;
+  const MatchFinder::MatchResult &Result;
+};
+
+
 SimplifyBooleanExprCheck::SimplifyBooleanExprCheck(StringRef Name,
ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
@@ -330,63 +344,82 @@ SimplifyBooleanExprCheck::SimplifyBoolea
   ChainedConditionalAssignment(
   Options.get("ChainedConditionalAssignment", 0U)) {}
 
-void SimplifyBooleanExprCheck::matchBoolBinOpExpr(MatchFinder *Finder,
-  bool Value,
-  StringRef OperatorName,
-  StringRef BooleanId) {
-  Finder->addMatcher(
-  binaryOperator(
-  isExpansionInMainFile(), hasOperatorName(OperatorName),
-  hasLHS(allOf(expr().bind(LHSId),
-   cxxBoolLiteral(equals(Value)).bind(BooleanId))),
-  hasRHS(expr().bind(RHSId)),
-  unless(hasRHS(hasDescendant(cxxBoolLiteral(),
-  this);
+bool containsBoolLiteral(const Expr *E) {
+  if (!E)
+return false;
+  E = E->IgnoreParenImpCasts();
+  if (isa(E))
+return true;
+  if (const auto *BinOp = dyn_cast(E))
+return containsBoolLiteral(BinOp->getLHS()) ||
+   containsBoolLiteral(BinOp->getRHS());
+  if (const auto *UnaryOp = dyn_cast(E))
+return containsBoolLiteral(UnaryOp->getSubExpr());
+  return false;
 }
 
-void SimplifyBooleanExprCheck::matchExprBinOpBool(MatchFinder *Finder,
-  bool Value,
-  StringRef OperatorName,
-  StringRef BooleanId) {
-  Finder->addMatcher(
-  binaryOperator(
-  isExpansionInMainFile(), hasOperatorName(OperatorName),
-  hasLHS(expr().bind(LHSId)),
-  unless(
-  hasLHS(anyOf(cxxBoolLiteral(), 
hasDescendant(cxxBoolLiteral(),
-  hasRHS(allOf(expr().bind(RHSId),
-   cxxBoolLiteral(equals(Value)).bind(BooleanId,
-  this);
-}
+void SimplifyBooleanExprCh

Re: r302966 - Remove unused tracking of owning module for MacroInfo objects.

2017-05-15 Thread Jordan Rose via cfe-commits
Hi, Richard. Swift was using this information in order to put imported macros 
in a particular context. It wouldn't surprise me to hear that we were doing it 
wrong, and that there's a better way to go from a macro back to a module, but 
is there a recommended replacement?

Thanks,
Jordan


> On May 12, 2017, at 16:40, Richard Smith via cfe-commits 
>  wrote:
> 
> Author: rsmith
> Date: Fri May 12 18:40:52 2017
> New Revision: 302966
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=302966&view=rev
> Log:
> Remove unused tracking of owning module for MacroInfo objects.
> 
> Modified:
>cfe/trunk/include/clang/Lex/MacroInfo.h
>cfe/trunk/include/clang/Lex/Preprocessor.h
>cfe/trunk/lib/Lex/MacroInfo.cpp
>cfe/trunk/lib/Lex/PPDirectives.cpp
>cfe/trunk/lib/Lex/Preprocessor.cpp
>cfe/trunk/lib/Serialization/ASTReader.cpp
>cfe/trunk/lib/Serialization/ASTWriter.cpp
> 
> Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=302966&r1=302965&r2=302966&view=diff
> ==
> --- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
> +++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri May 12 18:40:52 2017
> @@ -105,9 +105,6 @@ class MacroInfo {
>   /// \brief Must warn if the macro is unused at the end of translation unit.
>   bool IsWarnIfUnused : 1;
> 
> -  /// \brief Whether this macro info was loaded from an AST file.
> -  bool FromASTFile : 1;
> -
>   /// \brief Whether this macro was used as header guard.
>   bool UsedForHeaderGuard : 1;
> 
> @@ -264,34 +261,16 @@ public:
> IsDisabled = true;
>   }
> 
> -  /// \brief Determine whether this macro info came from an AST file (such as
> -  /// a precompiled header or module) rather than having been parsed.
> -  bool isFromASTFile() const { return FromASTFile; }
> -
>   /// \brief Determine whether this macro was used for a header guard.
>   bool isUsedForHeaderGuard() const { return UsedForHeaderGuard; }
> 
>   void setUsedForHeaderGuard(bool Val) { UsedForHeaderGuard = Val; }
> 
> -  /// \brief Retrieve the global ID of the module that owns this particular
> -  /// macro info.
> -  unsigned getOwningModuleID() const {
> -if (isFromASTFile())
> -  return *(const unsigned *)(this + 1);
> -
> -return 0;
> -  }
> -
>   void dump() const;
> 
> private:
>   unsigned getDefinitionLengthSlow(const SourceManager &SM) const;
> 
> -  void setOwningModuleID(unsigned ID) {
> -assert(isFromASTFile());
> -*(unsigned *)(this + 1) = ID;
> -  }
> -
>   friend class Preprocessor;
> };
> 
> 
> Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=302966&r1=302965&r2=302966&view=diff
> ==
> --- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
> +++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri May 12 18:40:52 2017
> @@ -644,14 +644,6 @@ class Preprocessor {
>   /// of that list.
>   MacroInfoChain *MIChainHead;
> 
> -  struct DeserializedMacroInfoChain {
> -MacroInfo MI;
> -unsigned OwningModuleID; // MUST be immediately after the MacroInfo 
> object
> - // so it can be accessed by 
> MacroInfo::getOwningModuleID().
> -DeserializedMacroInfoChain *Next;
> -  };
> -  DeserializedMacroInfoChain *DeserialMIChainHead;
> -
>   void updateOutOfDateIdentifier(IdentifierInfo &II) const;
> 
> public:
> @@ -1669,10 +1661,6 @@ public:
>   /// \brief Allocate a new MacroInfo object with the provided SourceLocation.
>   MacroInfo *AllocateMacroInfo(SourceLocation L);
> 
> -  /// \brief Allocate a new MacroInfo object loaded from an AST file.
> -  MacroInfo *AllocateDeserializedMacroInfo(SourceLocation L,
> -   unsigned SubModuleID);
> -
>   /// \brief Turn the specified lexer token into a fully checked and spelled
>   /// filename, e.g. as an operand of \#include. 
>   ///
> @@ -1764,9 +1752,6 @@ private:
>   /// macro name.
>   void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);
> 
> -  /// \brief Allocate a new MacroInfo object.
> -  MacroInfo *AllocateMacroInfo();
> -
>   DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI,
>SourceLocation Loc);
>   UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc);
> 
> Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=302966&r1=302965&r2=302966&view=diff
> ==
> --- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
> +++ cfe/trunk/lib/Lex/MacroInfo.cpp Fri May 12 18:40:52 2017
> @@ -29,7 +29,6 @@ MacroInfo::MacroInfo(SourceLocation DefL
> IsUsed(false),
> IsAllowRedefinitions

Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Steven Wu via cfe-commits
Hi Nico

Now that r262420 is landed. Is there any plan to move CUDA to the new approach 
so we can fix the UNIX conformance test?

Thanks

Steven

> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits 
>  wrote:
> 
> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> [Some necromancy here...]
> 
> This commit effectively reverted r173361 and r173825, breaking UNIX 
> conformance for our c99 wrapper.
> 
> See:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html 
> 
>> When c99 encounters a compilation error that causes an object file not to be 
>> created, it shall write a diagnostic to standard error and continue to 
>> compile other source code operands, but it shall not perform the link phase 
>> and it shall return a non-zero exit status.
> 
> 
> We had a test, but this commit changed that as well (I suppose it could have 
> been better documented).
> 
> How easily could this be restricted to only affect CUDA jobs?
> 
> If this gets reverted, the clang-cl PCH code needs to use the approach in 
> https://reviews.llvm.org/D17695  before I 
> rebased that patch over this revision here, so that a PCH compilation failure 
> stops the compilation of the main TU.
>  
> 
>> On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> 
>> Author: jlebar
>> Date: Wed Feb 24 15:49:28 2016
>> New Revision: 261774
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev 
>> 
>> Log:
>> Bail on compilation as soon as a job fails.
>> 
>> Summary:
>> (Re-land of r260448, which was reverted in r260522 due to a test failure
>> in Driver/output-file-cleanup.c that only showed up in fresh builds.)
>> 
>> Previously we attempted to be smart; if one job failed, we'd run all
>> jobs that didn't depend on the failing job.
>> 
>> Problem is, this doesn't work well for e.g. CUDA compilation without
>> -save-temps.  In this case, the device-side and host-side Assemble
>> actions (which actually are responsible for preprocess, compile,
>> backend, and assemble, since we're not saving temps) are necessarily
>> distinct.  So our clever heuristic doesn't help us, and we repeat every
>> error message once for host and once for each device arch.
>> 
>> The main effect of this change, other than fixing CUDA, is that if you
>> pass multiple cc files to one instance of clang and you get a compile
>> error, we'll stop when the first cc1 job fails.
>> 
>> Reviewers: echristo
>> 
>> Subscribers: cfe-commits, jhen, echristo, tra, rafael
>> 
>> Differential Revision: http://reviews.llvm.org/D17217 
>> 
>> 
>> Modified:
>>cfe/trunk/lib/Driver/Compilation.cpp
>>cfe/trunk/test/Driver/output-file-cleanup.c
>> 
>> Modified: cfe/trunk/lib/Driver/Compilation.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
>>  
>> 
>> ==
>> --- cfe/trunk/lib/Driver/Compilation.cpp (original)
>> +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
>> @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
>>   return ExecutionFailed ? 1 : Res;
>> }
>> 
>> -typedef SmallVectorImpl< std::pair > 
>> FailingCommandList;
>> -
>> -static bool ActionFailed(const Action *A,
>> - const FailingCommandList &FailingCommands) {
>> -
>> -  if (FailingCommands.empty())
>> -return false;
>> -
>> -  for (FailingCommandList::const_iterator CI = FailingCommands.begin(),
>> - CE = FailingCommands.end(); CI != CE; ++CI)
>> -if (A == &(CI->second->getSource()))
>> -  return true;
>> -
>> -  for (const Action *AI : A->inputs())
>> -if (ActionFailed(AI, FailingCommands))
>> -  return true;
>> -
>> -  return false;
>> -}
>> -
>> -static bool InputsOk(const Command &C,
>> - const FailingCommandList &FailingCommands) {
>> -  return !ActionFailed(&C.getSource(), FailingCommands);
>> -}
>> -
>> -void Compilation::ExecuteJobs(const JobList &Jobs,
>> -  FailingCommandList &FailingCommands) const {
>> +void Compilation::ExecuteJobs(
>> +const JobList &Jobs,
>> +SmallVectorImpl> &FailingCommands) 
>> const {
>>   for (const auto &Job : Jobs) {
>> -if (!InputsOk(Job, FailingCommands))
>> -  continue;
>> const Command *FailingCommand = nullptr;
>> -if (int Res = ExecuteCommand(Job, FailingCommand))
>> +if (int Res = ExecuteCommand(Job, FailingCommand)) {
>>   FailingCommands.push_back(std::make_pair(Res, FailingCommand));
>> +  // Bail as soon 

[PATCH] D32977: [OpenCL] Emit function-scope variable in constant address space as static variable

2017-05-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:10286
+  // these variables must be a compile time constant.
+  VDecl->getType().getAddressSpace() == LangAS::opencl_constant)
 CheckForConstantInitializer(Init, DclT);

yaxunl wrote:
> rjmccall wrote:
> > yaxunl wrote:
> > > Anastasia wrote:
> > > > yaxunl wrote:
> > > > > rjmccall wrote:
> > > > > > yaxunl wrote:
> > > > > > > rjmccall wrote:
> > > > > > > > Should this rule apply even in C++ mode?  I can't remember if 
> > > > > > > > there are any OpenCL/C++ hybrids.
> > > > > > > No. This rule (static local variable needs to be initialised with 
> > > > > > > compile-time constant) only applies to C and OpenCL. 
> > > > > > > In C++ static local variable can be initialised with 
> > > > > > > non-compile-time constant, in which case Clang will emit atomic 
> > > > > > > instructions to make sure it is only initialised once.
> > > > > > > 
> > > > > > > Currently OpenCL 2.2 defines OpenCL C++ but clang does not 
> > > > > > > support it.
> > > > > > Yes, I understand that C++ generally allows static locals to be 
> > > > > > lazily initialized, and that that rule would (probably) still apply 
> > > > > > to ordinary static locals in OpenCL C++.  However, I would expect 
> > > > > > that OpenCL C++ rule is that __constant local variables still need 
> > > > > > to be statically initialized, because there's no plausible way in 
> > > > > > the OpenCL implementation model to actually put lazily-initialized 
> > > > > > variables in the constant address space.  Assuming that's correct, 
> > > > > > then I would recommend reworking this whole chain of conditions to:
> > > > > > 
> > > > > >   // Don't check the initializer if the declaration is malformed.
> > > > > >   if (VDecl->isInvalidDecl()) {
> > > > > > // do nothing
> > > > > > 
> > > > > >   // OpenCL __constant locals must be constant-initialized, even in 
> > > > > > OpenCL C++.
> > > > > >   } else if (VDecl->getType().getAddressSpace() == 
> > > > > > LangAS::opencl_constant) {
> > > > > > CheckForConstantInitializer(Init, DclT);
> > > > > > 
> > > > > >   // Otherwise, C++ does not restrict the initializer.
> > > > > >   } else if (getLangOpts().CPlusPlus) {
> > > > > > // do nothing
> > > > > > 
> > > > > >   // C99 6.7.8p4: All the expressions in an initializer for an 
> > > > > > object that has
> > > > > >   // static storage duration shall be constant expressions or 
> > > > > > string literals.
> > > > > >   } else if (VDecl->getStorageClass() == SC_Static) {
> > > > > > CheckForConstantInitializer(Init, DclT);
> > > > > > 
> > > > > >   // C89 is stricter than C99 for aggregate initializers.
> > > > > >   // C89 6.5.7p3: All the expressions [...] in an initializer list
> > > > > >   // for an object that has aggregate or union type shall be
> > > > > >   // constant expressions.
> > > > > >   } else if (!getLangOpts().C99 && 
> > > > > > VDecl->getType()->isAggregateType() && isa(Init)) {
> > > > > > Expr *Culprit;
> > > > > > if (!Init->isConstantInitializer(Context, false, &Culprit)) {
> > > > > >   ...
> > > > > > }
> > > > > >   }
> > > > > Agree that even OpenCL C++ is unable to lazy initialise 
> > > > > function-scope var in constant addr space. Will do.
> > > > I think the original way would be much simpler to read and understand 
> > > > though.
> > > > 
> > > > To be honest I wouldn't complicate things now for the feature we don't 
> > > > support. I feel OpenCL C++ should be represented as a separate LangOpt 
> > > > since there are some places that will require special handling due to 
> > > > deviation from C++. I would rather extend things later in more 
> > > > systematic way.
> > > I will delete the comment about OpenCL C++ when committing.
> > I disagree.  Simple chains like this are almost always superior to building 
> > up complex logical conditions: the priorities between conditions are 
> > clearer (such as the interaction between __constant and C++ here), each 
> > condition can be conveniently documented without having to add comments to 
> > the middle of an expression, and there's less need to build up (A && !B) 
> > conditions just to make sure that cases are routed to the right place.  If 
> > the body of a clause is complex, it's usually a good idea to extract it 
> > into a separate function anyway, as has already been done here with 
> > CheckForConstantInitializer.
> > 
> > Deleting the comment about OpenCL C++ seems silly.  The comment is correct 
> > and explains why the clauses need to be ordered the way they are, and 
> > someone implementing OpenCL C++ support later will not think to add it back.
> > 
> > Please trust me that you would not want to use a different LangOpt for 
> > OpenCL C++.  OpenCL C++ may feel a little different from normal C++ to a 
> > user, but for the compiler its deviations are tiny compared to the number 
> > of ways in 

[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

2017-05-15 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki updated this revision to Diff 99022.
danielmarjamaki added a comment.

renamed exprComparesTo to svalComparesTo


Repository:
  rL LLVM

https://reviews.llvm.org/D30295

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
  lib/StaticAnalyzer/Core/CheckerHelpers.cpp
  test/Analysis/bitwise-ops.c

Index: test/Analysis/bitwise-ops.c
===
--- test/Analysis/bitwise-ops.c
+++ test/Analysis/bitwise-ops.c
@@ -29,4 +29,18 @@
   default:
 return 0;
   }
-}
\ No newline at end of file
+}
+
+int testOverflowShift(int a) {
+  if (a == 323) {
+return 1 << a; // expected-warning{{The result of the '<<' expression is undefined due to shift count >= width of type}}
+  }
+  return 0;
+}
+
+int testNegativeShift(int a) {
+  if (a == -5) {
+return 1 << a; // expected-warning{{The result of the '<<' expression is undefined due to negative value on the right side of operand}}
+  }
+  return 0;
+}
Index: lib/StaticAnalyzer/Core/CheckerHelpers.cpp
===
--- lib/StaticAnalyzer/Core/CheckerHelpers.cpp
+++ lib/StaticAnalyzer/Core/CheckerHelpers.cpp
@@ -94,3 +94,40 @@
 
   return std::make_pair(VD, RHS);
 }
+
+bool clang::ento::svalComparesTo(SVal LHSVal, BinaryOperatorKind ComparisonOp,
+ SVal RHSVal, ProgramStateRef State) {
+
+  if (LHSVal.isUnknownOrUndef())
+return false;
+  ProgramStateManager &Mgr = State->getStateManager();
+  if (!LHSVal.getAs() && LHSVal.getAs()) {
+LHSVal = Mgr.getStoreManager().getBinding(State->getStore(),
+  LHSVal.castAs());
+  }
+  if (LHSVal.isUnknownOrUndef() || !LHSVal.getAs())
+return false;
+
+  SValBuilder &Bldr = Mgr.getSValBuilder();
+  SVal Eval = Bldr.evalBinOp(State, ComparisonOp, LHSVal, RHSVal,
+ Bldr.getConditionType());
+  if (Eval.isUnknownOrUndef())
+return false;
+  ProgramStateRef StTrue, StFalse;
+  std::tie(StTrue, StFalse) = State->assume(Eval.castAs());
+  return StTrue && !StFalse;
+}
+
+// Is E value greater or equal than Val?
+bool clang::ento::isGreaterOrEqual(const Expr *E, unsigned long long Val,
+   CheckerContext &C) {
+  DefinedSVal V =
+  C.getSValBuilder().makeIntVal(Val, C.getASTContext().LongLongTy);
+  return svalComparesTo(C.getSVal(E), BO_GE, V, C.getState());
+}
+
+// Is E value negative?
+bool clang::ento::isNegative(const Expr *E, CheckerContext &C) {
+  DefinedSVal V = C.getSValBuilder().makeIntVal(0, false);
+  return svalComparesTo(C.getSVal(E), BO_LT, V, C.getState());
+}
Index: lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
@@ -17,6 +17,7 @@
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerHelpers.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/raw_ostream.h"
@@ -59,6 +60,11 @@
   return StOutBound && !StInBound;
 }
 
+static bool isShiftOverflow(const BinaryOperator *B, CheckerContext &C) {
+  return isGreaterOrEqual(
+  B->getRHS(), C.getASTContext().getIntWidth(B->getLHS()->getType()), C);
+}
+
 void UndefResultChecker::checkPostStmt(const BinaryOperator *B,
CheckerContext &C) const {
   ProgramStateRef state = C.getState();
@@ -103,12 +109,26 @@
  << "' is a garbage value";
   if (isArrayIndexOutOfBounds(C, Ex))
 OS << " due to array index out of bounds";
-}
-else {
+} else {
   // Neither operand was undefined, but the result is undefined.
-  OS << "The result of the '"
- << BinaryOperator::getOpcodeStr(B->getOpcode())
- << "' expression is undefined";
+  if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
+   B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
+  isNegative(B->getRHS(), C)) {
+OS << "The result of the '"
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to negative value on the right "
+  "side of operand";
+  } else if ((B->getOpcode() == BinaryOperatorKind::BO_Shl ||
+  B->getOpcode() == BinaryOperatorKind::BO_Shr) &&
+ isShiftOverflow(B, C)) {
+OS << "The result of the '"
+   << BinaryOperator::getOpcodeStr(B->getOpcode())
+   << "' expression is undefined due to shift count >= width of type";
+  } else {
+

[clang-tools-extra] r303085 - Make google-build-using-namespace skip std::.*literals

2017-05-15 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Mon May 15 12:37:48 2017
New Revision: 303085

URL: http://llvm.org/viewvc/llvm-project?rev=303085&view=rev
Log:
Make google-build-using-namespace skip std::.*literals

Summary:
C++14 added a couple of user-defined literals in the standard library. E.g.
std::chrono_literals and std::literals::chrono_literals . Using them
requires a using directive so do not warn in google-build-using-namespace
if namespace name starts with "std::" and ends with "literals".

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Patch by Martin Ejdestig!

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

Modified:
clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp?rev=303085&r1=303084&r2=303085&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp 
Mon May 15 12:37:48 2017
@@ -34,12 +34,32 @@ void UsingNamespaceDirectiveCheck::check
   if (U->isImplicit() || !Loc.isValid())
 return;
 
+  // Do not warn if namespace is a std namespace with user-defined literals. 
The
+  // user-defined literals can only be used with a using directive.
+  if (isStdLiteralsNamespace(U->getNominatedNamespace()))
+return;
+
   diag(Loc, "do not use namespace using-directives; "
 "use using-declarations instead");
   // TODO: We could suggest a list of using directives replacing the using
   //   namespace directive.
 }
 
+bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
+const NamespaceDecl *NS) {
+  if (!NS->getName().endswith("literals"))
+return false;
+
+  const auto *Parent = dyn_cast_or_null(NS->getParent());
+  if (!Parent)
+return false;
+
+  if (Parent->isStdNamespace())
+return true;
+
+  return Parent->getName() == "literals" && Parent->getParent() &&
+ Parent->getParent()->isStdNamespace();
+}
 } // namespace build
 } // namespace google
 } // namespace tidy

Modified: 
clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h?rev=303085&r1=303084&r2=303085&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h 
Mon May 15 12:37:48 2017
@@ -38,6 +38,9 @@ public:
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  static bool isStdLiteralsNamespace(const NamespaceDecl *NS);
 };
 
 } // namespace build

Modified: clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp?rev=303085&r1=303084&r2=303085&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp Mon May 15 
12:37:48 2017
@@ -6,3 +6,47 @@ using namespace spce;
 // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use 
using-declarations instead [google-build-using-namespace]
 
 using spce::core; // no-warning
+
+namespace std {
+inline namespace literals {
+inline namespace chrono_literals {
+}
+inline namespace complex_literals {
+}
+inline namespace string_literals {
+}
+}
+}
+
+using namespace std::chrono_literals;// no-warning
+using namespace std::complex_literals;   // no-warning
+using namespace std::literals;   // no-warning
+using namespace std::literals::chrono_literals;  // no-warning
+using namespace std::literals::complex_literals; // no-warning
+using namespace std::literals::string_literals;  // no-warning
+using namespace std::string_literals;// no-warning
+
+namespace literals {}
+
+using namespace literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use 
using-declarations instead [google-build-using-namespace]
+
+namespace foo {
+inline namespace literals {
+inline namespace bar_literals {}
+}
+}
+
+using namespace foo::literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use 
using-declarations instead [

[PATCH] D33010: Make google-build-using-namespace skip std::.*literals

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303085: Make google-build-using-namespace skip 
std::.*literals (authored by alexfh).

Changed prior to commit:
  https://reviews.llvm.org/D33010?vs=99011&id=99025#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33010

Files:
  clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
  clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
  clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-namespaces.cpp
@@ -6,3 +6,47 @@
 // CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
 
 using spce::core; // no-warning
+
+namespace std {
+inline namespace literals {
+inline namespace chrono_literals {
+}
+inline namespace complex_literals {
+}
+inline namespace string_literals {
+}
+}
+}
+
+using namespace std::chrono_literals;// no-warning
+using namespace std::complex_literals;   // no-warning
+using namespace std::literals;   // no-warning
+using namespace std::literals::chrono_literals;  // no-warning
+using namespace std::literals::complex_literals; // no-warning
+using namespace std::literals::string_literals;  // no-warning
+using namespace std::string_literals;// no-warning
+
+namespace literals {}
+
+using namespace literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+namespace foo {
+inline namespace literals {
+inline namespace bar_literals {}
+}
+}
+
+using namespace foo::literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+using namespace foo::bar_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+using namespace foo::literals::bar_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
+
+namespace foo_literals {}
+
+using namespace foo_literals;
+// CHECK: :[[@LINE-1]]:1: warning: do not use namespace using-directives; use using-declarations instead [google-build-using-namespace]
Index: clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
+++ clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.h
@@ -38,6 +38,9 @@
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+
+private:
+  static bool isStdLiteralsNamespace(const NamespaceDecl *NS);
 };
 
 } // namespace build
Index: clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp
@@ -34,12 +34,32 @@
   if (U->isImplicit() || !Loc.isValid())
 return;
 
+  // Do not warn if namespace is a std namespace with user-defined literals. The
+  // user-defined literals can only be used with a using directive.
+  if (isStdLiteralsNamespace(U->getNominatedNamespace()))
+return;
+
   diag(Loc, "do not use namespace using-directives; "
 "use using-declarations instead");
   // TODO: We could suggest a list of using directives replacing the using
   //   namespace directive.
 }
 
+bool UsingNamespaceDirectiveCheck::isStdLiteralsNamespace(
+const NamespaceDecl *NS) {
+  if (!NS->getName().endswith("literals"))
+return false;
+
+  const auto *Parent = dyn_cast_or_null(NS->getParent());
+  if (!Parent)
+return false;
+
+  if (Parent->isStdNamespace())
+return true;
+
+  return Parent->getName() == "literals" && Parent->getParent() &&
+ Parent->getParent()->isStdNamespace();
+}
 } // namespace build
 } // namespace google
 } // namespace tidy
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Tony Tye via Phabricator via cfe-commits
t-tye added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1115
+  assert(T.getAddressSpace() == LangAS::Default ||
+ T.getQualifiers().hasTargetSpecificAddressSpace());
+  auto Addr = getTargetHooks().performAddrSpaceCast(*this,

Should allowing specifying an address space on a function local automatic 
variable in OpenCL be allowed? It seems generating LLVM IR that allocates the 
variable in the alloca address space then address space casting the pointer to 
some other address space is not what such a language feature is requesting.

It seems it is really requesting that the variable is allocated in a different 
address space. That could be indicated by putting a different address space on 
the alloca itself, but the builder only allows an alloca to use the default 
alloca address space. No target supports this ability.

So maybe the best solution is to make OpenCL be the same as C and not allow an 
address space qualifier on function scope automatic variables.

If that is done then this assert will only allow the language default address 
space.


https://reviews.llvm.org/D32248



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 2 inline comments as done.
yaxunl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1115
+  assert(T.getAddressSpace() == LangAS::Default ||
+ T.getQualifiers().hasTargetSpecificAddressSpace());
+  auto Addr = getTargetHooks().performAddrSpaceCast(*this,

t-tye wrote:
> Should allowing specifying an address space on a function local automatic 
> variable in OpenCL be allowed? It seems generating LLVM IR that allocates the 
> variable in the alloca address space then address space casting the pointer 
> to some other address space is not what such a language feature is requesting.
> 
> It seems it is really requesting that the variable is allocated in a 
> different address space. That could be indicated by putting a different 
> address space on the alloca itself, but the builder only allows an alloca to 
> use the default alloca address space. No target supports this ability.
> 
> So maybe the best solution is to make OpenCL be the same as C and not allow 
> an address space qualifier on function scope automatic variables.
> 
> If that is done then this assert will only allow the language default address 
> space.
Agree. I think that is why C++ forbids `__attribute__((address_space(n))` on 
automatic variables. I will make it apply to all languages.


https://reviews.llvm.org/D32248



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


[clang-tools-extra] r303094 - Revert "[ClangD] Refactor clangd into separate components"

2017-05-15 Thread Adam Nemet via cfe-commits
Author: anemet
Date: Mon May 15 13:14:35 2017
New Revision: 303094

URL: http://llvm.org/viewvc/llvm-project?rev=303094&view=rev
Log:
Revert "[ClangD] Refactor clangd into separate components"

This reverts commit r303067.

Caused http://green.lab.llvm.org/green/job/clang-stage1-configure-RA/34305/

And even after Simon's fix there is still a test failure.

Added:
clang-tools-extra/trunk/clangd/ASTManager.cpp
clang-tools-extra/trunk/clangd/ASTManager.h
clang-tools-extra/trunk/clangd/DocumentStore.h
Removed:
clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
clang-tools-extra/trunk/clangd/ClangdLSPServer.h
clang-tools-extra/trunk/clangd/ClangdServer.cpp
clang-tools-extra/trunk/clangd/ClangdServer.h
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/ClangdUnit.h
clang-tools-extra/trunk/clangd/ClangdUnitStore.cpp
clang-tools-extra/trunk/clangd/ClangdUnitStore.h
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/clangd/Path.h
Modified:
clang-tools-extra/trunk/clangd/CMakeLists.txt
clang-tools-extra/trunk/clangd/ClangdMain.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.cpp
clang-tools-extra/trunk/clangd/ProtocolHandlers.h

Added: clang-tools-extra/trunk/clangd/ASTManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ASTManager.cpp?rev=303094&view=auto
==
--- clang-tools-extra/trunk/clangd/ASTManager.cpp (added)
+++ clang-tools-extra/trunk/clangd/ASTManager.cpp Mon May 15 13:14:35 2017
@@ -0,0 +1,440 @@
+//===--- ASTManager.cpp - Clang AST manager 
---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ASTManager.h"
+#include "JSONRPCDispatcher.h"
+#include "Protocol.h"
+#include "clang/Frontend/ASTUnit.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
+#include 
+#include 
+using namespace clang;
+using namespace clangd;
+
+void DocData::setAST(std::unique_ptr AST) {
+  this->AST = std::move(AST);
+}
+
+ASTUnit *DocData::getAST() const { return AST.get(); }
+
+void DocData::cacheFixIts(DiagnosticToReplacementMap FixIts) {
+  this->FixIts = std::move(FixIts);
+}
+
+std::vector
+DocData::getFixIts(const clangd::Diagnostic &D) const {
+  auto it = FixIts.find(D);
+  if (it != FixIts.end())
+return it->second;
+  return {};
+}
+
+ASTManagerRequest::ASTManagerRequest(ASTManagerRequestType Type,
+ std::string File,
+ DocVersion Version)
+: Type(Type), File(File), Version(Version) {}
+
+/// Retrieve a copy of the contents of every file in the store, for feeding 
into
+/// ASTUnit.
+static std::vector
+getRemappedFiles(const DocumentStore &Docs) {
+  // FIXME: Use VFS instead. This would allow us to get rid of the chdir below.
+  std::vector RemappedFiles;
+  for (const auto &P : Docs.getAllDocuments()) {
+StringRef FileName = P.first;
+RemappedFiles.push_back(ASTUnit::RemappedFile(
+FileName,
+llvm::MemoryBuffer::getMemBufferCopy(P.second, FileName).release()));
+  }
+  return RemappedFiles;
+}
+
+/// Convert from clang diagnostic level to LSP severity.
+static int getSeverity(DiagnosticsEngine::Level L) {
+  switch (L) {
+  case DiagnosticsEngine::Remark:
+return 4;
+  case DiagnosticsEngine::Note:
+return 3;
+  case DiagnosticsEngine::Warning:
+return 2;
+  case DiagnosticsEngine::Fatal:
+  case DiagnosticsEngine::Error:
+return 1;
+  case DiagnosticsEngine::Ignored:
+return 0;
+  }
+  llvm_unreachable("Unknown diagnostic level!");
+}
+
+static CompletionItemKind getKind(CXCursorKind K) {
+  switch (K) {
+  case CXCursor_MacroInstantiation:
+  case CXCursor_MacroDefinition:
+return CompletionItemKind::Text;
+  case CXCursor_CXXMethod:
+return CompletionItemKind::Method;
+  case CXCursor_FunctionDecl:
+  case CXCursor_FunctionTemplate:
+return CompletionItemKind::Function;
+  case CXCursor_Constructor:
+  case CXCursor_Destructor:
+return CompletionItemKind::Constructor;
+  case CXCursor_FieldDecl:
+return CompletionItemKind::Field;
+  case CXCursor_VarDecl:
+  case CXCursor_ParmDecl:
+return CompletionItemKind::Variable;
+  case CXCursor_ClassDecl:
+  case CXCursor_StructDecl:
+  case CXCursor_UnionDecl:
+  case CXCursor_ClassTemplate:
+  case CXCursor_ClassTemplatePartialSpecialization:
+return Completion

[clang-tools-extra] r303093 - Revert "Fix windows buildbots - missing include and namespace"

2017-05-15 Thread Adam Nemet via cfe-commits
Author: anemet
Date: Mon May 15 13:14:31 2017
New Revision: 303093

URL: http://llvm.org/viewvc/llvm-project?rev=303093&view=rev
Log:
Revert "Fix windows buildbots - missing include and namespace"

This reverts commit r303078.

One test is still failing even after this:
http://green.lab.llvm.org/green/job/clang-stage1-configure-RA_check/31374/consoleFull#18373900728254eaf0-7326-4999-85b0-388101f2d404

Modified:
clang-tools-extra/trunk/clangd/DraftStore.cpp
clang-tools-extra/trunk/clangd/DraftStore.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h

Modified: clang-tools-extra/trunk/clangd/DraftStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.cpp?rev=303093&r1=303092&r2=303093&view=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.cpp (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.cpp Mon May 15 13:14:31 2017
@@ -29,7 +29,7 @@ DocVersion DraftStore::getVersion(PathRe
   return It->second.Version;
 }
 
-DocVersion DraftStore::updateDraft(PathRef File, llvm::StringRef Contents) {
+DocVersion DraftStore::updateDraft(PathRef File, StringRef Contents) {
   std::lock_guard Lock(Mutex);
 
   auto &Entry = Drafts[File];

Modified: clang-tools-extra/trunk/clangd/DraftStore.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/DraftStore.h?rev=303093&r1=303092&r2=303093&view=diff
==
--- clang-tools-extra/trunk/clangd/DraftStore.h (original)
+++ clang-tools-extra/trunk/clangd/DraftStore.h Mon May 15 13:14:31 2017
@@ -45,7 +45,7 @@ public:
 
   /// Replace contents of the draft for \p File with \p Contents.
   /// \return The new version of the draft for \p File.
-  DocVersion updateDraft(PathRef File, llvm::StringRef Contents);
+  DocVersion updateDraft(PathRef File, StringRef Contents);
   /// Remove the contents of the draft
   /// \return The new version of the draft for \p File.
   DocVersion removeDraft(PathRef File);

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h?rev=303093&r1=303092&r2=303093&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h Mon May 15 
13:14:31 2017
@@ -14,7 +14,6 @@
 #include "llvm/ADT/StringMap.h"
 #include 
 #include 
-#include 
 
 namespace clang {
 


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


[PATCH] D33207: Fix an assertion failure in FormatASTNodeDiagnosticArgument.

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh created this revision.

The test being added in this patch used to cause an assertion failure:

/build/./bin/clang -cc1 -internal-isystem /build/lib/clang/5.0.0/include 
-nostdsysteminc -verify -fsyntax-only -std=c++11 -Wshadow-all 
/src/tools/clang/test/SemaCXX/warn-shadow.cpp


Exit Code: 134

Command Output (stderr):


clang: /src/tools/clang/lib/AST/ASTDiagnostic.cpp:424: void 
clang::FormatASTNodeDiagnosticArgument(DiagnosticsEngine::ArgumentKind, 
intptr_t, llvm::StringRef, llvm::StringRef, 
ArrayRef, SmallVectorImpl &, void *, 
ArrayRef): Assertion `isa(DC) && "Expected a NamedDecl"' 
failed.
Stack dump:
0.  Program arguments: /build/./bin/clang -cc1 -internal-isystem 
/build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 
-Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp

1. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:214:23: current parser token 
';'
2. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: parsing function body 
'handleLinkageSpec'
3. /src/tools/clang/test/SemaCXX/warn-shadow.cpp:213:26: in compound statement 
('{}')

/build/tools/clang/test/SemaCXX/Output/warn-shadow.cpp.script: line 1: 15595 
Aborted (core dumped) /build/./bin/clang -cc1 -internal-isystem 
/build/lib/clang/5.0.0/include -nostdsysteminc -verify -fsyntax-only -std=c++11 
-Wshadow-all /src/tools/clang/test/SemaCXX/warn-shadow.cpp


https://reviews.llvm.org/D33207

Files:
  lib/AST/ASTDiagnostic.cpp
  test/SemaCXX/warn-shadow.cpp


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -206,3 +206,10 @@
 }
 
 }
+
+extern "C" {
+typedef int externC; // expected-note {{previous declaration is here}}
+}
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in 
linkage specification}}
+}
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -420,6 +420,8 @@
 OS << ConvertTypeToDiagnosticString(Context,
 Context.getTypeDeclType(Type),
 PrevArgs, QualTypeVals);
+  } else if (const auto *LS = dyn_cast(DC)) {
+OS << "linkage specification";
   } else {
 assert(isa(DC) && "Expected a NamedDecl");
 NamedDecl *ND = cast(DC);


Index: test/SemaCXX/warn-shadow.cpp
===
--- test/SemaCXX/warn-shadow.cpp
+++ test/SemaCXX/warn-shadow.cpp
@@ -206,3 +206,10 @@
 }
 
 }
+
+extern "C" {
+typedef int externC; // expected-note {{previous declaration is here}}
+}
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in linkage specification}}
+}
Index: lib/AST/ASTDiagnostic.cpp
===
--- lib/AST/ASTDiagnostic.cpp
+++ lib/AST/ASTDiagnostic.cpp
@@ -420,6 +420,8 @@
 OS << ConvertTypeToDiagnosticString(Context,
 Context.getTypeDeclType(Type),
 PrevArgs, QualTypeVals);
+  } else if (const auto *LS = dyn_cast(DC)) {
+OS << "linkage specification";
   } else {
 assert(isa(DC) && "Expected a NamedDecl");
 NamedDecl *ND = cast(DC);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33207: Fix an assertion failure in FormatASTNodeDiagnosticArgument.

2017-05-15 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added a comment.

The patch is trivial, I'm mostly wondering about the wording and whether we 
want to expand the "linkage specification" to specify whether it is `extern 
"C"` or `extern "C++"`, for example.


https://reviews.llvm.org/D33207



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


[clang-tools-extra] r303095 - [clang-tidy] Fix a typo: dequeue => deque

2017-05-15 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Mon May 15 13:18:28 2017
New Revision: 303095

URL: http://llvm.org/viewvc/llvm-project?rev=303095&view=rev
Log:
[clang-tidy] Fix a typo: dequeue => deque

Modified:

clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp?rev=303095&r1=303094&r2=303095&view=diff
==
--- 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 (original)
+++ 
clang-tools-extra/trunk/clang-tidy/performance/InefficientVectorOperationCheck.cpp
 Mon May 15 13:18:28 2017
@@ -55,7 +55,7 @@ static const char RangeLoopName[] = "for
 ast_matchers::internal::Matcher supportedContainerTypesMatcher() {
   return hasType(cxxRecordDecl(hasAnyName(
   "::std::vector", "::std::set", "::std::unordered_set", "::std::map",
-  "::std::unordered_map", "::std::array", "::std::dequeue")));
+  "::std::unordered_map", "::std::array", "::std::deque")));
 }
 
 } // namespace


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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1115
+  assert(T.getAddressSpace() == LangAS::Default ||
+ T.getQualifiers().hasTargetSpecificAddressSpace());
+  auto Addr = getTargetHooks().performAddrSpaceCast(*this,

yaxunl wrote:
> t-tye wrote:
> > Should allowing specifying an address space on a function local automatic 
> > variable in OpenCL be allowed? It seems generating LLVM IR that allocates 
> > the variable in the alloca address space then address space casting the 
> > pointer to some other address space is not what such a language feature is 
> > requesting.
> > 
> > It seems it is really requesting that the variable is allocated in a 
> > different address space. That could be indicated by putting a different 
> > address space on the alloca itself, but the builder only allows an alloca 
> > to use the default alloca address space. No target supports this ability.
> > 
> > So maybe the best solution is to make OpenCL be the same as C and not allow 
> > an address space qualifier on function scope automatic variables.
> > 
> > If that is done then this assert will only allow the language default 
> > address space.
> Agree. I think that is why C++ forbids `__attribute__((address_space(n))` on 
> automatic variables. I will make it apply to all languages.
Yeah, the embedded C specification (ISO/IEC TR 18037) says "an address space 
name cannot be used to qualify an object that has automatic storage duration", 
so this restriction should be applied regardless of language mode.  We can deal 
with the possibility of auto variables in other address spaces when someone 
wants to add that capability.

(OpenCL's __constant is an acceptable exception because it implicitly makes the 
variable static.)





Comment at: lib/CodeGen/CGDecl.cpp:1119
+  T.getAddressSpace(), address.getPointer()->getType()->
+  getPointerElementType()->getPointerTo(getContext().getTargetAddressSpace(
+  T.getAddressSpace())), true);

Hmm.  I would prefer if we could avoid doing this in the fast path.  Suggestion:

  - Please add a variable (ASTAllocaAddressSpace) to CodeGenTypeCache that 
stores the AST address space of the stack.  You can add a function to 
CodeGenTargetInfo to initialize this; in most targets, it will just return 0, 
but your target can make it ~0U or something, anything works as long as it 
doesn't incorrectly match an actual target address space.  (But you should 
really consider adding an actual target-specific address space for the stack!  
It'll probably be useful in builtin code or something eventually.)

  - Please add an assert that T.getAddressSpace() == 0, and then make this call 
conditional on whether ASTAllocaAddressSpace is non-zero.

You can just write address.getElementType() instead of 
address.getPointer()->getType()->getPointerElementType().

Are you intentionally leaving emission.Addr as the unconverted pointer?  That 
will probably mess everything else downstream that uses 'emission', and the 
only reason you're not seeing that is that OpenCL probably doesn't actually 
have anything downstream that uses 'emission' — destructors or whatever else.

Please add an inline comment like
   , /*non-null*/ true);



Comment at: lib/CodeGen/TargetInfo.cpp:7294
   llvm::PointerType *T, QualType QT) const override;
+
 };

Spurious newline?


https://reviews.llvm.org/D32248



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


Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Nico Weber via cfe-commits
r262420 landed in a way adapted to Justin's change. An earlier version of
https://reviews.llvm.org/D17695 had a different approach. I don't know if
that approach could be used for CUDA. Justin should reply here.

On Mon, May 15, 2017 at 1:32 PM, Steven Wu  wrote:

> Hi Nico
>
> Now that r262420 is landed. Is there any plan to move CUDA to the new
> approach so we can fix the UNIX conformance test?
>
> Thanks
>
> Steven
>
> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> [Some necromancy here...]
>>
>> This commit effectively reverted r173361 and r173825, breaking UNIX
>> conformance for our c99 wrapper.
>>
>> See:
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html
>>
>> When c99 encounters a compilation error that causes an object file not to
>> be created, it shall write a diagnostic to standard error and continue to
>> compile other source code operands, but it shall not perform the link phase
>> and it shall return a non-zero exit status.
>>
>>
>> We had a test, but this commit changed that as well (I suppose it could
>> have been better documented).
>>
>> How easily could this be restricted to only affect CUDA jobs?
>>
>
> If this gets reverted, the clang-cl PCH code needs to use the approach in
> https://reviews.llvm.org/D17695 before I rebased that patch over this
> revision here, so that a PCH compilation failure stops the compilation of
> the main TU.
>
>
>>
>> On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>> Author: jlebar
>> Date: Wed Feb 24 15:49:28 2016
>> New Revision: 261774
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev
>> Log:
>> Bail on compilation as soon as a job fails.
>>
>> Summary:
>> (Re-land of r260448, which was reverted in r260522 due to a test failure
>> in Driver/output-file-cleanup.c that only showed up in fresh builds.)
>>
>> Previously we attempted to be smart; if one job failed, we'd run all
>> jobs that didn't depend on the failing job.
>>
>> Problem is, this doesn't work well for e.g. CUDA compilation without
>> -save-temps.  In this case, the device-side and host-side Assemble
>> actions (which actually are responsible for preprocess, compile,
>> backend, and assemble, since we're not saving temps) are necessarily
>> distinct.  So our clever heuristic doesn't help us, and we repeat every
>> error message once for host and once for each device arch.
>>
>> The main effect of this change, other than fixing CUDA, is that if you
>> pass multiple cc files to one instance of clang and you get a compile
>> error, we'll stop when the first cc1 job fails.
>>
>> Reviewers: echristo
>>
>> Subscribers: cfe-commits, jhen, echristo, tra, rafael
>>
>> Differential Revision: http://reviews.llvm.org/D17217
>>
>> Modified:
>>cfe/trunk/lib/Driver/Compilation.cpp
>>cfe/trunk/test/Driver/output-file-cleanup.c
>>
>> Modified: cfe/trunk/lib/Driver/Compilation.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Com
>> pilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
>> 
>> ==
>> --- cfe/trunk/lib/Driver/Compilation.cpp (original)
>> +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
>> @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
>>   return ExecutionFailed ? 1 : Res;
>> }
>>
>> -typedef SmallVectorImpl< std::pair >
>> FailingCommandList;
>> -
>> -static bool ActionFailed(const Action *A,
>> - const FailingCommandList &FailingCommands) {
>> -
>> -  if (FailingCommands.empty())
>> -return false;
>> -
>> -  for (FailingCommandList::const_iterator CI = FailingCommands.begin(),
>> - CE = FailingCommands.end(); CI != CE; ++CI)
>> -if (A == &(CI->second->getSource()))
>> -  return true;
>> -
>> -  for (const Action *AI : A->inputs())
>> -if (ActionFailed(AI, FailingCommands))
>> -  return true;
>> -
>> -  return false;
>> -}
>> -
>> -static bool InputsOk(const Command &C,
>> - const FailingCommandList &FailingCommands) {
>> -  return !ActionFailed(&C.getSource(), FailingCommands);
>> -}
>> -
>> -void Compilation::ExecuteJobs(const JobList &Jobs,
>> -  FailingCommandList &FailingCommands)
>> const {
>> +void Compilation::ExecuteJobs(
>> +const JobList &Jobs,
>> +SmallVectorImpl> &FailingCommands)
>> const {
>>   for (const auto &Job : Jobs) {
>> -if (!InputsOk(Job, FailingCommands))
>> -  continue;
>> const Command *FailingCommand = nullptr;
>> -if (int Res = ExecuteCommand(Job, FailingCommand))
>> +if (int Res = ExecuteCommand(Job, FailingCommand)) {
>>   FailingCommands.push_back(std::make_pair(Res, FailingCommand));
>> +  // Bail as soon as one command fails, so we don't outp

[PATCH] D32977: [OpenCL] Emit function-scope variable in constant address space as static variable

2017-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:10286
+  // these variables must be a compile time constant.
+  VDecl->getType().getAddressSpace() == LangAS::opencl_constant)
 CheckForConstantInitializer(Init, DclT);

Anastasia wrote:
> yaxunl wrote:
> > rjmccall wrote:
> > > yaxunl wrote:
> > > > Anastasia wrote:
> > > > > yaxunl wrote:
> > > > > > rjmccall wrote:
> > > > > > > yaxunl wrote:
> > > > > > > > rjmccall wrote:
> > > > > > > > > Should this rule apply even in C++ mode?  I can't remember if 
> > > > > > > > > there are any OpenCL/C++ hybrids.
> > > > > > > > No. This rule (static local variable needs to be initialised 
> > > > > > > > with compile-time constant) only applies to C and OpenCL. 
> > > > > > > > In C++ static local variable can be initialised with 
> > > > > > > > non-compile-time constant, in which case Clang will emit atomic 
> > > > > > > > instructions to make sure it is only initialised once.
> > > > > > > > 
> > > > > > > > Currently OpenCL 2.2 defines OpenCL C++ but clang does not 
> > > > > > > > support it.
> > > > > > > Yes, I understand that C++ generally allows static locals to be 
> > > > > > > lazily initialized, and that that rule would (probably) still 
> > > > > > > apply to ordinary static locals in OpenCL C++.  However, I would 
> > > > > > > expect that OpenCL C++ rule is that __constant local variables 
> > > > > > > still need to be statically initialized, because there's no 
> > > > > > > plausible way in the OpenCL implementation model to actually put 
> > > > > > > lazily-initialized variables in the constant address space.  
> > > > > > > Assuming that's correct, then I would recommend reworking this 
> > > > > > > whole chain of conditions to:
> > > > > > > 
> > > > > > >   // Don't check the initializer if the declaration is malformed.
> > > > > > >   if (VDecl->isInvalidDecl()) {
> > > > > > > // do nothing
> > > > > > > 
> > > > > > >   // OpenCL __constant locals must be constant-initialized, even 
> > > > > > > in OpenCL C++.
> > > > > > >   } else if (VDecl->getType().getAddressSpace() == 
> > > > > > > LangAS::opencl_constant) {
> > > > > > > CheckForConstantInitializer(Init, DclT);
> > > > > > > 
> > > > > > >   // Otherwise, C++ does not restrict the initializer.
> > > > > > >   } else if (getLangOpts().CPlusPlus) {
> > > > > > > // do nothing
> > > > > > > 
> > > > > > >   // C99 6.7.8p4: All the expressions in an initializer for an 
> > > > > > > object that has
> > > > > > >   // static storage duration shall be constant expressions or 
> > > > > > > string literals.
> > > > > > >   } else if (VDecl->getStorageClass() == SC_Static) {
> > > > > > > CheckForConstantInitializer(Init, DclT);
> > > > > > > 
> > > > > > >   // C89 is stricter than C99 for aggregate initializers.
> > > > > > >   // C89 6.5.7p3: All the expressions [...] in an initializer list
> > > > > > >   // for an object that has aggregate or union type shall be
> > > > > > >   // constant expressions.
> > > > > > >   } else if (!getLangOpts().C99 && 
> > > > > > > VDecl->getType()->isAggregateType() && isa(Init)) {
> > > > > > > Expr *Culprit;
> > > > > > > if (!Init->isConstantInitializer(Context, false, &Culprit)) {
> > > > > > >   ...
> > > > > > > }
> > > > > > >   }
> > > > > > Agree that even OpenCL C++ is unable to lazy initialise 
> > > > > > function-scope var in constant addr space. Will do.
> > > > > I think the original way would be much simpler to read and understand 
> > > > > though.
> > > > > 
> > > > > To be honest I wouldn't complicate things now for the feature we 
> > > > > don't support. I feel OpenCL C++ should be represented as a separate 
> > > > > LangOpt since there are some places that will require special 
> > > > > handling due to deviation from C++. I would rather extend things 
> > > > > later in more systematic way.
> > > > I will delete the comment about OpenCL C++ when committing.
> > > I disagree.  Simple chains like this are almost always superior to 
> > > building up complex logical conditions: the priorities between conditions 
> > > are clearer (such as the interaction between __constant and C++ here), 
> > > each condition can be conveniently documented without having to add 
> > > comments to the middle of an expression, and there's less need to build 
> > > up (A && !B) conditions just to make sure that cases are routed to the 
> > > right place.  If the body of a clause is complex, it's usually a good 
> > > idea to extract it into a separate function anyway, as has already been 
> > > done here with CheckForConstantInitializer.
> > > 
> > > Deleting the comment about OpenCL C++ seems silly.  The comment is 
> > > correct and explains why the clauses need to be ordered the way they are, 
> > > and someone implementing OpenCL C++ support later will not think to add 
> > > it back.
> > > 
> > > Please trust me that you would not w

r303106 - clang-format: [JS] for async loops.

2017-05-15 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Mon May 15 14:33:20 2017
New Revision: 303106

URL: http://llvm.org/viewvc/llvm-project?rev=303106&view=rev
Log:
clang-format: [JS] for async loops.

Summary:
JavaScript supports asynchronous loop iteration in async functions:

for async (const x of y) ...

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.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=303106&r1=303105&r2=303106&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 15 14:33:20 2017
@@ -576,9 +576,12 @@ private:
   }
   break;
 case tok::kw_for:
-  if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
-  Tok->Previous->is(tok::period))
-break;
+  if (Style.Language == FormatStyle::LK_JavaScript)
+if (Tok->Previous && Tok->Previous->is(tok::period))
+  break;
+// JS' for async ( ...
+if (CurrentToken->is(Keywords.kw_async))
+  next();
   Contexts.back().ColonIsForRangeExpr = true;
   next();
   if (!parseParens())
@@ -2249,6 +2252,10 @@ bool TokenAnnotator::spaceRequiredBefore
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=303106&r1=303105&r2=303106&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon May 15 14:33:20 2017
@@ -1635,6 +1635,10 @@ void UnwrappedLineParser::parseForOrWhil
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  // JS' for async ( ...
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+  FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=303106&r1=303105&r2=303106&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon May 15 14:33:20 2017
@@ -548,6 +548,15 @@ TEST_F(FormatTestJS, AsyncFunctions) {
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {


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


[PATCH] D33193: clang-format: [JS] for async loops.

2017-05-15 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
mprobst marked an inline comment as done.
Closed by commit rL303106: clang-format: [JS] for async loops. (authored by 
mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D33193?vs=98997&id=99048#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33193

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -576,9 +576,12 @@
   }
   break;
 case tok::kw_for:
-  if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
-  Tok->Previous->is(tok::period))
-break;
+  if (Style.Language == FormatStyle::LK_JavaScript)
+if (Tok->Previous && Tok->Previous->is(tok::period))
+  break;
+// JS' for async ( ...
+if (CurrentToken->is(Keywords.kw_async))
+  next();
   Contexts.back().ColonIsForRangeExpr = true;
   next();
   if (!parseParens())
@@ -2249,6 +2252,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1635,6 +1635,10 @@
   assert(FormatTok->isOneOf(tok::kw_for, tok::kw_while, TT_ForEachMacro) &&
  "'for', 'while' or foreach macro expected");
   nextToken();
+  // JS' for async ( ...
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+  FormatTok->is(Keywords.kw_async))
+nextToken();
   if (FormatTok->Tok.is(tok::l_paren))
 parseParens();
   if (FormatTok->Tok.is(tok::l_brace)) {


Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -548,6 +548,15 @@
"  // Comment.\n"
"  return async.then();\n"
"}\n");
+  verifyFormat("for async (const x of y) {\n"
+   "  console.log(x);\n"
+   "}\n");
+  verifyFormat("function asyncLoop() {\n"
+   "  for async (const x of y) {\n"
+   "console.log(x);\n"
+   "  }\n"
+   "}\n");
+
 }
 
 TEST_F(FormatTestJS, FunctionParametersTrailingComma) {
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -576,9 +576,12 @@
   }
   break;
 case tok::kw_for:
-  if (Style.Language == FormatStyle::LK_JavaScript && Tok->Previous &&
-  Tok->Previous->is(tok::period))
-break;
+  if (Style.Language == FormatStyle::LK_JavaScript)
+if (Tok->Previous && Tok->Previous->is(tok::period))
+  break;
+// JS' for async ( ...
+if (CurrentToken->is(Keywords.kw_async))
+  next();
   Contexts.back().ColonIsForRangeExpr = true;
   next();
   if (!parseParens())
@@ -2249,6 +2252,10 @@
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
+// for async ( ...
+if (Right.is(tok::l_paren) && Left.is(Keywords.kw_async) &&
+Left.Previous && Left.Previous->is(tok::kw_for))
+  return true;
 if (Left.is(Keywords.kw_async) && Right.is(tok::l_paren) &&
 Right.MatchingParen) {
   const FormatToken *Next = Right.MatchingParen->getNextNonComment();
Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
==

RE: r302935 - [Sema] Support implicit scalar to vector conversions

2017-05-15 Thread Simon Dardis via cfe-commits

Thanks, I'll try and look at this tomorrow.

Simon



From: Vitaly Buka [vitalyb...@google.com]

Sent: 15 May 2017 20:57

To: Simon Dardis; cfe-commits@lists.llvm.org

Subject: Re: r302935 - [Sema] Support implicit scalar to vector conversions


From ubsan bot:

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/4892/steps/check-clang%20ubsan/logs/stdio

llvm/tools/clang/lib/Sema/SemaExpr.cpp:8257:9: runtime error: load of value 
4294967295, which is not a valid value for type 'clang::CastKind'
#0 0x5bc3b88 in tryGCCVectorConvertAndSplat(clang::Sema&, 
clang::ActionResult*, clang::ActionResult*) 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Sema/SemaExpr.cpp:8257:9
#1 0x5bbbea5 in 
clang::Sema::CheckVectorOperands(clang::ActionResult&, 
clang::ActionResult&, clang::SourceLocation, bool, bool, 
bool) 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Sema/SemaExpr.cpp:8352:12
#2 0x5bcc553 in 
clang::Sema::CheckVectorCompareOperands(clang::ActionResult&, clang::ActionResult&, clang::SourceLocation, bool) 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Sema/SemaExpr.cpp:9990:20
#3 0x5bc93a8 in 
clang::Sema::CheckCompareOperands(clang::ActionResult&, 
clang::ActionResult&, clang::SourceLocation, 
clang::BinaryOperatorKind, bool) 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/Sema/SemaExpr.cpp:9495:12



On Fri, May 12, 2017 at 12:24 PM Simon Dardis via cfe-commits 
 wrote:



Author: sdardis

Date: Fri May 12 14:11:06 2017

New Revision: 302935



URL: 
http://llvm.org/viewvc/llvm-project?rev=302935&view=rev

Log:

[Sema] Support implicit scalar to vector conversions



This patch teaches clang to perform implicit scalar to vector conversions

when one of the operands of a binary vector expression is a scalar which

can be converted to the element type of the vector without truncation

following GCC's implementation.



If the (constant) scalar is can be casted safely, it is implicitly casted to the

vector elements type and splatted to produce a vector of the same type.



Contributions from: Petar Jovanovic



Reviewers: bruno, vkalintiris



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





Added:

cfe/trunk/test/Sema/vector-gcc-compat.c

cfe/trunk/test/Sema/vector-gcc-compat.cpp

Modified:

cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

cfe/trunk/include/clang/Sema/Sema.h

cfe/trunk/lib/Sema/SemaExpr.cpp

cfe/trunk/lib/Sema/SemaExprCXX.cpp

cfe/trunk/test/Sema/vector-cast.c

cfe/trunk/test/Sema/vector-ops.c

cfe/trunk/test/Sema/zvector.c

cfe/trunk/test/SemaCXX/vector-no-lax.cpp



Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=302935&r1=302934&r2=302935&view=diff

==

--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)

+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri May 12 14:11:06 
2017

@@ -2465,6 +2465,9 @@ def err_attribute_invalid_size : Error<

   "vector size not an integral multiple of component size">;

 def err_attribute_zero_size : Error<"zero vector size">;

 def err_attribute_size_too_large : Error<"vector size too large">;

+def err_typecheck_vector_not_convertable_implict_truncation : Error<

+   "cannot convert between %select{scalar|vector}0 type %1 and vector type"

+   " %2 as implicit conversion would cause truncation">;

 def err_typecheck_vector_not_convertable : Error<

   "cannot convert between vector values of different size (%0 and %1)">;

 def err_typecheck_vector_not_convertable_non_scalar : Error<

@@ -5779,6 +5782,9 @@ def err_objc_object_assignment : Error<

   "cannot assign to class object (%0 invalid)">;

 def err_typecheck_invalid_operands : Error<

   "invalid operands to binary expression (%0 and %1)">;

+def err_typecheck_logical_vector_expr_gnu_cpp_restrict : Error<

+  "logical expression with vector %select{type %1 and non-vector type %2|types"

+  " %1 and %2}0 is only supported in C++">;

 def err_typecheck_sub_ptr_compatible : Error<

   "%diff{$ and $ are not pointers to compatible types|"

   "pointers to incompatible types}0,1">;



Modified: cfe/trunk/include/clang/Sema/Sema.h

URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=302935&r1=302934&r2=302935&view=diff

==

--- cfe/trunk/include/clang/Sema/Sema.h (original)

+++ cfe/trunk/include/clang/Sema/Sema.h Fri May 12 14:11:06 2017

@@ -9285,6 +9285,8 @@ public:

   /// type checking binary operators (subroutines of CreateBuiltinBinOp).

   QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS,

ExprResult &RHS);

+  Qu

[PATCH] D33207: Fix an assertion failure in FormatASTNodeDiagnosticArgument.

2017-05-15 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: test/SemaCXX/warn-shadow.cpp:214
+void handleLinkageSpec() {
+  typedef void externC; // expected-warning {{declaration shadows a typedef in 
linkage specification}}
+}

We should be producing a diagnostic talking about the enclosing namespace / TU 
scope, not the linkage specification. Whoever is emitting the diagnostic seems 
to be missing a call to `getRedeclContext()` -- although perhaps we could do 
that in the diagnostic code instead.


https://reviews.llvm.org/D33207



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99056.
yaxunl marked an inline comment as done.
yaxunl added a comment.

diagnose automatic var with invalid addr space for OpenCL.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/SemaOpenCL/atomic-init.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = &G4;
-  private int *constant L7 = &x; // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = &L1;
-  local int *constant L9 = &L2; // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{automatic variable qualified with an invalid address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = &G4;
+  private int *constant L8 = &x;  // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = &L1;
+  local int *constant L10 = &L2;  // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{automatic variable qualified with an invalid address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{automatic variable qualified with an invalid address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function scope cannot be declared static}}
+
+
+  extern constant float L5;
+  extern local float L6; // expected-error{{extern variable must reside in constant address space}}
+
+  static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
+  static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
Index: test/SemaOpenCL/storageclass-cl20.cl
===
--- test/SemaOpenCL/storageclass-cl20.cl
+++ test/SemaOpenCL/storageclass-c

[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-15 Thread Krzysztof Parzyszek via Phabricator via cfe-commits
kparzysz added a comment.

In https://reviews.llvm.org/D31885#751164, @rjmccall wrote:

> The right fix is probably just to make sure that EmitLValueForField doesn't 
> add TBAA information when the base LValue doesn't have it.  That will also 
> fix problems with recursive member access where the base is may_alias.


That won't work for arrays that are member of unions.  We'd need to change 
EmitArraySubscriptExpr, which at some point calls MakeAddrLValue for the type 
being loaded/stored. MakeAddrLValue adds TBAAInfo for that type (unsigned short 
in case of the C testcase) and it does so regardless of any struct paths. This 
TBAA info must be removed for the testcase to be fixed.  At that point we would 
have to examine the base expression to see if it refers to a union member, 
which is not different from the approach in this review.  The LValue 
construction is done in a piecewise manner where some elements of the 
previously (recursively) created LValues may or may not be preserved.  This 
makes me concerned that any more detailed attempt at fixing this may 
accidentally omit some case.
The patch in this review is not intended as a permanent solution, only 
something that is easily revertible and will fix the problem until a better 
solution is developed (which is already worked on).


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaDecl.cpp:7210
+  return;
+}
   }

err_opencl_function_variable seems like a better diagnostic, at least for 
opencl_global.  You can fall back on this more general diagnostic for other 
address spaces.

I think you can just assert here that T.getAddressSpace() != 
LangAS::opencl_constant instead of checking it.

Thinking about it, it feels like opencl_local should be handled the same way: 
they shouldn't get here because they don't really have automatic storage 
duration.  They're much more like a thread-local than an actual local.  
However, we can tackle that some other time.


https://reviews.llvm.org/D32248



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


[PATCH] D31839: make -Winteger-overflow find overflows in function arguments

2017-05-15 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky added a comment.

Ping!


https://reviews.llvm.org/D31839



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


r303114 - [asan] One more test for -fsanitize-address-globals-dead-stripping.

2017-05-15 Thread Evgeniy Stepanov via cfe-commits
Author: eugenis
Date: Mon May 15 15:43:48 2017
New Revision: 303114

URL: http://llvm.org/viewvc/llvm-project?rev=303114&view=rev
Log:
[asan] One more test for -fsanitize-address-globals-dead-stripping.

Added:
cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp

Added: cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp?rev=303114&view=auto
==
--- cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp (added)
+++ cfe/trunk/test/CodeGen/asan-no-globals-no-comdat.cpp Mon May 15 15:43:48 
2017
@@ -0,0 +1,11 @@
+// Test that on Linux asan constructor is placed in a comdat iff globals-gc is 
on.
+// Even if there are no globals in the module.
+
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -emit-llvm -o - -triple x86_64-linux 
%s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fdata-sections -emit-llvm -o - 
-triple x86_64-linux %s | FileCheck %s --check-prefix=WITH-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fno-integrated-as -fdata-sections 
-emit-llvm -o - -triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address 
-fsanitize-address-globals-dead-stripping -fno-integrated-as -emit-llvm -o - 
-triple x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang_cc1 -fsanitize=address -fdata-sections -emit-llvm -o - -triple 
x86_64-linux %s | FileCheck %s --check-prefix=WITHOUT-GC
+
+// WITH-GC: define internal void @asan.module_ctor() comdat {
+// WITHOUT-GC: define internal void @asan.module_ctor() {


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


[PATCH] D31885: Remove TBAA information from LValues representing union members

2017-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D31885#755456, @kparzysz wrote:

> In https://reviews.llvm.org/D31885#751164, @rjmccall wrote:
>
> > The right fix is probably just to make sure that EmitLValueForField doesn't 
> > add TBAA information when the base LValue doesn't have it.  That will also 
> > fix problems with recursive member access where the base is may_alias.
>
>
> That won't work for arrays that are member of unions.  We'd need to change 
> EmitArraySubscriptExpr, which at some point calls MakeAddrLValue for the type 
> being loaded/stored. MakeAddrLValue adds TBAAInfo for that type (unsigned 
> short in case of the C testcase) and it does so regardless of any struct 
> paths. This TBAA info must be removed for the testcase to be fixed.  At that 
> point we would have to examine the base expression to see if it refers to a 
> union member, which is not different from the approach in this review.  The 
> LValue construction is done in a piecewise manner where some elements of the 
> previously (recursively) created LValues may or may not be preserved.  This 
> makes me concerned that any more detailed attempt at fixing this may 
> accidentally omit some case.


That is a reasonable concern.

Hmm.  It seems to me that we do already propagate an important semantic 
property from the base l-value in every important case: the alignment source.  
That audit has already been done, and all you really need to do do is 
generalize it: look at all the places that generically propagate an 
AlignmentSource, e.g. EmitPointerWithAlignment and almost everywhere that calls 
LValue::getAlignmentSource(), and make them propagate an LValueBaseInfo (or 
whatever) instead.  You can then make sure that may_alias-ness is stored in an 
LValueBaseInfo along with the alignment source, and then suppress TBAA when a 
base info is known to be may_alias, and then your temporary fix is just to make 
all union accesses unconditionally set may_alias to true.


Repository:
  rL LLVM

https://reviews.llvm.org/D31885



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99061.
yaxunl added a comment.

Fix diagnostic for global addr


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = &G4;
-  private int *constant L7 = &x; // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = &L1;
-  local int *constant L9 = &L2; // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = &G4;
+  private int *constant L8 = &x;  // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = &L1;
+  local int *constant L10 = &L2;  // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function scope cannot be declared static}}
+
+
+  extern constant float L5;
+  extern local float L6; // expected-error{{extern variable must reside in constant address space}}
+
+  static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
+  static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
Index: test/SemaOpenCL/storageclass-cl20.cl
===
--- test/SemaOpenCL/storageclass-cl20.cl
+++ test/SemaOpenCL/storageclass-cl20.cl
@@ -12,7 +12,8 @@
 
   constant int L1 = 0;
   local int L2;
-  global 

[PATCH] D33214: [libcxx] [test] Workaround C1XX bug in uses_allocator_types.hpp

2017-05-15 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

Needed by IIRC 
allocator.adaptor\allocator.adaptor.members\construct_pair.pass.cpp.


https://reviews.llvm.org/D33214

Files:
  test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
  test/support/test_workarounds.h
  test/support/uses_alloc_types.hpp


Index: test/support/uses_alloc_types.hpp
===
--- test/support/uses_alloc_types.hpp
+++ test/support/uses_alloc_types.hpp
@@ -15,6 +15,7 @@
 #include 
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 #include "type_id.h"
 
 // There are two forms of uses-allocator construction:
@@ -256,6 +257,13 @@
 return alloc;
 }
 
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+template 
+static CtorAlloc getAllocatorFromPackImp(CtorAlloc const& alloc) {
+return alloc;
+}
+#endif
+
 bool has_alloc() const { return alloc_store.get_allocator() != nullptr; }
 const CtorAlloc *get_alloc() const { return alloc_store.get_allocator(); }
 public:
Index: test/support/test_workarounds.h
===
--- test/support/test_workarounds.h
+++ test/support/test_workarounds.h
@@ -20,6 +20,7 @@
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
 # define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+# define TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
 # ifndef _MSC_EXTENSIONS
 #  define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
 # endif
Index: 
test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
===
--- /dev/null
+++ test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
@@ -0,0 +1,49 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION.
+
+#include 
+
+#include "test_workarounds.h"
+
+template
+struct identity {
+using type = T;
+};
+
+template struct list {};
+
+// C1XX believes this function template is not viable when LArgs is an empty
+// parameter pack.
+template 
+int f2(typename identity::type..., int i) {
+return i;
+}
+
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+// C1XX believes this function template *is* viable when LArgs is an empty
+// parameter pack. Conforming compilers believe the two overloads are
+// ambiguous when LArgs is an empty pack.
+template 
+int f2(int i) {
+return i;
+}
+#endif
+
+template 
+int f1(list, Args&&... args) {
+return f2(args...);
+}
+
+int main() {
+f1(list<>{}, 42);
+}


Index: test/support/uses_alloc_types.hpp
===
--- test/support/uses_alloc_types.hpp
+++ test/support/uses_alloc_types.hpp
@@ -15,6 +15,7 @@
 #include 
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 #include "type_id.h"
 
 // There are two forms of uses-allocator construction:
@@ -256,6 +257,13 @@
 return alloc;
 }
 
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+template 
+static CtorAlloc getAllocatorFromPackImp(CtorAlloc const& alloc) {
+return alloc;
+}
+#endif
+
 bool has_alloc() const { return alloc_store.get_allocator() != nullptr; }
 const CtorAlloc *get_alloc() const { return alloc_store.get_allocator(); }
 public:
Index: test/support/test_workarounds.h
===
--- test/support/test_workarounds.h
+++ test/support/test_workarounds.h
@@ -20,6 +20,7 @@
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
 # define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+# define TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
 # ifndef _MSC_EXTENSIONS
 #  define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
 # endif
Index: test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
===
--- /dev/null
+++ test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
@@ -0,0 +1,49 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_EMPTY_PARAMET

[PATCH] D33209: [clang-tidy] Add "emplace_back" detection in inefficient-vector-operation.

2017-05-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a subscriber: cfe-commits.
malcolm.parsons added inline comments.



Comment at: clang-tidy/performance/InefficientVectorOperationCheck.cpp:92
+  const auto VectorAppendCall = expr(
+  anyOf(VectorAppendCallExpr, 
exprWithCleanups(has(VectorAppendCallExpr;
   const auto VectorVarDefStmt =

I'd use ignoringImplicit(VectorAppendCallExpr) to ignore ExprWithCleanups.


Repository:
  rL LLVM

https://reviews.llvm.org/D33209



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


[PATCH] D33170: [X86] Adding avx512_vpopcntdq feature set and its intrinsics

2017-05-15 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added inline comments.



Comment at: lib/CodeGen/CGBuiltin.cpp:7526
+llvm::Type *ResultType = ConvertType(E->getType());
+Value *X = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType);

I'm not sure what EmitScalarExpr does, but I got think its not right for a 
vector argument.



Comment at: lib/CodeGen/CGBuiltin.cpp:7527
+Value *X = EmitScalarExpr(E->getArg(0));
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::ctpop, ResultType);
+return Builder.CreateCall(F, X);

I think you can use Ops[0]->getType() and avoid the call to ConvertType. See 
the code for BI__builtin_ia32_vplzcntq_512_mask.


Repository:
  rL LLVM

https://reviews.llvm.org/D33170



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Looking good.  We had some overlapping patches and comments there, so I want to 
make sure you didn't miss my comment on EmitAutoVarAlloca.




Comment at: lib/Sema/SemaDecl.cpp:7205
+}
+assert (T.getAddressSpace() != LangAS::opencl_constant);
+if (T.getAddressSpace() == LangAS::opencl_global) {

LLVM code style doesn't put a space after assert.


https://reviews.llvm.org/D32248



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


[PATCH] D32520: Support __fp16 vectors

2017-05-15 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

ping


https://reviews.llvm.org/D32520



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


Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Steven Wu via cfe-commits
The other option is to make this behavior configurable so that clang on UNIX 
behaves differently than clang-cl or CUDA. I am not sure what problem CUDA is 
hitting. Is there a test case for that?

Steven

> On May 15, 2017, at 12:42 PM, Nico Weber  wrote:
> 
> r262420 landed in a way adapted to Justin's change. An earlier version of 
> https://reviews.llvm.org/D17695  had a 
> different approach. I don't know if that approach could be used for CUDA. 
> Justin should reply here.
> 
> On Mon, May 15, 2017 at 1:32 PM, Steven Wu  > wrote:
> Hi Nico
> 
> Now that r262420 is landed. Is there any plan to move CUDA to the new 
> approach so we can fix the UNIX conformance test?
> 
> Thanks
> 
> Steven
> 
>> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> 
>> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> [Some necromancy here...]
>> 
>> This commit effectively reverted r173361 and r173825, breaking UNIX 
>> conformance for our c99 wrapper.
>> 
>> See:
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html 
>> 
>>> When c99 encounters a compilation error that causes an object file not to 
>>> be created, it shall write a diagnostic to standard error and continue to 
>>> compile other source code operands, but it shall not perform the link phase 
>>> and it shall return a non-zero exit status.
>> 
>> 
>> We had a test, but this commit changed that as well (I suppose it could have 
>> been better documented).
>> 
>> How easily could this be restricted to only affect CUDA jobs?
>> 
>> If this gets reverted, the clang-cl PCH code needs to use the approach in 
>> https://reviews.llvm.org/D17695  before I 
>> rebased that patch over this revision here, so that a PCH compilation 
>> failure stops the compilation of the main TU.
>>  
>> 
>>> On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> 
>>> Author: jlebar
>>> Date: Wed Feb 24 15:49:28 2016
>>> New Revision: 261774
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev 
>>> 
>>> Log:
>>> Bail on compilation as soon as a job fails.
>>> 
>>> Summary:
>>> (Re-land of r260448, which was reverted in r260522 due to a test failure
>>> in Driver/output-file-cleanup.c that only showed up in fresh builds.)
>>> 
>>> Previously we attempted to be smart; if one job failed, we'd run all
>>> jobs that didn't depend on the failing job.
>>> 
>>> Problem is, this doesn't work well for e.g. CUDA compilation without
>>> -save-temps.  In this case, the device-side and host-side Assemble
>>> actions (which actually are responsible for preprocess, compile,
>>> backend, and assemble, since we're not saving temps) are necessarily
>>> distinct.  So our clever heuristic doesn't help us, and we repeat every
>>> error message once for host and once for each device arch.
>>> 
>>> The main effect of this change, other than fixing CUDA, is that if you
>>> pass multiple cc files to one instance of clang and you get a compile
>>> error, we'll stop when the first cc1 job fails.
>>> 
>>> Reviewers: echristo
>>> 
>>> Subscribers: cfe-commits, jhen, echristo, tra, rafael
>>> 
>>> Differential Revision: http://reviews.llvm.org/D17217 
>>> 
>>> 
>>> Modified:
>>>cfe/trunk/lib/Driver/Compilation.cpp
>>>cfe/trunk/test/Driver/output-file-cleanup.c
>>> 
>>> Modified: cfe/trunk/lib/Driver/Compilation.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
>>>  
>>> 
>>> ==
>>> --- cfe/trunk/lib/Driver/Compilation.cpp (original)
>>> +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
>>> @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
>>>   return ExecutionFailed ? 1 : Res;
>>> }
>>> 
>>> -typedef SmallVectorImpl< std::pair > 
>>> FailingCommandList;
>>> -
>>> -static bool ActionFailed(const Action *A,
>>> - const FailingCommandList &FailingCommands) {
>>> -
>>> -  if (FailingCommands.empty())
>>> -return false;
>>> -
>>> -  for (FailingCommandList::const_iterator CI = FailingCommands.begin(),
>>> - CE = FailingCommands.end(); CI != CE; ++CI)
>>> -if (A == &(CI->second->getSource()))
>>> -  return true;
>>> -
>>> -  for (const Action *AI : A->inputs())
>>> -if (ActionFailed(AI, FailingCommands))
>>> -  return true;
>>> -
>>> -  return false;
>>> -}
>>> -
>>> -static bool InputsOk(const Command &C,
>>>

Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Justin Lebar via cfe-commits
> I don't know if that approach could be used for CUDA. Justin should reply 
> here.

Sorry, I am not sure what the question is.

Compiling a single CUDA file invokes clang -cc1 multiple times: Once
for the host (i.e. CPU), and once for every GPU architecture we're
targeting.  We then take the output of all of these invocations of
clang -cc1 and glom them together into a single object file.

I think the correct thing to do is to treat CUDA compilation of a
single file as a unit and stop compiling *for that file* as soon as
one of the constituent compilations fails.  But we can continue
compiling any other files that were listed on the same command line.

On Mon, May 15, 2017 at 2:42 PM, Steven Wu  wrote:
> The other option is to make this behavior configurable so that clang on UNIX
> behaves differently than clang-cl or CUDA. I am not sure what problem CUDA
> is hitting. Is there a test case for that?
>
> Steven
>
> On May 15, 2017, at 12:42 PM, Nico Weber  wrote:
>
> r262420 landed in a way adapted to Justin's change. An earlier version of
> https://reviews.llvm.org/D17695 had a different approach. I don't know if
> that approach could be used for CUDA. Justin should reply here.
>
> On Mon, May 15, 2017 at 1:32 PM, Steven Wu  wrote:
>>
>> Hi Nico
>>
>> Now that r262420 is landed. Is there any plan to move CUDA to the new
>> approach so we can fix the UNIX conformance test?
>>
>> Thanks
>>
>> Steven
>>
>> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits
>>  wrote:
>>
>> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits
>>  wrote:
>>>
>>> [Some necromancy here...]
>>>
>>> This commit effectively reverted r173361 and r173825, breaking UNIX
>>> conformance for our c99 wrapper.
>>>
>>> See:
>>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html
>>>
>>> When c99 encounters a compilation error that causes an object file not to
>>> be created, it shall write a diagnostic to standard error and continue to
>>> compile other source code operands, but it shall not perform the link phase
>>> and it shall return a non-zero exit status.
>>>
>>>
>>> We had a test, but this commit changed that as well (I suppose it could
>>> have been better documented).
>>>
>>> How easily could this be restricted to only affect CUDA jobs?
>>
>>
>> If this gets reverted, the clang-cl PCH code needs to use the approach in
>> https://reviews.llvm.org/D17695 before I rebased that patch over this
>> revision here, so that a PCH compilation failure stops the compilation of
>> the main TU.
>>
>>>
>>>
>>> On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits
>>>  wrote:
>>>
>>> Author: jlebar
>>> Date: Wed Feb 24 15:49:28 2016
>>> New Revision: 261774
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev
>>> Log:
>>> Bail on compilation as soon as a job fails.
>>>
>>> Summary:
>>> (Re-land of r260448, which was reverted in r260522 due to a test failure
>>> in Driver/output-file-cleanup.c that only showed up in fresh builds.)
>>>
>>> Previously we attempted to be smart; if one job failed, we'd run all
>>> jobs that didn't depend on the failing job.
>>>
>>> Problem is, this doesn't work well for e.g. CUDA compilation without
>>> -save-temps.  In this case, the device-side and host-side Assemble
>>> actions (which actually are responsible for preprocess, compile,
>>> backend, and assemble, since we're not saving temps) are necessarily
>>> distinct.  So our clever heuristic doesn't help us, and we repeat every
>>> error message once for host and once for each device arch.
>>>
>>> The main effect of this change, other than fixing CUDA, is that if you
>>> pass multiple cc files to one instance of clang and you get a compile
>>> error, we'll stop when the first cc1 job fails.
>>>
>>> Reviewers: echristo
>>>
>>> Subscribers: cfe-commits, jhen, echristo, tra, rafael
>>>
>>> Differential Revision: http://reviews.llvm.org/D17217
>>>
>>> Modified:
>>>cfe/trunk/lib/Driver/Compilation.cpp
>>>cfe/trunk/test/Driver/output-file-cleanup.c
>>>
>>> Modified: cfe/trunk/lib/Driver/Compilation.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
>>>
>>> ==
>>> --- cfe/trunk/lib/Driver/Compilation.cpp (original)
>>> +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
>>> @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
>>>   return ExecutionFailed ? 1 : Res;
>>> }
>>>
>>> -typedef SmallVectorImpl< std::pair >
>>> FailingCommandList;
>>> -
>>> -static bool ActionFailed(const Action *A,
>>> - const FailingCommandList &FailingCommands) {
>>> -
>>> -  if (FailingCommands.empty())
>>> -return false;
>>> -
>>> -  for (FailingCommandList::const_iterator CI = FailingCommands.begin(),
>>> - CE = FailingCommands.end(); CI != CE; ++CI)
>>> -if (A == &(CI->second->getSource()))
>>> -  retu

Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Nico Weber via cfe-commits
test/Driver/cl-pch-errorhandling.cpp tests the clang-cl pch bits.

On Mon, May 15, 2017 at 5:42 PM, Steven Wu  wrote:

> The other option is to make this behavior configurable so that clang on
> UNIX behaves differently than clang-cl or CUDA. I am not sure what problem
> CUDA is hitting. Is there a test case for that?
>
> Steven
>
> On May 15, 2017, at 12:42 PM, Nico Weber  wrote:
>
> r262420 landed in a way adapted to Justin's change. An earlier version of
> https://reviews.llvm.org/D17695 had a different approach. I don't know if
> that approach could be used for CUDA. Justin should reply here.
>
> On Mon, May 15, 2017 at 1:32 PM, Steven Wu  wrote:
>
>> Hi Nico
>>
>> Now that r262420 is landed. Is there any plan to move CUDA to the new
>> approach so we can fix the UNIX conformance test?
>>
>> Thanks
>>
>> Steven
>>
>> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits
>>  wrote:
>>
>>> [Some necromancy here...]
>>>
>>> This commit effectively reverted r173361 and r173825, breaking UNIX
>>> conformance for our c99 wrapper.
>>>
>>> See:
>>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html
>>>
>>> When c99 encounters a compilation error that causes an object file not
>>> to be created, it shall write a diagnostic to standard error and continue
>>> to compile other source code operands, but it shall not perform the link
>>> phase and it shall return a non-zero exit status.
>>>
>>>
>>> We had a test, but this commit changed that as well (I suppose it could
>>> have been better documented).
>>>
>>> How easily could this be restricted to only affect CUDA jobs?
>>>
>>
>> If this gets reverted, the clang-cl PCH code needs to use the approach in
>> https://reviews.llvm.org/D17695 before I rebased that patch over this
>> revision here, so that a PCH compilation failure stops the compilation of
>> the main TU.
>>
>>
>>>
>>> On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>> Author: jlebar
>>> Date: Wed Feb 24 15:49:28 2016
>>> New Revision: 261774
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev
>>> Log:
>>> Bail on compilation as soon as a job fails.
>>>
>>> Summary:
>>> (Re-land of r260448, which was reverted in r260522 due to a test failure
>>> in Driver/output-file-cleanup.c that only showed up in fresh builds.)
>>>
>>> Previously we attempted to be smart; if one job failed, we'd run all
>>> jobs that didn't depend on the failing job.
>>>
>>> Problem is, this doesn't work well for e.g. CUDA compilation without
>>> -save-temps.  In this case, the device-side and host-side Assemble
>>> actions (which actually are responsible for preprocess, compile,
>>> backend, and assemble, since we're not saving temps) are necessarily
>>> distinct.  So our clever heuristic doesn't help us, and we repeat every
>>> error message once for host and once for each device arch.
>>>
>>> The main effect of this change, other than fixing CUDA, is that if you
>>> pass multiple cc files to one instance of clang and you get a compile
>>> error, we'll stop when the first cc1 job fails.
>>>
>>> Reviewers: echristo
>>>
>>> Subscribers: cfe-commits, jhen, echristo, tra, rafael
>>>
>>> Differential Revision: http://reviews.llvm.org/D17217
>>>
>>> Modified:
>>>cfe/trunk/lib/Driver/Compilation.cpp
>>>cfe/trunk/test/Driver/output-file-cleanup.c
>>>
>>> Modified: cfe/trunk/lib/Driver/Compilation.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Com
>>> pilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
>>> 
>>> ==
>>> --- cfe/trunk/lib/Driver/Compilation.cpp (original)
>>> +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
>>> @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
>>>   return ExecutionFailed ? 1 : Res;
>>> }
>>>
>>> -typedef SmallVectorImpl< std::pair >
>>> FailingCommandList;
>>> -
>>> -static bool ActionFailed(const Action *A,
>>> - const FailingCommandList &FailingCommands) {
>>> -
>>> -  if (FailingCommands.empty())
>>> -return false;
>>> -
>>> -  for (FailingCommandList::const_iterator CI = FailingCommands.begin(),
>>> - CE = FailingCommands.end(); CI != CE; ++CI)
>>> -if (A == &(CI->second->getSource()))
>>> -  return true;
>>> -
>>> -  for (const Action *AI : A->inputs())
>>> -if (ActionFailed(AI, FailingCommands))
>>> -  return true;
>>> -
>>> -  return false;
>>> -}
>>> -
>>> -static bool InputsOk(const Command &C,
>>> - const FailingCommandList &FailingCommands) {
>>> -  return !ActionFailed(&C.getSource(), FailingCommands);
>>> -}
>>> -
>>> -void Compilation::ExecuteJobs(const JobList &Jobs,
>>> -  FailingCommandList &FailingCommands)
>>> const {
>>> +void Compilation::ExecuteJobs(

[PATCH] D32146: PR32476: __nop_locale_mgmt.h not needed with newlib 2.5+

2017-05-15 Thread Orivej Desh via Phabricator via cfe-commits
orivej added inline comments.



Comment at: include/support/newlib/xlocale.h:20
+#if defined(__NEWLIB__) && (__NEWLIB__ == 2) \
+&& defined(__NEWLIB_MINOR__) && (__NEWLIB_MINOR__ >= 5) \
+&& (!defined(__POSIX_VISIBLE) || (__POSIX_VISIBLE < 200809))

You meant `__NEWLIB_MINOR__ < 5`.
Could not this be just the following?
```
#if __NEWLIB__ < 2 || __NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5
#include 
#endif
```


https://reviews.llvm.org/D32146



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


r303121 - [Sema] Use CK_NoOp instead CK_Invalid in tryGCCVectorConvertAndSplat

2017-05-15 Thread Vitaly Buka via cfe-commits
Author: vitalybuka
Date: Mon May 15 17:04:03 2017
New Revision: 303121

URL: http://llvm.org/viewvc/llvm-project?rev=303121&view=rev
Log:
[Sema] Use CK_NoOp instead CK_Invalid in tryGCCVectorConvertAndSplat

This fix UBSAN bots after r302935. Storing non-defined values in enum is
undefined behavior.

Other places, where "if (ScalarCast != CK_Invalid)" is used, never get to the
"if" with CK_Invalid. tryGCCVectorConvertAndSplat can get to the "if" with
CK_Invalid and it looks like expected case. So we have to use something other
than CK_Invalid, e.g. CK_NoOp.

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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=303121&r1=303120&r2=303121&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon May 15 17:04:03 2017
@@ -8204,7 +8204,7 @@ static bool tryGCCVectorConvertAndSplat(
 
   // The conversion to apply to the scalar before splatting it,
   // if necessary.
-  CastKind ScalarCast = CK_Invalid;
+  CastKind ScalarCast = CK_NoOp;
 
   // Accept cases where the vector elements are integers and the scalar is
   // an integer.
@@ -8254,7 +8254,7 @@ static bool tryGCCVectorConvertAndSplat(
 
   // Adjust scalar if desired.
   if (Scalar) {
-if (ScalarCast != CK_Invalid)
+if (ScalarCast != CK_NoOp)
   *Scalar = S.ImpCastExprToType(Scalar->get(), VectorEltTy, ScalarCast);
 *Scalar = S.ImpCastExprToType(Scalar->get(), VectorTy, CK_VectorSplat);
   }


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


Re: r261774 - Bail on compilation as soon as a job fails.

2017-05-15 Thread Steven Wu via cfe-commits
> On May 15, 2017, at 3:03 PM, Nico Weber  wrote:
> 
> test/Driver/cl-pch-errorhandling.cpp tests the clang-cl pch bits.

I don't think reverting r261774 will break any cl-pch tests (didn't try 
windows). That is why I wondering if there is any test case for CUDA so I don't 
break them when fixing UNIX conformance.

Steven

> 
> On Mon, May 15, 2017 at 5:42 PM, Steven Wu  > wrote:
> The other option is to make this behavior configurable so that clang on UNIX 
> behaves differently than clang-cl or CUDA. I am not sure what problem CUDA is 
> hitting. Is there a test case for that?
> 
> Steven
> 
>> On May 15, 2017, at 12:42 PM, Nico Weber > > wrote:
>> 
>> r262420 landed in a way adapted to Justin's change. An earlier version of 
>> https://reviews.llvm.org/D17695  had a 
>> different approach. I don't know if that approach could be used for CUDA. 
>> Justin should reply here.
>> 
>> On Mon, May 15, 2017 at 1:32 PM, Steven Wu > > wrote:
>> Hi Nico
>> 
>> Now that r262420 is landed. Is there any plan to move CUDA to the new 
>> approach so we can fix the UNIX conformance test?
>> 
>> Thanks
>> 
>> Steven
>> 
>>> On Apr 22, 2017, at 8:08 PM, Nico Weber via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> 
>>> On Sat, Apr 22, 2017 at 8:40 PM, Duncan P. N. Exon Smith via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> [Some necromancy here...]
>>> 
>>> This commit effectively reverted r173361 and r173825, breaking UNIX 
>>> conformance for our c99 wrapper.
>>> 
>>> See:
>>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html 
>>> 
 When c99 encounters a compilation error that causes an object file not to 
 be created, it shall write a diagnostic to standard error and continue to 
 compile other source code operands, but it shall not perform the link 
 phase and it shall return a non-zero exit status.
>>> 
>>> 
>>> We had a test, but this commit changed that as well (I suppose it could 
>>> have been better documented).
>>> 
>>> How easily could this be restricted to only affect CUDA jobs?
>>> 
>>> If this gets reverted, the clang-cl PCH code needs to use the approach in 
>>> https://reviews.llvm.org/D17695  before I 
>>> rebased that patch over this revision here, so that a PCH compilation 
>>> failure stops the compilation of the main TU.
>>>  
>>> 
 On Feb 24, 2016, at 13:49, Justin Lebar via cfe-commits 
 mailto:cfe-commits@lists.llvm.org>> wrote:
 
 Author: jlebar
 Date: Wed Feb 24 15:49:28 2016
 New Revision: 261774
 
 URL: http://llvm.org/viewvc/llvm-project?rev=261774&view=rev 
 
 Log:
 Bail on compilation as soon as a job fails.
 
 Summary:
 (Re-land of r260448, which was reverted in r260522 due to a test failure
 in Driver/output-file-cleanup.c that only showed up in fresh builds.)
 
 Previously we attempted to be smart; if one job failed, we'd run all
 jobs that didn't depend on the failing job.
 
 Problem is, this doesn't work well for e.g. CUDA compilation without
 -save-temps.  In this case, the device-side and host-side Assemble
 actions (which actually are responsible for preprocess, compile,
 backend, and assemble, since we're not saving temps) are necessarily
 distinct.  So our clever heuristic doesn't help us, and we repeat every
 error message once for host and once for each device arch.
 
 The main effect of this change, other than fixing CUDA, is that if you
 pass multiple cc files to one instance of clang and you get a compile
 error, we'll stop when the first cc1 job fails.
 
 Reviewers: echristo
 
 Subscribers: cfe-commits, jhen, echristo, tra, rafael
 
 Differential Revision: http://reviews.llvm.org/D17217 
 
 
 Modified:
cfe/trunk/lib/Driver/Compilation.cpp
cfe/trunk/test/Driver/output-file-cleanup.c
 
 Modified: cfe/trunk/lib/Driver/Compilation.cpp
 URL: 
 http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=261774&r1=261773&r2=261774&view=diff
  
 
 ==
 --- cfe/trunk/lib/Driver/Compilation.cpp (original)
 +++ cfe/trunk/lib/Driver/Compilation.cpp Wed Feb 24 15:49:28 2016
 @@ -163,39 +163,17 @@ int Compilation::ExecuteCommand(const Co
   return ExecutionFailed ? 1 : Res;
 }
 
 -typedef SmallVectorImpl< std::pair > 
 FailingCommandList;
 -
 -static bool ActionFailed(const Action *A,
>

[PATCH] D33214: [libcxx] [test] Workaround C1XX bug in uses_allocator_types.hpp

2017-05-15 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter updated this revision to Diff 99086.
CaseyCarter edited the summary of this revision.
CaseyCarter added a comment.

Silence warnings.


https://reviews.llvm.org/D33214

Files:
  
test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
  test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
  test/support/test_workarounds.h
  test/support/uses_alloc_types.hpp

Index: test/support/uses_alloc_types.hpp
===
--- test/support/uses_alloc_types.hpp
+++ test/support/uses_alloc_types.hpp
@@ -15,6 +15,7 @@
 #include 
 
 #include "test_macros.h"
+#include "test_workarounds.h"
 #include "type_id.h"
 
 // There are two forms of uses-allocator construction:
@@ -256,6 +257,13 @@
 return alloc;
 }
 
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+template 
+static CtorAlloc getAllocatorFromPackImp(CtorAlloc const& alloc) {
+return alloc;
+}
+#endif
+
 bool has_alloc() const { return alloc_store.get_allocator() != nullptr; }
 const CtorAlloc *get_alloc() const { return alloc_store.get_allocator(); }
 public:
Index: test/support/test_workarounds.h
===
--- test/support/test_workarounds.h
+++ test/support/test_workarounds.h
@@ -20,6 +20,7 @@
 #if defined(TEST_COMPILER_C1XX)
 # define TEST_WORKAROUND_C1XX_BROKEN_NULLPTR_CONVERSION_OPERATOR
 # define TEST_WORKAROUND_C1XX_BROKEN_IS_TRIVIALLY_COPYABLE
+# define TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
 # ifndef _MSC_EXTENSIONS
 #  define TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK
 # endif
Index: test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
===
--- /dev/null
+++ test/support/test.workarounds/c1xx_empty_parameter_pack_expansion.pass.cpp
@@ -0,0 +1,49 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+// Verify TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION.
+
+#include 
+
+#include "test_workarounds.h"
+
+template
+struct identity {
+using type = T;
+};
+
+template struct list {};
+
+// C1XX believes this function template is not viable when LArgs is an empty
+// parameter pack.
+template 
+int f2(typename identity::type..., int i) {
+return i;
+}
+
+#ifdef TEST_WORKAROUND_C1XX_EMPTY_PARAMETER_PACK_EXPANSION
+// C1XX believes this function template *is* viable when LArgs is an empty
+// parameter pack. Conforming compilers believe the two overloads are
+// ambiguous when LArgs is an empty pack.
+template 
+int f2(int i) {
+return i;
+}
+#endif
+
+template 
+int f1(list, Args&&... args) {
+return f2(args...);
+}
+
+int main() {
+f1(list<>{}, 42);
+}
Index: test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
===
--- test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
+++ test/std/utilities/allocator.adaptor/allocator.adaptor.members/construct_pair.pass.cpp
@@ -39,6 +39,7 @@
 using SA = std::scoped_allocator_adaptor;
 static_assert(std::uses_allocator >::value, "");
 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+assert(ptr);
 Alloc CA(P);
 SA A(CA);
 A.construct(ptr);
@@ -61,6 +62,7 @@
 using SA = std::scoped_allocator_adaptor;
 static_assert(std::uses_allocator >::value, "");
 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+assert(ptr);
 Alloc CA(P);
 SA A(CA);
 A.construct(ptr);
@@ -77,7 +79,6 @@
 
 void test_with_inner_alloc()
 {
-using VoidAlloc1 = CountingAllocator;
 using VoidAlloc2 = CountingAllocator;
 
 AllocController POuter;
@@ -93,6 +94,7 @@
 static_assert(!std::uses_allocator::value, "");
 static_assert(std::uses_allocator::value, "");
 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+assert(ptr);
 Outer O(POuter);
 Inner I(PInner);
 SA A(O, I);
@@ -119,6 +121,7 @@
 static_assert(!std::uses_allocator::value, "");
 static_assert(std::uses_allocator::value, "");
 Pair * ptr = (Pair*)std::malloc(sizeof(Pair));
+assert(ptr);
 Outer O(POuter);
 Inner I(PInner);
 SA A(O, I);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31646: [coroutines] Build GRO declaration and return GRO statement

2017-05-15 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

Half-monthly ping


https://reviews.llvm.org/D31646



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


[PATCH] D31608: [coroutines] Add emission of initial and final suspends

2017-05-15 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov added a comment.

soft ping


https://reviews.llvm.org/D31608



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99094.
yaxunl added a comment.

Fix format.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = &G4;
-  private int *constant L7 = &x; // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = &L1;
-  local int *constant L9 = &L2; // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = &G4;
+  private int *constant L8 = &x;  // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = &L1;
+  local int *constant L10 = &L2;  // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function scope cannot be declared static}}
+
+
+  extern constant float L5;
+  extern local float L6; // expected-error{{extern variable must reside in constant address space}}
+
+  static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
+  static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
Index: test/SemaOpenCL/storageclass-cl20.cl
===
--- test/SemaOpenCL/storageclass-cl20.cl
+++ test/SemaOpenCL/storageclass-cl20.cl
@@ -12,7 +12,8 @@
 
   constant int L1 = 0;
   local int L2;
-  global int L3; // expected

[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1119
+  T.getAddressSpace(), address.getPointer()->getType()->
+  getPointerElementType()->getPointerTo(getContext().getTargetAddressSpace(
+  T.getAddressSpace())), true);

rjmccall wrote:
> Hmm.  I would prefer if we could avoid doing this in the fast path.  
> Suggestion:
> 
>   - Please add a variable (ASTAllocaAddressSpace) to CodeGenTypeCache that 
> stores the AST address space of the stack.  You can add a function to 
> CodeGenTargetInfo to initialize this; in most targets, it will just return 0, 
> but your target can make it ~0U or something, anything works as long as it 
> doesn't incorrectly match an actual target address space.  (But you should 
> really consider adding an actual target-specific address space for the stack! 
>  It'll probably be useful in builtin code or something eventually.)
> 
>   - Please add an assert that T.getAddressSpace() == 0, and then make this 
> call conditional on whether ASTAllocaAddressSpace is non-zero.
> 
> You can just write address.getElementType() instead of 
> address.getPointer()->getType()->getPointerElementType().
> 
> Are you intentionally leaving emission.Addr as the unconverted pointer?  That 
> will probably mess everything else downstream that uses 'emission', and the 
> only reason you're not seeing that is that OpenCL probably doesn't actually 
> have anything downstream that uses 'emission' — destructors or whatever else.
> 
> Please add an inline comment like
>, /*non-null*/ true);
Sorry I missed this comment. I will do the changes.

About emission.Addr, I leave the unconverted pointer intentionally. I need this 
to work for both C++ and OpenCL. I checked the usage of emission.Addr and they 
seem to be only load or store, so I think it is safe to use the unconverted 
pointer. Now you mention destructor. I think I need to change that and I am 
going to add a lit test also.


https://reviews.llvm.org/D32248



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


[PATCH] D32248: CodeGen: Cast alloca to expected address space

2017-05-15 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 99099.
yaxunl added a comment.

Revised by John's comments.


https://reviews.llvm.org/D32248

Files:
  include/clang/AST/Type.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenTypeCache.h
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaDecl.cpp
  test/CodeGen/address-space.c
  test/CodeGenCXX/amdgcn-automatic-variable.cpp
  test/CodeGenOpenCL/amdgcn-automatic-variable.cl
  test/SemaOpenCL/storageclass-cl20.cl
  test/SemaOpenCL/storageclass.cl

Index: test/SemaOpenCL/storageclass.cl
===
--- test/SemaOpenCL/storageclass.cl
+++ test/SemaOpenCL/storageclass.cl
@@ -13,29 +13,37 @@
   constant int L1 = 0;
   local int L2;
 
-  auto int L3 = 7; // expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
-  global int L4;   // expected-error{{function scope variable cannot be declared in global address space}}
-
-  constant int L5 = x; // expected-error {{initializer element is not a compile-time constant}}
-  global int *constant L6 = &G4;
-  private int *constant L7 = &x; // expected-error {{initializer element is not a compile-time constant}}
-  constant int *constant L8 = &L1;
-  local int *constant L9 = &L2; // expected-error {{initializer element is not a compile-time constant}}
+  auto int L3 = 7;// expected-error{{OpenCL version 1.2 does not support the 'auto' storage class specifier}}
+  global int L4;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L5; // expected-error{{automatic variable qualified with an invalid address space}}
+
+  constant int L6 = x;// expected-error {{initializer element is not a compile-time constant}}
+  global int *constant L7 = &G4;
+  private int *constant L8 = &x;  // expected-error {{initializer element is not a compile-time constant}}
+  constant int *constant L9 = &L1;
+  local int *constant L10 = &L2;  // expected-error {{initializer element is not a compile-time constant}}
 }
 
 static void kernel bar() { // expected-error{{kernel functions cannot be declared static}}
 }
 
 void f() {
-  constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-  local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+  constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+  local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+  global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+  __attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
+
   {
-constant int L1 = 0; // expected-error{{non-kernel function variable cannot be declared in constant address space}}
-local int L2;// expected-error{{non-kernel function variable cannot be declared in local address space}}
+constant int L1 = 0;// expected-error{{non-kernel function variable cannot be declared in constant address space}}
+local int L2;   // expected-error{{non-kernel function variable cannot be declared in local address space}}
+global int L3;  // expected-error{{function scope variable cannot be declared in global address space}}
+__attribute__((address_space(100))) int L4; // expected-error{{automatic variable qualified with an invalid address space}}
   }
-  global int L3; // expected-error{{function scope variable cannot be declared in global address space}}
-  extern constant float L4;
-  extern local float L5; // expected-error{{extern variable must reside in constant address space}}
-  static int L6 = 0; // expected-error{{variables in function scope cannot be declared static}}
-  static int L7; // expected-error{{variables in function scope cannot be declared static}}
+
+
+  extern constant float L5;
+  extern local float L6; // expected-error{{extern variable must reside in constant address space}}
+
+  static int L7 = 0; // expected-error{{variables in function scope cannot be declared static}}
+  static int L8; // expected-error{{variables in function scope cannot be declared static}}
 }
Index: test/SemaOpenCL/storageclass-cl20.cl
===
--- test/SemaOpenCL/storageclass-cl20.cl
+++ test/SemaOpenCL/storageclass-cl20.cl
@@ -12,7 

[clang-tools-extra] r303139 - [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-15 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Mon May 15 23:25:42 2017
New Revision: 303139

URL: http://llvm.org/viewvc/llvm-project?rev=303139&view=rev
Log:
[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

Summary:
This patch makes modernize-use-emplace remove unnecessary make_ calls from 
push_back calls and turn them into emplace_back -- the same way make_pair calls 
are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new 
options that control that are `TupleTypes` and `TupleMakeFunctions`. By 
default, the check removes calls to `std::make_pair` and `std::make_tuple`.

Eq.

```
std::vector> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);
```

Reviewers: alexfh, aaron.ballman, Prazek, hokein

Reviewed By: Prazek

Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=303139&r1=303138&r2=303139&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Mon May 15 
23:25:42 2017
@@ -24,6 +24,8 @@ const auto DefaultContainersWithPushBack
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
+const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
 } // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
@@ -31,7 +33,11 @@ UseEmplaceCheck::UseEmplaceCheck(StringR
   ContainersWithPushBack(utils::options::parseStringList(Options.get(
   "ContainersWithPushBack", DefaultContainersWithPushBack))),
   SmartPointers(utils::options::parseStringList(
-  Options.get("SmartPointers", DefaultSmartPointers))) {}
+  Options.get("SmartPointers", DefaultSmartPointers))),
+  TupleTypes(utils::options::parseStringList(
+  Options.get("TupleTypes", DefaultTupleTypes))),
+  TupleMakeFunctions(utils::options::parseStringList(
+  Options.get("TupleMakeFunctions", DefaultTupleMakeFunctions))) {}
 
 void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -87,20 +93,23 @@ void UseEmplaceCheck::registerMatchers(M
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakePair = ignoringImplicit(
-  callExpr(callee(expr(ignoringImplicit(
-  declRefExpr(unless(hasExplicitTemplateArgs()),
-  to(functionDecl(hasName("::std::make_pair"
-  .bind("make_pair"));
+  auto MakeTuple = ignoringImplicit(
+  callExpr(
+  callee(expr(ignoringImplicit(declRefExpr(
+  unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasAnyName(SmallVector(
+  TupleMakeFunctions.begin(), TupleMakeFunctions.end())
+  .bind("make"));
 
-  // make_pair can return type convertible to container's element type.
+  // make_something can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(MakePair)),
-  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+  auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakeTuple)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  SmallVector(TupleTypes.begin(), 
TupleTypes.end(;
 
   auto SoughtParam = materializeTemporaryExpr(
-  anyOf(has(MakePair), has(MakePairCtor),
+  anyOf(has(MakeTuple), has(MakeTupleCtor),
 HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
   Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
@@ -112,8 +121,8 @@ void UseEmplaceCheck::registerMatchers(M
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
-  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
-  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched")

[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-15 Thread Jakub Kuderski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL303139: [clang-tidy] modernize-use-emplace: Remove 
unnecessary make_tuple calls (authored by kuhar).

Changed prior to commit:
  https://reviews.llvm.org/D32690?vs=98073&id=99100#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32690

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -24,14 +24,20 @@
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
+const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
 } // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
   ContainersWithPushBack(utils::options::parseStringList(Options.get(
   "ContainersWithPushBack", DefaultContainersWithPushBack))),
   SmartPointers(utils::options::parseStringList(
-  Options.get("SmartPointers", DefaultSmartPointers))) {}
+  Options.get("SmartPointers", DefaultSmartPointers))),
+  TupleTypes(utils::options::parseStringList(
+  Options.get("TupleTypes", DefaultTupleTypes))),
+  TupleMakeFunctions(utils::options::parseStringList(
+  Options.get("TupleMakeFunctions", DefaultTupleMakeFunctions))) {}
 
 void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -87,20 +93,23 @@
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakePair = ignoringImplicit(
-  callExpr(callee(expr(ignoringImplicit(
-  declRefExpr(unless(hasExplicitTemplateArgs()),
-  to(functionDecl(hasName("::std::make_pair"
-  .bind("make_pair"));
+  auto MakeTuple = ignoringImplicit(
+  callExpr(
+  callee(expr(ignoringImplicit(declRefExpr(
+  unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasAnyName(SmallVector(
+  TupleMakeFunctions.begin(), TupleMakeFunctions.end())
+  .bind("make"));
 
-  // make_pair can return type convertible to container's element type.
+  // make_something can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(MakePair)),
-  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+  auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakeTuple)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  SmallVector(TupleTypes.begin(), TupleTypes.end(;
 
   auto SoughtParam = materializeTemporaryExpr(
-  anyOf(has(MakePair), has(MakePairCtor),
+  anyOf(has(MakeTuple), has(MakeTupleCtor),
 HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
   Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
@@ -112,8 +121,8 @@
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
-  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
-  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched");
+  const auto *MakeCall = Result.Nodes.getNodeAs("make");
+  assert((InnerCtorCall || MakeCall) && "No push_back parameter matched");
 
   const auto FunctionNameSourceRange = CharSourceRange::getCharRange(
   Call->getExprLoc(), Call->getArg(0)->getExprLoc());
@@ -123,20 +132,20 @@
   if (FunctionNameSourceRange.getBegin().isMacroID())
 return;
 
-  const auto *EmplacePrefix = MakePairCall ? "emplace_back" : "emplace_back(";
+  const auto *EmplacePrefix = MakeCall ? "emplace_back" : "emplace_back(";
   Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, EmplacePrefix);
 
   const SourceRange CallParensRange =
-  MakePairCall ? SourceRange(MakePairCall->getCallee()->getLocEnd(),
- MakePairCall->getRParenLoc())
-   : InnerCtorCall->getParenOrBraceRange();
+  MakeCall ? SourceRange(MakeCall->getCallee()->getLocEnd(),
+ MakeCall->getRParenLoc()

[clang-tools-extra] r303140 - Revert "[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls"

2017-05-15 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Tue May 16 00:07:40 2017
New Revision: 303140

URL: http://llvm.org/viewvc/llvm-project?rev=303140&view=rev
Log:
Revert "[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls"

This reverts commit r303139. The commit made docs build emit a warning.

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=303140&r1=303139&r2=303140&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Tue May 16 
00:07:40 2017
@@ -24,8 +24,6 @@ const auto DefaultContainersWithPushBack
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
-const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
-const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
 } // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
@@ -33,11 +31,7 @@ UseEmplaceCheck::UseEmplaceCheck(StringR
   ContainersWithPushBack(utils::options::parseStringList(Options.get(
   "ContainersWithPushBack", DefaultContainersWithPushBack))),
   SmartPointers(utils::options::parseStringList(
-  Options.get("SmartPointers", DefaultSmartPointers))),
-  TupleTypes(utils::options::parseStringList(
-  Options.get("TupleTypes", DefaultTupleTypes))),
-  TupleMakeFunctions(utils::options::parseStringList(
-  Options.get("TupleMakeFunctions", DefaultTupleMakeFunctions))) {}
+  Options.get("SmartPointers", DefaultSmartPointers))) {}
 
 void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -93,23 +87,20 @@ void UseEmplaceCheck::registerMatchers(M
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakeTuple = ignoringImplicit(
-  callExpr(
-  callee(expr(ignoringImplicit(declRefExpr(
-  unless(hasExplicitTemplateArgs()),
-  to(functionDecl(hasAnyName(SmallVector(
-  TupleMakeFunctions.begin(), TupleMakeFunctions.end())
-  .bind("make"));
+  auto MakePair = ignoringImplicit(
+  callExpr(callee(expr(ignoringImplicit(
+  declRefExpr(unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasName("::std::make_pair"
+  .bind("make_pair"));
 
-  // make_something can return type convertible to container's element type.
+  // make_pair can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(MakeTuple)),
-  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
-  SmallVector(TupleTypes.begin(), 
TupleTypes.end(;
+  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakePair)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
 
   auto SoughtParam = materializeTemporaryExpr(
-  anyOf(has(MakeTuple), has(MakeTupleCtor),
+  anyOf(has(MakePair), has(MakePairCtor),
 HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
   Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
@@ -121,8 +112,8 @@ void UseEmplaceCheck::registerMatchers(M
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
-  const auto *MakeCall = Result.Nodes.getNodeAs("make");
-  assert((InnerCtorCall || MakeCall) && "No push_back parameter matched");
+  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
+  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched");
 
   const auto FunctionNameSourceRange = CharSourceRange::getCharRange(
   Call->getExprLoc(), Call->getArg(0)->getExprLoc());
@@ -132,20 +123,20 @@ void UseEmplaceCheck::check(const MatchF
   if (FunctionNameSourceRange.getBegin().isMacroID())
 return;
 
-  const auto *EmplacePrefix = MakeCall ? "emplace_back" : "emplace_back(";
+  const auto *EmplacePrefix = MakePairCall ? "emplace_back" : "emplace_back(";
   Diag << FixItHint::CreateReplacement(FunctionNameSourceRange, EmplacePrefix);
 
   cons

[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-15 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar updated this revision to Diff 99103.
kuhar added a comment.

The patch broke the spinx docs build and I had to revert it in r303140.
I fixed the docs file problems.


Repository:
  rL LLVM

https://reviews.llvm.org/D32690

Files:
  clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tidy/modernize/UseEmplaceCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-emplace.rst
  test/clang-tidy/modernize-use-emplace.cpp

Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -1,7 +1,12 @@
 // RUN: %check_clang_tidy %s modernize-use-emplace %t -- \
 // RUN:   -config="{CheckOptions: \
 // RUN: [{key: modernize-use-emplace.ContainersWithPushBack, \
-// RUN:   value: '::std::vector; ::std::list; ::std::deque; llvm::LikeASmallVector'}]}" -- -std=c++11
+// RUN:   value: '::std::vector; ::std::list; ::std::deque; llvm::LikeASmallVector'}, \
+// RUN:  {key: modernize-use-emplace.TupleTypes, \
+// RUN:   value: '::std::pair; std::tuple; ::test::Single'}, \
+// RUN:  {key: modernize-use-emplace.TupleMakeFunctions, \
+// RUN:   value: '::std::make_pair; ::std::make_tuple; ::test::MakeSingle'}] \
+// RUN: }" -- -std=c++11
 
 namespace std {
 template 
@@ -46,27 +51,54 @@
   ~deque();
 };
 
-template 
-class pair {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+
+template  class pair {
 public:
   pair() = default;
   pair(const pair &) = default;
   pair(pair &&) = default;
 
   pair(const T1 &, const T2 &) {}
   pair(T1 &&, T2 &&) {}
 
-  template 
-  pair(const pair &p){};
-  template 
-  pair(pair &&p){};
+  template  pair(const pair &){};
+  template  pair(pair &&){};
 };
 
 template 
-pair make_pair(T1&&, T2&&) {
+pair::type, typename remove_reference::type>
+make_pair(T1 &&, T2 &&) {
   return {};
 };
 
+template  class tuple {
+public:
+  tuple() = default;
+  tuple(const tuple &) = default;
+  tuple(tuple &&) = default;
+
+  tuple(const Ts &...) {}
+  tuple(Ts &&...) {}
+
+  template  tuple(const tuple &){};
+  template  tuple(tuple &&) {}
+
+  template  tuple(const pair &) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+  template  tuple(pair &&) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+};
+
+template 
+tuple::type...> make_tuple(Ts &&...) {
+  return {};
+}
+
 template 
 class unique_ptr {
 public:
@@ -207,6 +239,30 @@
   // CHECK-FIXES: v2.emplace_back(Something(42, 42), Zoz(Something(21, 37)));
 }
 
+void testTuple() {
+  std::vector> v;
+  v.push_back(std::tuple(false, 'x', 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'x', 1);
+
+  v.push_back(std::tuple{false, 'y', 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'y', 2);
+
+  v.push_back({true, 'z', 3});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(true, 'z', 3);
+
+  std::vector> x;
+  x.push_back(std::make_pair(1, false));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(1, false);
+
+  x.push_back(std::make_pair(2LL, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(2LL, 1);
+}
+
 struct Base {
   Base(int, int *, int = 42);
 };
@@ -328,6 +384,77 @@
   // make_pair cannot be removed here, as Y is not constructible with two ints.
 }
 
+void testMakeTuple() {
+  std::vector> v;
+  v.push_back(std::make_tuple(1, true, 'v'));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(1, true, 'v');
+
+  v.push_back(std::make_tuple(2ULL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(2ULL, 1, 0);
+
+  v.push_back(std::make_tuple(3LL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(std::make_tuple(3LL, 1, 0));
+  // make_tuple is not removed when there are explicit template
+  // arguments provided.
+}
+
+namespace test {
+template  struct Single {
+  Single() = default;
+  Single(const Single &) = default;
+  Single(Single &&) = default;
+
+  Single(const T &) {}
+  Single(T &&) {}
+
+  template  Single(const Single &) {}
+  template  Single(Single &&) {}
+
+  template  Single(const std::tuple &) {}
+  template  Single(std::tuple &&) {}
+};
+
+template 
+Single::type> MakeSingle(T &&) {
+  return {};
+}
+} // namespace test
+
+void testOtherTuples() {
+  std::vector> v;
+  v.push_back(test::Single(1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_b

[clang-tools-extra] r303145 - [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-05-15 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Tue May 16 01:32:38 2017
New Revision: 303145

URL: http://llvm.org/viewvc/llvm-project?rev=303145&view=rev
Log:
[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

Summary:
This patch makes modernize-use-emplace remove unnecessary make_ calls from 
push_back calls and turn them into emplace_back -- the same way make_pair calls 
are handled.
Custom make_ calls can be removed for custom tuple-like types -- two new 
options that control that are `TupleTypes` and `TupleMakeFunctions`. By 
default, the check removes calls to `std::make_pair` and `std::make_tuple`.

Eq.

```
std::vector> v;
v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true);
```

Reviewers: alexfh, aaron.ballman, Prazek, hokein

Reviewed By: Prazek

Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
clang-tools-extra/trunk/test/clang-tidy/modernize-use-emplace.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=303145&r1=303144&r2=303145&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Tue May 16 
01:32:38 2017
@@ -24,6 +24,8 @@ const auto DefaultContainersWithPushBack
 "::std::vector; ::std::list; ::std::deque";
 const auto DefaultSmartPointers =
 "::std::shared_ptr; ::std::unique_ptr; ::std::auto_ptr; ::std::weak_ptr";
+const auto DefaultTupleTypes = "::std::pair; ::std::tuple";
+const auto DefaultTupleMakeFunctions = "::std::make_pair; ::std::make_tuple";
 } // namespace
 
 UseEmplaceCheck::UseEmplaceCheck(StringRef Name, ClangTidyContext *Context)
@@ -31,7 +33,11 @@ UseEmplaceCheck::UseEmplaceCheck(StringR
   ContainersWithPushBack(utils::options::parseStringList(Options.get(
   "ContainersWithPushBack", DefaultContainersWithPushBack))),
   SmartPointers(utils::options::parseStringList(
-  Options.get("SmartPointers", DefaultSmartPointers))) {}
+  Options.get("SmartPointers", DefaultSmartPointers))),
+  TupleTypes(utils::options::parseStringList(
+  Options.get("TupleTypes", DefaultTupleTypes))),
+  TupleMakeFunctions(utils::options::parseStringList(
+  Options.get("TupleMakeFunctions", DefaultTupleMakeFunctions))) {}
 
 void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
   if (!getLangOpts().CPlusPlus11)
@@ -87,20 +93,23 @@ void UseEmplaceCheck::registerMatchers(M
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakePair = ignoringImplicit(
-  callExpr(callee(expr(ignoringImplicit(
-  declRefExpr(unless(hasExplicitTemplateArgs()),
-  to(functionDecl(hasName("::std::make_pair"
-  .bind("make_pair"));
+  auto MakeTuple = ignoringImplicit(
+  callExpr(
+  callee(expr(ignoringImplicit(declRefExpr(
+  unless(hasExplicitTemplateArgs()),
+  to(functionDecl(hasAnyName(SmallVector(
+  TupleMakeFunctions.begin(), TupleMakeFunctions.end())
+  .bind("make"));
 
-  // make_pair can return type convertible to container's element type.
+  // make_something can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(MakePair)),
-  hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
+  auto MakeTupleCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakeTuple)),
+  hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  SmallVector(TupleTypes.begin(), 
TupleTypes.end(;
 
   auto SoughtParam = materializeTemporaryExpr(
-  anyOf(has(MakePair), has(MakePairCtor),
+  anyOf(has(MakeTuple), has(MakeTupleCtor),
 HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
   Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
@@ -112,8 +121,8 @@ void UseEmplaceCheck::registerMatchers(M
 void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Call = Result.Nodes.getNodeAs("call");
   const auto *InnerCtorCall = Result.Nodes.getNodeAs("ctor");
-  const auto *MakePairCall = Result.Nodes.getNodeAs("make_pair");
-  assert((InnerCtorCall || MakePairCall) && "No push_back parameter matched")