r288119 - clang-format: Fix unnnecessary line break.

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

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

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

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

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

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

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


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


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

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

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

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

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

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


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


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

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

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

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

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

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

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

[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(&DeclRef),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

How will this work with lambdas / local classes declared inside a loop? Not 
sure if this case is going to happen in real code, but we'd better be clear 
about the limitations of the implementation.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:129
+forStmt(), cxxForRangeStmt(), whileStmt(),
+doStmt()).bind("declRef")),
+Stmt, Context);

Do you actually need to bind the node to "declRef"?


Repository:
  rL LLVM

https://reviews.llvm.org/D27187



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


r288124 - Correct comment: we are creating a canonicla decltypetype.

2016-11-29 Thread Yaron Keren via cfe-commits
Author: yrnkrn
Date: Tue Nov 29 04:08:20 2016
New Revision: 288124

URL: http://llvm.org/viewvc/llvm-project?rev=288124&view=rev
Log:
Correct comment: we are creating a canonicla decltypetype.


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

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=288124&r1=288123&r2=288124&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov 29 04:08:20 2016
@@ -4330,7 +4330,7 @@ QualType ASTContext::getDecltypeType(Exp
 DependentDecltypeType *Canon
   = DependentDecltypeTypes.FindNodeOrInsertPos(ID, InsertPos);
 if (!Canon) {
-  // Build a new, canonical typeof(expr) type.
+  // Build a new, canonical decltype(expr) type.
   Canon = new (*this, TypeAlignment) DependentDecltypeType(*this, e);
   DependentDecltypeTypes.InsertNode(Canon, InsertPos);
 }


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


r288126 - [OpenCL] Prohibit using reserve_id_t in program scope.

2016-11-29 Thread Alexey Bader via cfe-commits
Author: bader
Date: Tue Nov 29 04:21:40 2016
New Revision: 288126

URL: http://llvm.org/viewvc/llvm-project?rev=288126&view=rev
Log:
[OpenCL] Prohibit using reserve_id_t in program scope.

Patch by Egor Churaev (echuraev).

Reviewers: Anastasia

Subscribers: cfe-commits, yaxunl, bader

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


Added:
cfe/trunk/test/SemaOpenCL/invalid-clk-events-cl2.0.cl
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaOpenCL/event_t.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=288126&r1=288125&r2=288126&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov 29 04:21:40 
2016
@@ -8075,8 +8075,6 @@ def note_within_field_of_type : Note<
   "within field of type %0 declared here">;
 def note_illegal_field_declared_here : Note<
   "field of illegal %select{type|pointer type}0 %1 declared here">;
-def err_event_t_global_var : Error<
-  "the event_t type cannot be used to declare a program scope variable">;
 def err_opencl_type_struct_or_union_field : Error<
   "the %0 type cannot be used to declare a structure or union field">;
 def err_event_t_addr_space_qual : Error<
@@ -8589,6 +8587,8 @@ def note_related_result_type_inferred :
 def note_related_result_type_explicit : Note<
   "%select{overridden|current}0 method is explicitly declared 'instancetype'"
   "%select{| and is expected to return an instance of its class type}0">;
+def err_invalid_type_for_program_scope_var : Error<
+  "the %0 type cannot be used to declare a program scope variable">;
 
 }
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=288126&r1=288125&r2=288126&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Nov 29 04:21:40 2016
@@ -5909,32 +5909,31 @@ NamedDecl *Sema::ActOnVariableDeclarator
 return nullptr;
   }
 
-  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
-  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
-  // argument.
-  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
-Diag(D.getIdentifierLoc(),
- diag::err_opencl_type_can_only_be_used_as_function_parameter)
-<< R;
-D.setInvalidType();
-return nullptr;
-  }
-
-  DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
-  StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
-
-  // dllimport globals without explicit storage class are treated as extern. We
-  // have to change the storage class this early to get the right DeclContext.
-  if (SC == SC_None && !DC->isRecord() &&
-  hasParsedAttr(S, D, AttributeList::AT_DLLImport) &&
-  !hasParsedAttr(S, D, AttributeList::AT_DLLExport))
-SC = SC_Extern;
+  if (getLangOpts().OpenCL) {
+// OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+// OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+// argument.
+if (R->isImageType() || R->isPipeType()) {
+  Diag(D.getIdentifierLoc(),
+   diag::err_opencl_type_can_only_be_used_as_function_parameter)
+  << R;
+  D.setInvalidType();
+  return nullptr;
+}
 
-  DeclContext *OriginalDC = DC;
-  bool IsLocalExternDecl = SC == SC_Extern &&
-   adjustContextForLocalExternDecl(DC);
+// OpenCL v1.2 s6.9.r:
+// The event type cannot be used to declare a program scope variable.
+// OpenCL v2.0 s6.9.q:
+// The clk_event_t and reserve_id_t types cannot be declared in program 
scope.
+if (NULL == S->getParent()) {
+  if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+Diag(D.getIdentifierLoc(),
+ diag::err_invalid_type_for_program_scope_var) << R;
+D.setInvalidType();
+return nullptr;
+  }
+}
 
-  if (getLangOpts().OpenCL) {
 // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
 QualType NR = R;
 while (NR->isPointerType()) {
@@ -5954,8 +5953,40 @@ NamedDecl *Sema::ActOnVariableDeclarator
 D.setInvalidType();
   }
 }
+
+// OpenCL v1.2 s6.9.b p4:
+// The sampler type cannot be used with the __local and __global address
+// space qualifiers.
+if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
+  R.getAddressSpace() == LangAS::opencl_global)) {
+  Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
+}
+
+// OpenCL v1.2 s6.9.r:
+// The event

r288125 - Removed DEBUG_TYPE from TokenAnalyzer.h

2016-11-29 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Nov 29 04:21:28 2016
New Revision: 288125

URL: http://llvm.org/viewvc/llvm-project?rev=288125&view=rev
Log:
Removed DEBUG_TYPE from TokenAnalyzer.h

Summary:
Defining DEBUG_TYPE in a header file doesn't make sense.
It is already defined in the corresponding source file.

Reviewers: klimek, ioeric

Subscribers: klimek

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

Modified:
cfe/trunk/lib/Format/TokenAnalyzer.h

Modified: cfe/trunk/lib/Format/TokenAnalyzer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnalyzer.h?rev=288125&r1=288124&r2=288125&view=diff
==
--- cfe/trunk/lib/Format/TokenAnalyzer.h (original)
+++ cfe/trunk/lib/Format/TokenAnalyzer.h Tue Nov 29 04:21:28 2016
@@ -31,8 +31,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Debug.h"
 
-#define DEBUG_TYPE "format-formatter"
-
 namespace clang {
 namespace format {
 


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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:173-177
+/// Matches the type that was substituted for the template parameter.
+AST_MATCHER_P(SubstTemplateTypeParmType, hasReplacementType,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  return InnerMatcher.matches(Node.getReplacementType(), Finder, Builder);
+}

Ideally, this should go to ASTMatchers.h (with a proper test and documentation).



Comment at: clang-tidy/modernize/UseAutoCheck.cpp:256
+StatementMatcher makeDeclWithTemplateCastMatcher() {
+  auto ST = 
substTemplateTypeParmType(hasReplacementType(equalsBoundNode("a")));
+

It might make sense to use a more specific identifier than "a" to avoid 
collisions.


https://reviews.llvm.org/D27166



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


[PATCH] D27099: [OpenCL] Prohibit using reserve_id_t in program scope.

2016-11-29 Thread Alexey Bader via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288126: [OpenCL] Prohibit using reserve_id_t in program 
scope. (authored by bader).

Changed prior to commit:
  https://reviews.llvm.org/D27099?vs=79508&id=79525#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27099

Files:
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/SemaOpenCL/event_t.cl
  cfe/trunk/test/SemaOpenCL/invalid-clk-events-cl2.0.cl
  cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -5909,32 +5909,31 @@
 return nullptr;
   }
 
-  // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
-  // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
-  // argument.
-  if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) {
-Diag(D.getIdentifierLoc(),
- diag::err_opencl_type_can_only_be_used_as_function_parameter)
-<< R;
-D.setInvalidType();
-return nullptr;
-  }
-
-  DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
-  StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
-
-  // dllimport globals without explicit storage class are treated as extern. We
-  // have to change the storage class this early to get the right DeclContext.
-  if (SC == SC_None && !DC->isRecord() &&
-  hasParsedAttr(S, D, AttributeList::AT_DLLImport) &&
-  !hasParsedAttr(S, D, AttributeList::AT_DLLExport))
-SC = SC_Extern;
+  if (getLangOpts().OpenCL) {
+// OpenCL v2.0 s6.9.b - Image type can only be used as a function argument.
+// OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function
+// argument.
+if (R->isImageType() || R->isPipeType()) {
+  Diag(D.getIdentifierLoc(),
+   diag::err_opencl_type_can_only_be_used_as_function_parameter)
+  << R;
+  D.setInvalidType();
+  return nullptr;
+}
 
-  DeclContext *OriginalDC = DC;
-  bool IsLocalExternDecl = SC == SC_Extern &&
-   adjustContextForLocalExternDecl(DC);
+// OpenCL v1.2 s6.9.r:
+// The event type cannot be used to declare a program scope variable.
+// OpenCL v2.0 s6.9.q:
+// The clk_event_t and reserve_id_t types cannot be declared in program scope.
+if (NULL == S->getParent()) {
+  if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) {
+Diag(D.getIdentifierLoc(),
+ diag::err_invalid_type_for_program_scope_var) << R;
+D.setInvalidType();
+return nullptr;
+  }
+}
 
-  if (getLangOpts().OpenCL) {
 // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed.
 QualType NR = R;
 while (NR->isPointerType()) {
@@ -5954,8 +5953,40 @@
 D.setInvalidType();
   }
 }
+
+// OpenCL v1.2 s6.9.b p4:
+// The sampler type cannot be used with the __local and __global address
+// space qualifiers.
+if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
+  R.getAddressSpace() == LangAS::opencl_global)) {
+  Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
+}
+
+// OpenCL v1.2 s6.9.r:
+// The event type cannot be used with the __local, __constant and __global
+// address space qualifiers.
+if (R->isEventT()) {
+  if (R.getAddressSpace()) {
+Diag(D.getLocStart(), diag::err_event_t_addr_space_qual);
+D.setInvalidType();
+  }
+}
   }
 
+  DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec();
+  StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec());
+
+  // dllimport globals without explicit storage class are treated as extern. We
+  // have to change the storage class this early to get the right DeclContext.
+  if (SC == SC_None && !DC->isRecord() &&
+  hasParsedAttr(S, D, AttributeList::AT_DLLImport) &&
+  !hasParsedAttr(S, D, AttributeList::AT_DLLExport))
+SC = SC_Extern;
+
+  DeclContext *OriginalDC = DC;
+  bool IsLocalExternDecl = SC == SC_Extern &&
+   adjustContextForLocalExternDecl(DC);
+
   if (SCSpec == DeclSpec::SCS_mutable) {
 // mutable can only appear on non-static class members, so it's always
 // an error here
@@ -5988,32 +6019,6 @@
 }
   }
 
-  if (getLangOpts().OpenCL) {
-// OpenCL v1.2 s6.9.b p4:
-// The sampler type cannot be used with the __local and __global address
-// space qualifiers.
-if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local ||
-  R.getAddressSpace() == LangAS::opencl_global)) {
-  Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace);
-}
-
-// OpenCL 1.2 spec, p6.9 r:
-// The event type cannot be used to declare a program scope variable.
-// The event type cannot be used wi

[PATCH] D26916: [ObjC] Avoid a @try/@finally/@autoreleasepool fixit when parsing an expression

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Parse/ParseObjc.cpp:2877
+if (GetLookAheadToken(1).is(tok::l_brace) &&
+ExprStatementTokLoc == AtLoc) {
   char ch = Tok.getIdentifierInfo()->getNameStart()[0];

bruno wrote:
> Does this only triggers when `Res.isInvalid()` returns true in the first part 
> of the patch? I wonder if it's also safe to allow  `ExprStatementTokLoc = 
> AtLoc;` for every path or only when it fails.
Yes, this code will always flow to the body of the if with `Res.isInvalid`, but 
only after this code is executed, so we need to set `ExprStatementTokLoc` 
before the check for `Res.isInvalid`. As well as that, all users of 
`ExprStatementTokLoc` currently care only about the current  location where the 
current statement is being parsed (they check to see if some expression 
location matches it), so it should be set before a method call like 
`ParseExpressionWithLeadingAt`, and it doesn't have to be cleared as the next 
statement will have a different location anyway. So it seems safe to set 
`ExprStatementTokLoc = AtLoc` as it follows the intended convention.


Repository:
  rL LLVM

https://reviews.llvm.org/D26916



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


[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 79530.
klimek added a comment.

Add tests, update hasDeclaration to work for ElaboratedType.


https://reviews.llvm.org/D27104

Files:
  include/clang/ASTMatchers/ASTMatchersInternal.h
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -227,6 +227,17 @@
   EXPECT_FALSE(internal::has_getDecl::value);
 }
 
+TEST(HasDeclaration, ElaboratedType) {
+  EXPECT_TRUE(matches(
+  "namespace n { template  struct X {}; }"
+  "void f(n::X);",
+  parmVarDecl(hasType(qualType(hasDeclaration(cxxRecordDecl()));
+  EXPECT_TRUE(matches(
+  "namespace n { template  struct X {}; }"
+  "void f(n::X);",
+  parmVarDecl(hasType(elaboratedType(hasDeclaration(cxxRecordDecl()));
+}
+
 TEST(HasDeclaration, HasDeclarationOfTypeWithDecl) {
   EXPECT_TRUE(matches("typedef int X; X a;",
   varDecl(hasName("a"),
@@ -239,6 +250,13 @@
   EXPECT_TRUE(matches("template  class A {}; A a;",
   varDecl(hasType(templateSpecializationType(
 hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {};"
+  "template  class B { A a; };",
+  fieldDecl(hasType(templateSpecializationType(
+hasDeclaration(namedDecl(hasName("A";
+  EXPECT_TRUE(matches("template  class A {}; A a;",
+  varDecl(hasType(templateSpecializationType(
+  hasDeclaration(cxxRecordDecl()));
 }
 
 TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {
Index: include/clang/ASTMatchers/ASTMatchersInternal.h
===
--- include/clang/ASTMatchers/ASTMatchersInternal.h
+++ include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -728,48 +728,84 @@
   }
 
 private:
-  /// \brief If getDecl exists as a member of U, returns whether the inner
-  /// matcher matches Node.getDecl().
-  template 
-  bool matchesSpecialized(
-  const U &Node, ASTMatchFinder *Finder, BoundNodesTreeBuilder *Builder,
-  typename std::enable_if::value, int>::type = 0) const {
-return matchesDecl(Node.getDecl(), Finder, Builder);
-  }
-
-  /// \brief Extracts the TagDecl of a QualType and returns whether the inner
-  /// matcher matches on it.
+  /// \brief Forwards to matching on the underlying type of the QualType.
   bool matchesSpecialized(const QualType &Node, ASTMatchFinder *Finder,
   BoundNodesTreeBuilder *Builder) const {
 if (Node.isNull())
   return false;
 
-if (auto *TD = Node->getAsTagDecl())
-  return matchesDecl(TD, Finder, Builder);
-else if (auto *TT = Node->getAs())
-  return matchesDecl(TT->getDecl(), Finder, Builder);
-// Do not use getAs instead of the direct dyn_cast.
-// Calling getAs will return the canonical type, but that type does not
-// store a TemplateTypeParmDecl. We *need* the uncanonical type, if it is
-// available, and using dyn_cast ensures that.
-else if (auto *TTP = dyn_cast(Node.getTypePtr()))
-  return matchesDecl(TTP->getDecl(), Finder, Builder);
-else if (auto *OCIT = Node->getAs())
-  return matchesDecl(OCIT->getDecl(), Finder, Builder);
-else if (auto *UUT = Node->getAs())
-  return matchesDecl(UUT->getDecl(), Finder, Builder);
-else if (auto *ICNT = Node->getAs())
-  return matchesDecl(ICNT->getDecl(), Finder, Builder);
+return matchesSpecialized(*Node, Finder, Builder);
+  }
+
+  /// \brief Finds the best declaration for a type and returns whether the inner
+  /// matcher matches on it.
+  bool matchesSpecialized(const Type &Node, ASTMatchFinder *Finder,
+  BoundNodesTreeBuilder *Builder) const {
+// First, for any types that have a declaration, extract the declaration and
+// match on it.
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getDecl(), Finder, Builder);
+}
+if (const auto *S = dyn_cast(&Node)) {
+  return matchesDecl(S->getInterface(), Finder, Builder);
+}
+
+// A SubstTemplateTypeParmType exists solely to mark a type substitution
+// on the instantiated template. As users usually want to match the
+// template parameter on the uninitialized template, we can always desugar
+ 

[PATCH] D27104: Unify and simplify the behavior of the hasDeclaration matcher.

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D27104#607161, @lukasza wrote:

> Forcing shallow matching means that unit test below will stop passing after 
> this CL.
>
>   TEST(HasDeclaration, DeepTagType) {
> std::string input =
> "class Foo {};\n"
> "using Bar = Foo;\n"
> "void Function(Bar param) {}\n";
>   
> // Matcher for declaration of the Foo class.
> auto param_type_decl_matcher = cxxRecordDecl(hasName("Foo"));
>   
> // hasDeclaration / qualType-flavour.
> EXPECT_TRUE(matches(input, parmVarDecl(
> hasName("param"),
> hasType(qualType(hasDeclaration(decl(param_type_decl_matcher)));
>   }
>   
>
> I am working on a tool that renames methods in a specific namespace - the 
> tool depends on hasDeclaration doing deep-matching to tell whether an 
> UnresolvedUsingValueDecl and/or CXXDependentScopeMemberExpr end up pointing 
> at a record or template from the namespace of interest.
>
> Q1: I assume that the breaking aspect of this CL is understood and accepted?


Yes. That this worked was by chance.

> Q2: Can you please provide an example code (here or in the CL description) 
> for how to achieve deep matching (since AFAIU hasDeclaration would no longer 
> do deep matching after the CL under review)?  Can deep matching be achieved 
> by combining existing matchers with the now shallow hasDeclaration?  Or does 
> deep matching require authoring a custom matcher?  How would the custom 
> matcher look like (i.e. would it have to consider all possible types that can 
> be desugared - e.g. requiring separate code for each possible type node - 
> i.e. having separate code for hopping over a type alias and over other type 
> nodes).

I think we should either:
a) add a hasAnyDeclaration matcher, or
b) add a desugarsTo() matcher that just triest to run getAs<> on the node.

I'm going to get you an implementation in a different CL.




Comment at: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp:250
 }
 
 TEST(HasDeclaration, HasDeclarationOfCXXNewExpr) {

lukasza wrote:
> Could you please add a unit test that covers a scenario made possible by your 
> CL and which involves an elaborated type?
> 
> TEST(HasDeclaration, ElaboratedTypeAndTemplateSpecializationType) {
>   std::string input =
>   "namespace Namespace {\n"
>   "template\n"
>   "class Template {\n"
>   " public:\n"
>   "  void Method() {}\n"
>   "};\n"
>   "}  // namespace Namespace\n"
>   "template \n"
>   "void Function(Namespace::Template param) {\n"
>   "  param.Method();\n"
>   "};\n";
> 
>   // Matcher for ::Namespace::Template template decl.
>   auto param_type_decl_matcher = classTemplateDecl(
>   hasName("Template"),
>   hasParent(namespaceDecl(hasName("Namespace"))),
>   has(templateTypeParmDecl(hasName("T";
> 
>   // hasDeclaration / qualType-flavour.
>   EXPECT_TRUE(matches(input, parmVarDecl(
>   hasName("param"),
>   hasType(qualType(hasDeclaration(decl(param_type_decl_matcher)));
> }
> 
> I was a little bit surprised that ElaboratedType is handled when going via 
> qualType, but not when matching the type directly - the test code below (an 
> extension of the unit test proposed above) fails to compile.  Is this 
> expected (for this CL?  for long-term?)?
> 
>   // hasDeclaration / elaboratedType-flavour.
>   EXPECT_TRUE(matches(input, parmVarDecl(
>   hasName("param"),
>   
> hasType(elaboratedType(hasDeclaration(decl(param_type_decl_matcher)));
> 

Added unit test and added ElaboratedType to the list of allowed types for 
hasDeclaration.


https://reviews.llvm.org/D27104



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


[PATCH] D26922: [ObjC++] Don't enter a C++ declarator context when the current context is an Objective-C declaration

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

In https://reviews.llvm.org/D26922#607186, @ahatanak wrote:

> I wonder whether it is possible to avoid calling 
> DeclScopeObj.EnterDeclaratorScope at ParseDecl.cpp:5317 instead of fixing 
> Sema::ActOnCXXEnterDeclaratorScope?
>
> I believe it's calling EnterDeclaratorScope to enable name lookup when a 
> namespace-member variable is defined outside the namespace. Since that's not 
> the case here, it seems to me that it shouldn't called in the first place.
>
> http://en.cppreference.com/w/cpp/language/unqualified_lookup


Do you mean at ParseDecl:5266 (I get this line in the crash backtrace with ToT)?

AFAIK it's also used for static class member lookups for variables defined 
outside of a class. The `OuterType` is a C++ record so that's why it should be 
valid to call `EnterDeclaratorScope` there. I tested to verify this and I reach 
that call on line 5266 with the following example 3 times:

  namespace Foo {
   extern int x;
  }
  
  int Foo::x = 2; // EnterDeclaratorScope is called here
  
  class Bar {
  public:
 void foo();
 static int m;
  };
  
  int Bar::m = 2; // here
  
  class FooBar {
friend void Bar::foo(); // and here
  };

So it doesn't seem reasonable to required this only for namespaces.

I suppose it might be better to avoid calling `EnterDeclaratorScope` anyway by 
moving the current context ObjC isa checks to `ShouldEnterDeclaratorScope`.


Repository:
  rL LLVM

https://reviews.llvm.org/D26922



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


[PATCH] D27199: [libcxx] Make std::ignore constexpr

2016-11-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev created this revision.
AntonBikineev added reviewers: mclow.lists, EricWF.
AntonBikineev added a subscriber: cfe-commits.

This addresses DR 2773 .

  // 20.5.2.4, tuple creation functions:
  constexpr unspecified ignore;
  }


https://reviews.llvm.org/D27199

Files:
  include/tuple
  test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
  www/cxx1z_status.html


Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -407,7 +407,7 @@
http://wg21.link/LWG2767";>2767not_fn 
call_wrapper can form invalid typesIssaquahComplete
http://wg21.link/LWG2769";>2769Redundant 
const in the return type of any_cast(const 
any&)IssaquahComplete
http://wg21.link/LWG2771";>2771Broken 
Effects of some basic_string::compare functions in terms of 
basic_string_viewIssaquahComplete
-   http://wg21.link/LWG2773";>2773Making 
std::ignore constexprIssaquah
+   http://wg21.link/LWG2773";>2773Making 
std::ignore constexprIssaquahComplete
http://wg21.link/LWG2777";>2777basic_string_view::copy should 
use char_traits::copyIssaquahComplete
http://wg21.link/LWG2778";>2778basic_string_view is missing 
constexprIssaquah
 
Index: test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
@@ -22,6 +22,15 @@
 
 #include "test_macros.h"
 
+#if TEST_STD_VER > 14
+template 
+constexpr auto check_ce_ignore(T ignore)
+{
+ignore = 4;
+return ignore;
+}
+#endif
+
 int main()
 {
 {
@@ -40,4 +49,9 @@
 static_assert ( std::get<1>(t) == 1.1, "" );
 }
 #endif
+#if TEST_STD_VER > 14
+{
+constexpr auto t = check_ce_ignore(std::ignore);
+}
+#endif
 }
Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -70,7 +70,7 @@
 void swap(tuple&) noexcept(AND(swap(declval(), declval())...));
 };
 
-const unspecified ignore;
+constexpr unspecified ignore;
 
 template  tuple  make_tuple(T&&...); // constexpr in C++14
 template  tuple forward_as_tuple(T&&...) noexcept; // 
constexpr in C++14
@@ -1047,11 +1047,11 @@
 struct __ignore_t
 {
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
 const __ignore_t& operator=(_Tp&&) const {return *this;}
 };
 
-namespace { const __ignore_t ignore = __ignore_t(); }
+namespace { _LIBCPP_CONSTEXPR_AFTER_CXX14 const __ignore_t 
ignore = __ignore_t(); }
 
 template 
 struct __make_tuple_return_impl


Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -407,7 +407,7 @@
 	http://wg21.link/LWG2767";>2767not_fn call_wrapper can form invalid typesIssaquahComplete
 	http://wg21.link/LWG2769";>2769Redundant const in the return type of any_cast(const any&)IssaquahComplete
 	http://wg21.link/LWG2771";>2771Broken Effects of some basic_string::compare functions in terms of basic_string_viewIssaquahComplete
-	http://wg21.link/LWG2773";>2773Making std::ignore constexprIssaquah
+	http://wg21.link/LWG2773";>2773Making std::ignore constexprIssaquahComplete
 	http://wg21.link/LWG2777";>2777basic_string_view::copy should use char_traits::copyIssaquahComplete
 	http://wg21.link/LWG2778";>2778basic_string_view is missing constexprIssaquah
 
Index: test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
===
--- test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
+++ test/std/utilities/tuple/tuple.tuple/tuple.creation/tie.pass.cpp
@@ -22,6 +22,15 @@
 
 #include "test_macros.h"
 
+#if TEST_STD_VER > 14
+template 
+constexpr auto check_ce_ignore(T ignore)
+{
+ignore = 4;
+return ignore;
+}
+#endif
+
 int main()
 {
 {
@@ -40,4 +49,9 @@
 static_assert ( std::get<1>(t) == 1.1, "" );
 }
 #endif
+#if TEST_STD_VER > 14
+{
+constexpr auto t = check_ce_ignore(std::ignore);
+}
+#endif
 }
Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -70,7 +70,7 @@
 void swap(tuple&) noexcept(AND(swap(declval(), declval())...));
 };
 
-const unspecified ignore;
+constexpr unspecified ignore;
 
 template  tuple  make_tuple(T&&...); // constexpr in C++14
 template  tuple forward_as_tuple(T&&...) noexcept; // constexpr in C++14
@@ -1047,11 +1047,11 @@
 struct __ignore_t
 {
 template 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
 const __ignore_t& operator=(_Tp&&) const {return *this;}
 };
 
-namespace 

[PATCH] D26829: [clang] Allow lexer to handle string_view literals

2016-11-29 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added a comment.

@rsmith Richard, any plans to merge this or is there anything left?


https://reviews.llvm.org/D26829



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


[PATCH] D26838: [analyzer] Enforce super-region classes for various memory regions through compile-time and run-time type checks.

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:1279
   ///  associated element type, index, and super region.
   const ElementRegion *getElementRegion(QualType elementType, NonLoc Idx,
+const SubRegion *superRegion,

xazax.hun wrote:
> a.sidorin wrote:
> > I think we should perform a `cast<>` to `SubRegion` internally in order to 
> > keep API simple and do not force clients to introduce casts in their code. 
> > This will still allow us to keep nice suggestions about 
> > SubRegions/MemSpaces in our hierarchy.
> I prefer having a stricter static type.
I also believe in "static > dynamic" when it comes to type checks.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h:1347
 private:
-  template 
-  RegionTy* getSubRegion(const A1 a1, const MemRegion* superRegion);
+  template 
+  RegionTy* getSubRegion(const A1 a1, const SuperTy* superRegion);

xazax.hun wrote:
> a.sidorin wrote:
> > Maybe we should give types and paramers some more meaningful names as a 
> > part of refactoring? At least, the number in `A1` is not needed now.
> Agreed.
Hmm, should we turn this into a proper variadic function then?



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/Store.h:238
 protected:
-  const MemRegion *MakeElementRegion(const MemRegion *baseRegion,
+  const MemRegion *MakeElementRegion(const SubRegion *baseRegion,
  QualType pointeeTy, uint64_t index = 0);

xazax.hun wrote:
> Shouldn't the return value be at least a SubRegion as well?
Yep!


https://reviews.llvm.org/D26838



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


[PATCH] D26838: [analyzer] Enforce super-region classes for various memory regions through compile-time and run-time type checks.

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 79537.
NoQ marked 5 inline comments as done.
NoQ added a comment.

Thanks for the comments!
Addressed.


https://reviews.llvm.org/D26838

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  include/clang/StaticAnalyzer/Core/PathSensitive/Store.h
  lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  lib/StaticAnalyzer/Core/Store.cpp

Index: lib/StaticAnalyzer/Core/Store.cpp
===
--- lib/StaticAnalyzer/Core/Store.cpp
+++ lib/StaticAnalyzer/Core/Store.cpp
@@ -42,17 +42,18 @@
   return Store;
 }
 
-const MemRegion *StoreManager::MakeElementRegion(const MemRegion *Base,
-  QualType EleTy, uint64_t index) {
+const ElementRegion *StoreManager::MakeElementRegion(const SubRegion *Base,
+ QualType EleTy,
+ uint64_t index) {
   NonLoc idx = svalBuilder.makeArrayIndex(index);
   return MRMgr.getElementRegion(EleTy, idx, Base, svalBuilder.getContext());
 }
 
 StoreRef StoreManager::BindDefault(Store store, const MemRegion *R, SVal V) {
   return StoreRef(store, *this);
 }
 
-const ElementRegion *StoreManager::GetElementZeroRegion(const MemRegion *R,
+const ElementRegion *StoreManager::GetElementZeroRegion(const SubRegion *R,
 QualType T) {
   NonLoc idx = svalBuilder.makeZeroArrayIndex();
   assert(!T.isNull());
@@ -126,7 +127,7 @@
 case MemRegion::VarRegionKind:
 case MemRegion::CXXTempObjectRegionKind:
 case MemRegion::CXXBaseObjectRegionKind:
-  return MakeElementRegion(R, PointeeTy);
+  return MakeElementRegion(cast(R), PointeeTy);
 
 case MemRegion::ElementRegionKind: {
   // If we are casting from an ElementRegion to another type, the
@@ -171,7 +172,7 @@
 }
 
 // Otherwise, create a new ElementRegion at offset 0.
-return MakeElementRegion(baseR, PointeeTy);
+return MakeElementRegion(cast(baseR), PointeeTy);
   }
 
   // We have a non-zero offset from the base region.  We want to determine
@@ -202,10 +203,11 @@
   if (!newSuperR) {
 // Create an intermediate ElementRegion to represent the raw byte.
 // This will be the super region of the final ElementRegion.
-newSuperR = MakeElementRegion(baseR, Ctx.CharTy, off.getQuantity());
+newSuperR = MakeElementRegion(cast(baseR), Ctx.CharTy,
+  off.getQuantity());
   }
 
-  return MakeElementRegion(newSuperR, PointeeTy, newIndex);
+  return MakeElementRegion(cast(newSuperR), PointeeTy, newIndex);
 }
   }
 
@@ -271,9 +273,8 @@
 BaseDecl = BaseType->getAsCXXRecordDecl();
   assert(BaseDecl && "not a C++ object?");
 
-  const MemRegion *BaseReg =
-MRMgr.getCXXBaseObjectRegion(BaseDecl, DerivedRegVal->getRegion(),
- IsVirtual);
+  const MemRegion *BaseReg = MRMgr.getCXXBaseObjectRegion(
+  BaseDecl, cast(DerivedRegVal->getRegion()), IsVirtual);
 
   return loc::MemRegionVal(BaseReg);
 }
@@ -390,11 +391,11 @@
 return Base;
 
   Loc BaseL = Base.castAs();
-  const MemRegion* BaseR = nullptr;
+  const SubRegion* BaseR = nullptr;
 
   switch (BaseL.getSubKind()) {
   case loc::MemRegionValKind:
-BaseR = BaseL.castAs().getRegion();
+BaseR = cast(BaseL.castAs().getRegion());
 break;
 
   case loc::GotoLabelKind:
@@ -434,7 +435,8 @@
   if (Base.isUnknownOrUndef() || Base.getAs())
 return Base;
 
-  const MemRegion* BaseRegion = Base.castAs().getRegion();
+  const SubRegion *BaseRegion =
+  Base.castAs().getRegionAs();
 
   // Pointer of any type can be cast and used as array base.
   const ElementRegion *ElemR = dyn_cast(BaseRegion);
@@ -471,9 +473,8 @@
 if (isa(BaseRegion->StripCasts()))
   return UnknownVal();
 
-return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset,
-ElemR->getSuperRegion(),
-Ctx));
+return loc::MemRegionVal(MRMgr.getElementRegion(
+elementType, Offset, cast(ElemR->getSuperRegion()), Ctx));
   }
 
   const llvm::APSInt& OffI = Offset.castAs().getValue();
@@ -484,7 +485,7 @@
 OffI));
 
   // Construct the new ElementRegion.
-  const MemRegion *ArrayR = ElemR->getSuperRegion();
+  const SubRegion *ArrayR = cast(ElemR->getSuperRegion());
   return loc::MemRegionVal(MRMgr.getElementRegion(elementType, NewIdx, ArrayR,
   Ctx));
 }
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

[PATCH] D26837: [analyzer] Litter the SVal/SymExpr/MemRegion class hierarchy with asserts.

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 79538.
NoQ marked 3 inline comments as done.
NoQ added a comment.

Thanks for the comments!
Addressed.


https://reviews.llvm.org/D26837

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/StaticAnalyzer/Core/SVals.cpp

Index: lib/StaticAnalyzer/Core/SVals.cpp
===
--- lib/StaticAnalyzer/Core/SVals.cpp
+++ lib/StaticAnalyzer/Core/SVals.cpp
@@ -29,25 +29,6 @@
 // Utility methods.
 //===--===//
 
-bool SVal::hasConjuredSymbol() const {
-  if (Optional SV = getAs()) {
-SymbolRef sym = SV->getSymbol();
-if (isa(sym))
-  return true;
-  }
-
-  if (Optional RV = getAs()) {
-const MemRegion *R = RV->getRegion();
-if (const SymbolicRegion *SR = dyn_cast(R)) {
-  SymbolRef sym = SR->getSymbol();
-  if (isa(sym))
-return true;
-}
-  }
-
-  return false;
-}
-
 const FunctionDecl *SVal::getAsFunctionDecl() const {
   if (Optional X = getAs()) {
 const MemRegion* R = X->getRegion();
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -379,10 +379,8 @@
 //===--===//
 
 void GlobalsSpaceRegion::anchor() { }
-void HeapSpaceRegion::anchor() { }
-void UnknownSpaceRegion::anchor() { }
-void StackLocalsSpaceRegion::anchor() { }
-void StackArgumentsSpaceRegion::anchor() { }
+void NonStaticGlobalSpaceRegion::anchor() { }
+void StackSpaceRegion::anchor() { }
 void TypedRegion::anchor() { }
 void TypedValueRegion::anchor() { }
 void CodeTextRegion::anchor() { }
Index: include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
@@ -44,7 +44,10 @@
 
 public:
   SymbolRegionValue(SymbolID sym, const TypedValueRegion *r)
-: SymbolData(SymbolRegionValueKind, sym), R(r) {}
+  : SymbolData(SymbolRegionValueKind, sym), R(r) {
+assert(r);
+assert(isValidTypeForSymbol(r->getValueType()));
+  }
 
   const TypedValueRegion* getRegion() const { return R; }
 
@@ -81,7 +84,15 @@
   SymbolConjured(SymbolID sym, const Stmt *s, const LocationContext *lctx,
  QualType t, unsigned count, const void *symbolTag)
   : SymbolData(SymbolConjuredKind, sym), S(s), T(t), Count(count),
-LCtx(lctx), SymbolTag(symbolTag) {}
+LCtx(lctx), SymbolTag(symbolTag) {
+// FIXME: 's' might be a nullptr if we're conducting invalidation
+// that was caused by a destructor call on a temporary object,
+// which has no statement associated with it.
+// Due to this, we might be creating the same invalidation symbol for
+// two different invalidation passes (for two different temporaries).
+assert(lctx);
+assert(isValidTypeForSymbol(t));
+  }
 
   const Stmt *getStmt() const { return S; }
   unsigned getCount() const { return Count; }
@@ -120,7 +131,11 @@
 
 public:
   SymbolDerived(SymbolID sym, SymbolRef parent, const TypedValueRegion *r)
-: SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {}
+  : SymbolData(SymbolDerivedKind, sym), parentSymbol(parent), R(r) {
+assert(parent);
+assert(r);
+assert(isValidTypeForSymbol(r->getValueType()));
+  }
 
   SymbolRef getParentSymbol() const { return parentSymbol; }
   const TypedValueRegion *getRegion() const { return R; }
@@ -155,7 +170,9 @@
   
 public:
   SymbolExtent(SymbolID sym, const SubRegion *r)
-  : SymbolData(SymbolExtentKind, sym), R(r) {}
+  : SymbolData(SymbolExtentKind, sym), R(r) {
+assert(r);
+  }
 
   const SubRegion *getRegion() const { return R; }
 
@@ -193,7 +210,13 @@
   SymbolMetadata(SymbolID sym, const MemRegion* r, const Stmt *s, QualType t,
  const LocationContext *LCtx, unsigned count, const void *tag)
   : SymbolData(SymbolMetadataKind, sym), R(r), S(s), T(t), LCtx(LCtx),
-Count(count), Tag(tag) {}
+Count(count), Tag(tag) {
+  assert(r);
+  assert(s);
+  assert(isValidTypeForSymbol(t));
+  assert(LCtx);
+  assert(tag);
+}
 
   const MemRegion *getRegion() const { return R; }
   const Stmt *getStmt() const { return S; }
@@ -236,8 +259,13 @@
   QualType ToTy;
 
 public:
-  SymbolCast(const SymExpr *In, QualType From, QualType To) :
-SymExpr(SymbolCastKind), Operand(In), FromTy(From), ToTy(To) { }
+  Symb

[PATCH] D26837: [analyzer] Litter the SVal/SymExpr/MemRegion class hierarchy with asserts.

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:319
 public:
-  SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) {}
+  SymbolVal() = delete;
+  SymbolVal(SymbolRef sym) : NonLoc(SymbolValKind, sym) { assert(sym); }

a.sidorin wrote:
> I cannot completely agree with this change. For example, some STL container 
> methods require their type to be default constructible. Yes, it is a very 
> limited usage case but  I don't see strong reason to do it because there also 
> may be some another usage scenarios.
Hmm. I'd definitely suggest a container of `SymbolRef`s or `SVal`s for this use 
case.

Compare to memory region classes, which aren't constructible at all.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:478
 public:
-  explicit GotoLabel(LabelDecl *Label) : Loc(GotoLabelKind, Label) {}
+  explicit GotoLabel(LabelDecl *Label) : Loc(GotoLabelKind, Label) {
+assert(Label);

a.sidorin wrote:
> By the way, why does this ctor accept a non-constant pointer?
Ouch. I think it's because `AddrLabelExpr::getLabel()` returns a non-constant 
pointer. Worth fixing, i guess.


https://reviews.llvm.org/D26837



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


[PATCH] D26839: [analyzer] An attempt to fix pr19539 - crashes on temporaries life-extended via members

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 79540.
NoQ marked an inline comment as done.
NoQ added a comment.

Update the comment.


https://reviews.llvm.org/D26839

Files:
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/lifetime-extension.cpp

Index: test/Analysis/lifetime-extension.cpp
===
--- /dev/null
+++ test/Analysis/lifetime-extension.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -Wno-unused -std=c++11 -analyze -analyzer-checker=debug.ExprInspection -verify %s
+
+struct A {
+  int i;
+  int j[2];
+  A() : i(1) {
+j[0] = 2;
+j[1] = 3;
+  }
+  ~A() {}
+};
+
+void clang_analyzer_eval(bool);
+
+void f() {
+  const int &x = A().i; // no-crash
+  const int &y = A().j[1]; // no-crash
+  const int &z = (A().j[1], A().j[0]); // no-crash
+
+  // FIXME: All of these should be TRUE, but constructors aren't inlined.
+  clang_analyzer_eval(x == 1); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(y == 3); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(z == 2); // expected-warning{{UNKNOWN}}
+}
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -202,51 +202,70 @@
   MemRegionManager &MRMgr = StateMgr.getRegionManager();
   StoreManager &StoreMgr = StateMgr.getStoreManager();
 
-  // We need to be careful about treating a derived type's value as
-  // bindings for a base type. Unless we're creating a temporary pointer region,
-  // start by stripping and recording base casts.
-  SmallVector Casts;
-  const Expr *Inner = Ex->IgnoreParens();
-  if (!Loc::isLocType(Result->getType())) {
-while (const CastExpr *CE = dyn_cast(Inner)) {
-  if (CE->getCastKind() == CK_DerivedToBase ||
-  CE->getCastKind() == CK_UncheckedDerivedToBase)
-Casts.push_back(CE);
-  else if (CE->getCastKind() != CK_NoOp)
-break;
+  // MaterializeTemporaryExpr may appear out of place, after a few field and
+  // base-class accesses have been made to the object, even though semantically
+  // it is the whole object that gets materialized and lifetime-extended.
+  //
+  // For example:
+  //
+  //   `-MaterializeTemporaryExpr
+  // `-MemberExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // instead of the more natural
+  //
+  //   `-MemberExpr
+  // `-MaterializeTemporaryExpr
+  //   `-CXXTemporaryObjectExpr
+  //
+  // Use the usual methods for obtaining the expression of the base object,
+  // and record the adjustments that we need to make to obtain the sub-object
+  // that the whole expression 'Ex' refers to. This trick is usual,
+  // in the sense that CodeGen takes a similar route.
 
-  Inner = CE->getSubExpr()->IgnoreParens();
-}
-  }
+  SmallVector CommaLHSs;
+  SmallVector Adjustments;
+
+  const Expr *Init = Ex->skipRValueSubobjectAdjustments(CommaLHSs, Adjustments);
 
-  // Create a temporary object region for the inner expression (which may have
-  // a more derived type) and bind the value into it.
   const TypedValueRegion *TR = nullptr;
   if (const MaterializeTemporaryExpr *MT =
   dyn_cast(Result)) {
 StorageDuration SD = MT->getStorageDuration();
 // If this object is bound to a reference with static storage duration, we
 // put it in a different region to prevent "address leakage" warnings.
 if (SD == SD_Static || SD == SD_Thread)
-TR = MRMgr.getCXXStaticTempObjectRegion(Inner);
+  TR = MRMgr.getCXXStaticTempObjectRegion(Init);
   }
   if (!TR)
-TR = MRMgr.getCXXTempObjectRegion(Inner, LC);
+TR = MRMgr.getCXXTempObjectRegion(Init, LC);
 
   SVal Reg = loc::MemRegionVal(TR);
 
+  // Make the necessary adjustments to obtain the sub-object.
+  for (auto I = Adjustments.rbegin(), E = Adjustments.rend(); I != E; ++I) {
+const SubobjectAdjustment &Adj = *I;
+switch (Adj.Kind) {
+case SubobjectAdjustment::DerivedToBaseAdjustment:
+  Reg = StoreMgr.evalDerivedToBase(Reg, Adj.DerivedToBase.BasePath);
+  break;
+case SubobjectAdjustment::FieldAdjustment:
+  Reg = StoreMgr.getLValueField(Adj.Field, Reg);
+  break;
+case SubobjectAdjustment::MemberPointerAdjustment:
+  // FIXME: Unimplemented.
+  State->bindDefault(Reg, UnknownVal());
+  return State;
+}
+  }
+
+  // Try to recover some path sensitivity in case we couldn't compute the value.
   if (V.isUnknown())
 V = getSValBuilder().conjureSymbolVal(Result, LC, TR->getValueType(),
   currBldrCtx->blockCount());
+  // Bind the value of the expression to the sub-object region, and then bind
+  // the sub-object region to our expression.
   State = State->bindLoc(Reg, V);
-
-  // Re-apply the casts (from innermost to outermost) for type sanity.
-  for (SmallVectorImpl::reverse_iterator I = Casts.rbegin(),
-   E = Ca

[PATCH] D27202: [analyzer] Do not conjure a symbol for return value of a conservatively evaluated function

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: zaks.anna, dcoughlin, xazax.hun, a.sidorin.
NoQ added subscribers: cfe-commits, baloghadamsoftware.

Instead, return a `nonloc::LazyCompoundVal` of a temporary region for the call 
expression, with a trivial store in which the temporary region is invalidated.

Returning a conjured record-type symbol is painful because the return value of 
the function may suddenly change during materialization of a temporary - it 
will be hotfixed into the same lazy compound value anyway in some cases, eg. in 
`createTemporaryRegionIfNeeded` when handling a `MaterializeTemporaryExpr`. 
After this patch, we should be receiving the same temporary region during 
materialization, instead of constructing a new region, and materialization of a 
conjured structure starts doing a lot less things.

I'm including a change in the yet-to-land iterator checker 
(https://reviews.llvm.org/D25660), which should or should not be committed 
depending on the order of patches landing. This change demonstrates how the 
problem explained above causes checkers to hack around.


https://reviews.llvm.org/D27202

Files:
  lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/explain-svals.cpp


Index: test/Analysis/explain-svals.cpp
===
--- test/Analysis/explain-svals.cpp
+++ test/Analysis/explain-svals.cpp
@@ -94,5 +94,5 @@
 
 void test_6() {
   clang_analyzer_explain(conjure_S()); // expected-warning-re^lazily 
frozen compound value of temporary object constructed at statement 
'conjure_S\(\)'$
-  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value 
derived from \(symbol of type 'struct S' conjured at statement 
'conjure_S\(\)'\) for field 'z' of temporary object constructed at statement 
'conjure_S\(\)'$
+  clang_analyzer_explain(conjure_S().z); // expected-warning-re^value 
derived from \(symbol of type 'int' conjured at statement 'conjure_S\(\)'\) for 
field 'z' of temporary object constructed at statement 'conjure_S\(\)'$
 }
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -553,7 +553,28 @@
   QualType ResultTy = Call.getResultType();
   SValBuilder &SVB = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
-  SVal R = SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+  SVal R;
+
+  if (NonLoc::isCompoundType(ResultTy)) {
+// Return a (lazy) compound value for compound types.
+MemRegionManager &MemMgr = SVB.getRegionManager();
+StoreManager &StoreMgr = SVB.getStateManager().getStoreManager();
+
+const CXXTempObjectRegion *TR = MemMgr.getCXXTempObjectRegion(E, LCtx);
+
+StoreRef EmptyStore = StoreMgr.getInitialStore(LCtx);
+
+InvalidatedSymbols IS;
+RegionAndSymbolInvalidationTraits ITraits;
+ITraits.setTrait(TR, RegionAndSymbolInvalidationTraits::TK_SuppressEscape);
+StoreRef ConjuredStore = StoreMgr.invalidateRegions(
+EmptyStore.getStore(), loc::MemRegionVal(TR), E, Count, LCtx, nullptr,
+IS, ITraits, nullptr, nullptr);
+
+R = SVB.makeLazyCompoundVal(ConjuredStore, TR);
+  } else {
+R = SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+  }
   return State->BindExpr(E, LCtx, R);
 }
 
Index: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
+++ lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
@@ -68,10 +68,9 @@
 
 class IteratorPastEndChecker
 : public Checker<
-  check::PreCall, check::PostCall, check::PreStmt,
-  check::PostStmt, check::PostStmt,
-  check::PostStmt, check::BeginFunction,
-  check::DeadSymbols, eval::Assume, eval::Call> {
+  check::PreCall, check::PostCall, check::PostStmt,
+  check::PostStmt, check::PostStmt,
+  check::BeginFunction, check::DeadSymbols, eval::Assume, eval::Call> {
   mutable IdentifierInfo *II_std = nullptr, *II_find = nullptr,
  *II_find_end = nullptr, *II_find_first_of = nullptr,
  *II_find_if = nullptr, *II_find_if_not = nullptr,
@@ -105,7 +104,6 @@
 
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
   void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
-  void checkPreStmt(const CXXOperatorCallExpr *COCE, CheckerContext &C) const;
   void checkBeginFunction(CheckerContext &C) const;
   void checkPostStmt(const CXXConstructExpr *CCE, CheckerContext &C) const;
   void checkPostStmt(const DeclStmt *DS, CheckerContext &C) const;
@@ -216,27 +214,6 @@
   }
 }
 
-void IteratorPastEndChecker::checkPreStmt(const CXXOperatorCallExpr *COCE,

r288133 - [AST] Use static_assert to verify types instead of undefined classes.

2016-11-29 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Nov 29 06:41:21 2016
New Revision: 288133

URL: http://llvm.org/viewvc/llvm-project?rev=288133&view=rev
Log:
[AST] Use static_assert to verify types instead of undefined classes.

No functionliaty change intended.

Modified:
cfe/trunk/include/clang/AST/CanonicalType.h
cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/CanonicalType.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CanonicalType.h?rev=288133&r1=288132&r2=288133&view=diff
==
--- cfe/trunk/include/clang/AST/CanonicalType.h (original)
+++ cfe/trunk/include/clang/AST/CanonicalType.h Tue Nov 29 06:41:21 2016
@@ -630,8 +630,8 @@ CanQual CanQual::CreateUnsafe(Qual
 template
 template
 CanProxy CanQual::getAs() const {
-  ArrayType_cannot_be_used_with_getAs at;
-  (void)at;
+  static_assert(!TypeIsArrayType::value,
+"ArrayType cannot be used with getAs!");
 
   if (Stored.isNull())
 return CanProxy();
@@ -645,8 +645,8 @@ CanProxy CanQual::getAs() const {
 template
 template
 CanProxy CanQual::castAs() const {
-  ArrayType_cannot_be_used_with_getAs at;
-  (void)at;
+  static_assert(!TypeIsArrayType::value,
+"ArrayType cannot be used with castAs!");
 
   assert(!Stored.isNull() && isa(Stored.getTypePtr()));
   return CanQual::CreateUnsafe(Stored);

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=288133&r1=288132&r2=288133&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Nov 29 06:41:21 2016
@@ -5916,17 +5916,15 @@ inline const PartialDiagnostic &operator
 
 // Helper class template that is used by Type::getAs to ensure that one does
 // not try to look through a qualified type to get to an array type.
-template ::value ||
-  std::is_base_of::value)>
-struct ArrayType_cannot_be_used_with_getAs {};
-
-template
-struct ArrayType_cannot_be_used_with_getAs;
+template 
+using TypeIsArrayType =
+std::integral_constant::value ||
+ std::is_base_of::value>;
 
 // Member-template getAs'.
 template  const T *Type::getAs() const {
-  ArrayType_cannot_be_used_with_getAs at;
-  (void)at;
+  static_assert(!TypeIsArrayType::value,
+"ArrayType cannot be used with getAs!");
 
   // If this is directly a T type, return it.
   if (const T *Ty = dyn_cast(this))
@@ -5956,8 +5954,8 @@ inline const ArrayType *Type::getAsArray
 }
 
 template  const T *Type::castAs() const {
-  ArrayType_cannot_be_used_with_getAs at;
-  (void) at;
+  static_assert(!TypeIsArrayType::value,
+"ArrayType cannot be used with castAs!");
 
   if (const T *ty = dyn_cast(this)) return ty;
   assert(isa(CanonicalType));


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


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

2016-11-29 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a reviewer: NoQ.
NoQ added a comment.
This revision is now accepted and ready to land.

In https://reviews.llvm.org/D25660#598576, @baloghadamsoftware wrote:

> In https://reviews.llvm.org/D25660#590778, @NoQ wrote:
>
> > - Agree on the `evalAssume()` implementation (i'm still not quite 
> > understanding what the problem is here, see the new inline comments);
>
>
> I think it will be settled soon.


This part makes a lot of sense to me now, cool!

Hmm, so we model `!($x)` as `$x == 0`. That's tricky. Maybe we should also 
consider a test like `if ( (i == v.end()) == true )`; once it's done, we're be 
doing as good of a job as `RangeConstraintManager` does on numeric symbols, 
which would be great and not worth improving further.

> 
> 
>> - We should probably not warn by default on unchecked std::find (see 
>> comments following the `push_back(2016)` example), unless some strong 
>> arguments against such code patterns are provided;
> 
> It is automatic. The role of evalCall is only to reduce the exploded graph. 
> If I remove it, we get the same result (that is why we have a nonStdFind 
> there, to check this case). but with far more states. Especially in case of 
> vector, where the GNU implementation is quite complicated because of 
> optimizations.

Yep, i agree that some kind of evalCall is useful. However, it's now causing 
more positives than it should, and i think this behavior needs to be eventually 
avoided, because false positives are very scary - eg. we should try to end up 
with one state instead of two. Because by splitting states, we declare the 
possibility of both branches, which in this case is not always correct.

> 
> 
>> - A BugReporterVisitor should be added to report iterator state changes to 
>> the user across the diagnostic path;
> 
> I also thought of this. The question is where to start the chain.

At least, the very last state update to the region that failed (without copies) 
should be easy to support. Copies would be tricky - i'm thinking of tagging 
nodes where copies happened with special program point tags that help us 
understand which region was the source for the copy.

>> - More checks could be implemented in this checker, eg. passing `end()` as 
>> first argument of `std::find()` is an instant bug (somebody accidentally 
>> swapped begin and end?).
> 
> Good idea, but what if it is intentional? I do not mean that we pass end() 
> directly, but if we do a loop of find() functions where the beginning of the 
> next range is always the successor of the last found element, we may result 
> in a range of [end(), end()[, which I think is a valid empty range:
> 
>   const auto start = v.begin();
>   while(true) {
>  const auto item = find(start, v.end());
>  if(item==v.end())
> break;
>  doSomething(*item);
>  start = ++item;
>   }
>

I misread the docs, sorry><

>> A list of ideas on improving core experience, mostly for myself because i 
>> seem to be the only one with strong opinions on this:
>> 
>> - Provide a checker callback for structure copies, which would unify the 
>> multitude of similar callbacks in this checker;
> 
> A callback? Or just move the copy into a simple (or template?) function?

A callback would certainly be better, because it removes a lot of boilerplate 
from the checker (to subscribe to one callback instead of five would be great). 
But that's a future plan, not for this patch.

>> - Consider removing the conjured structure symbol hack.
> 
> Which hack do you mean here? In evalCall() of the various std functions? As I 
> mentioned, they can be removed, but then we will get more states in the 
> exploded graph.

I've just made an attempt in https://reviews.llvm.org/D27202.



I think this is good to go as an alpha checker!
I'm still in favor of more comments in this code.
One more minor inline nit.




Comment at: lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp:459
+  } else if (const auto TruthVal = RetVal.getAs()) {
+if (State = processComparison(
+State, getRegionOrSymbol(LVal), getRegionOrSymbol(RVal),

This produces a `-Wparentheses` warning, i think we should silence it by 
putting an extra `()` around operator `=` because the assignment is intentional 
here.


https://reviews.llvm.org/D25660



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


[PATCH] D27204: [libcxxabi] Introduce an externally threaded libc++abi variant

2016-11-29 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath created this revision.
rmaprath added reviewers: mclow.lists, EricWF, bcraig.
rmaprath added a subscriber: cfe-commits.
Herald added a subscriber: mgorny.

This is more-or-less a mirror image of https://reviews.llvm.org/D21968, 
repeated for libcxxabi.

I will soon upload a dependent patch for libcxx which makes it possible to run 
the libcxx test suite with the externally-threaded libcxxabi variant.


https://reviews.llvm.org/D27204

Files:
  CMakeLists.txt
  src/CMakeLists.txt
  src/config.h
  src/threading_support.h
  test/CMakeLists.txt
  test/libcxxabi/test/config.py
  test/lit.cfg
  test/lit.site.cfg.in
  test/support/external_threads.cpp

Index: test/support/external_threads.cpp
===
--- /dev/null
+++ test/support/external_threads.cpp
@@ -0,0 +1,10 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+#define _LIBCXXABI_BUILDING_EXTERNAL_THREADS
+#include 
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -19,6 +19,8 @@
 config.host_triple  = "@LLVM_HOST_TRIPLE@"
 config.target_triple= "@TARGET_TRIPLE@"
 config.use_target   = len("@LIBCXXABI_TARGET_TRIPLE@") > 0
+config.cxx_ext_threads  = "@LIBCXX_HAS_EXTERNAL_THREAD_API@"
+config.cxxabi_ext_threads   = "@LIBCXXABI_HAS_EXTERNAL_THREAD_API@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXXABI_SOURCE_DIR@/test/lit.cfg")
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -18,7 +18,7 @@
 config.name = 'libc++abi'
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = ['.cpp', '.s']
+config.suffixes = ['.pass.cpp', '.sh.s', '.sh.cpp']
 
 # test_source_root: The root path where tests are located.
 config.test_source_root = os.path.dirname(__file__)
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -39,6 +39,9 @@
 self.config.available_features.add('libcxxabi-no-exceptions')
 if not self.cxx.addCompileFlagIfSupported(['-Xclang', '-mqualified-function-type-info']):
 self.config.available_features.add("libcxxabi-no-qualified-function-types")
+# test_exception_storage_nodynmem.pass.cpp fails under this specific configuration
+if self.get_lit_bool('cxxabi_ext_threads', False) and self.get_lit_bool('libcxxabi_shared', False):
+self.config.available_features.add('libcxxabi-shared-externally-threaded')
 
 def configure_compile_flags(self):
 self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -17,6 +17,9 @@
 pythonize_bool(LIBCXXABI_ENABLE_THREADS)
 pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
+pythonize_bool(LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
+pythonize_bool(LIBCXX_HAS_EXTERNAL_THREAD_API)
+pythonize_bool(LIBCXXABI_HAS_EXTERNAL_THREAD_API)
 set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
 "TargetInfo to use when setting up test environment.")
 set(LIBCXXABI_EXECUTOR "None" CACHE STRING
@@ -34,6 +37,14 @@
   set(LIBCXXABI_TEST_DEPS cxxabi_static)
 endif()
 
+if (LIBCXXABI_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxxabi_external_threads")
+endif()
+
+if (LIBCXX_HAS_EXTERNAL_THREAD_API)
+  list(APPEND LIBCXXABI_TEST_DEPS "cxx_external_threads")
+endif()
+
 if (NOT LIBCXXABI_STANDALONE_BUILD)
   list(APPEND LIBCXXABI_TEST_DEPS cxx)
   if (LIBCXXABI_USE_LLVM_UNWINDER)
Index: src/threading_support.h
===
--- src/threading_support.h
+++ src/threading_support.h
@@ -15,93 +15,149 @@
 
 #ifndef _LIBCXXABI_HAS_NO_THREADS
 
-#if defined(_LIBCXXABI_USE_THREAD_API_PTHREAD)
+#ifndef __libcxxabi_has_include
+  #ifndef __has_include
+#define __libcxxabi_has_include(x) 0
+  #else
+#define __libcxxabi_has_include(x) __has_include(x)
+  #endif
+#endif
+
+#if defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL) && \
+__libcxxabi_has_include()
+#include 
+#else
 #include 
 
+#if defined(_LIBCXXABI_HAS_THREAD_API_EXTERNAL)
+#define _LIBCXXABI_THREAD_ABI_VISIBILITY _LIBCXXABI_FUNC_VIS
+#else
 #define _LIBCXXABI_THREAD_ABI_VISIBILITY inline _LIBCXXABI_INLINE_VISIBILITY
+#endif
 
 // Mutex
 typedef pthread_mutex_t __libcxxabi_mutex_t;

[PATCH] D27207: Adds hasUnqualifiedDesugaredType to allow matching through type sugar.

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek created this revision.
klimek added reviewers: bkramer, lukasza.
klimek added a subscriber: cfe-commits.

https://reviews.llvm.org/D27207

Files:
  docs/LibASTMatchersReference.html
  include/clang/ASTMatchers/ASTMatchers.h
  lib/ASTMatchers/Dynamic/Registry.cpp
  unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===
--- unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -247,6 +247,12 @@
   cxxNewExpr(hasDeclaration(functionDecl(parameterCountIs(1));
 }
 
+TEST(HasUnqualifiedDesugaredType, DesugarsUsing) {
+  EXPECT_TRUE(
+  matches("struct A {}; using B = A; B b;",
+  varDecl(hasType(hasUnqualifiedDesugaredType(recordType());
+}
+
 TEST(HasUnderlyingDecl, Matches) {
   EXPECT_TRUE(matches("namespace N { template  void f(T t); }"
   "template  void g() { using N::f; f(T()); }",
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -270,6 +270,7 @@
   REGISTER_MATCHER(hasUnaryOperand);
   REGISTER_MATCHER(hasUnarySelector);
   REGISTER_MATCHER(hasUnderlyingDecl);
+  REGISTER_MATCHER(hasUnqualifiedDesugaredType);
   REGISTER_MATCHER(hasValueType);
   REGISTER_MATCHER(ifStmt);
   REGISTER_MATCHER(ignoringImplicit);
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2738,6 +2738,22 @@
   .matches(Node, Finder, Builder);
 }
 
+/// \brief Matches if the matched type matches the unqualified desugared
+/// type of the matched node.
+///
+/// For example, in:
+/// \code
+///   class A {};
+///   using B = A;
+/// \endcode
+/// The matcher type(hasUniqualifeidDesugaredType(recordType())) matches
+/// both B and A.
+AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher,
+  InnerMatcher) {
+  return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder,
+  Builder);
+}
+
 /// \brief Matches if the matched type is a reference type and the referenced
 /// type matches the specified matcher.
 ///
Index: docs/LibASTMatchersReference.html
===
--- docs/LibASTMatchersReference.html
+++ docs/LibASTMatchersReference.html
@@ -3758,8 +3758,8 @@
 
 
 
-MatcherAddrLabelExpr>hasDeclarationMatcherDecl>  InnerMatcher
-Matches a node if the declaration associated with that node
+MatcherAddrLabelExpr>hasDeclarationMatcherDecl>  InnerMatcher
+Matches a node if the declaration associated with that node
 matches the given matcher.
 
 The associated declaration is:
@@ -3772,13 +3772,13 @@
 Also usable as Matcher for any T supporting the getDecl() member
 function. e.g. various subtypes of clang::Type and various expressions.
 
-Usable as: MatcherCallExpr>, MatcherCXXConstructExpr>,
-  MatcherCXXNewExpr>,
-  MatcherDeclRefExpr>, MatcherEnumType>, MatcherInjectedClassNameType>,
-  MatcherLabelStmt>, MatcherAddrLabelExpr>, MatcherMemberExpr>,
-  MatcherQualType>, MatcherRecordType>, MatcherTagType>,
-  MatcherTemplateSpecializationType>, MatcherTemplateTypeParmType>,
-  MatcherTypedefType>, MatcherUnresolvedUsingType>
+Usable as: MatcherAddrLabelExpr>, MatcherCallExpr>,
+  Ma

[PATCH] D27140: Allow clang to write compilation database records

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added reviewers: bkramer, akyrtzi.
klimek added a comment.

Adding some folks. One question is whether we can use the additional output 
stuff doug added at some point for this.


https://reviews.llvm.org/D27140



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


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Can you add a test to ASTMatchersNodeTests.cpp? Otherwise LG for the matcher 
parts.


https://reviews.llvm.org/D27181



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: lib/Tooling/JSONCompilationDatabase.cpp:266
+nodeToCommandLine(Syntax, std::get<2>(CommandsRef[I])),
+Output ? Output->getValue(OutputStorage) : "");
   }

joerg wrote:
> klimek wrote:
> > joerg wrote:
> > > klimek wrote:
> > > > joerg wrote:
> > > > > klimek wrote:
> > > > > > Optional: I'd probably let the nodeToCommandLine handle the null 
> > > > > > value and make this code more straight forward?
> > > > > I couldn't find a way to create a synthetic node without changing the 
> > > > > YAML API.
> > > > I'm probably missing something - why would we need a synthetic node? 
> > > > Can't we just put nullptr into the vector?
> > > That's what I am doing and why this line checks output :)
> > Ok, let's ask differently: why is it a problem if we put a nullptr into the 
> > array?
> I think it just adds unnecessary complexity. An empty file name is not a 
> valid output, so "" vs Optional has the same result. I'd have prefered to 
> keep this complexity inside the JSON parser, but that would have meant 
> creating a synthetic node with value "" and there is no API for that at the 
> moment.
Don't we thus want to actually be able to err out on a higher level when 
getting an empty output dir, but be OK with an unspecified (-> nullptr) one?


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: hokein.
ioeric added a subscriber: cfe-commits.

https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,41 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "namespace nb {\n"
+  "void f() {\n"
+  "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+  "}\n"
+  "}  // namespace nb\n"
+  "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult &Result,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const Decl *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const Decl *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-cla

[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx removed rL LLVM as the repository for this revision.
flx updated this revision to Diff 79550.

https://reviews.llvm.org/D27187

Files:
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tidy/utils/DeclRefExprUtils.cpp
  clang-tidy/utils/DeclRefExprUtils.h
  test/clang-tidy/performance-unnecessary-value-param.cpp


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -225,6 +225,15 @@
   // CHECK-FIXES: F = std::move(E);
 }
 
+// The argument could be moved but is not since copy statement is inside a 
loop.
+void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied
+  // CHECK-FIXES: void PositiveNoMoveInsideLoop(const ExpensiveMovableType& E) 
{
+  for (;;) {
+auto F = E;
+  }
+}
+
 void PositiveConstRefNotMoveConstructible(ExpensiveToCopyType T) {
   // CHECK-MESSAGES: [[@LINE-1]]:63: warning: the parameter 'T' is copied
   // CHECK-FIXES: void PositiveConstRefNotMoveConstructible(const 
ExpensiveToCopyType& T) {
Index: clang-tidy/utils/DeclRefExprUtils.h
===
--- clang-tidy/utils/DeclRefExprUtils.h
+++ clang-tidy/utils/DeclRefExprUtils.h
@@ -47,6 +47,11 @@
 bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt,
   ASTContext &Context);
 
+// Returns true if DeclRefExpr has a loop statement (ForStmt, CXXForRangeStmt,
+// WhileStmt, DoStmt) as ancestor.
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+ ASTContext &Context);
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/utils/DeclRefExprUtils.cpp
===
--- clang-tidy/utils/DeclRefExprUtils.cpp
+++ clang-tidy/utils/DeclRefExprUtils.cpp
@@ -120,6 +120,17 @@
   return !Matches.empty();
 }
 
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+ ASTContext &Context) {
+  auto Matches =
+  match(findAll(declRefExpr(equalsNode(&DeclRef),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),
+doStmt())),
+Stmt, Context);
+  return Matches.empty();
+}
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/performance/UnnecessaryValueParamCheck.cpp
===
--- clang-tidy/performance/UnnecessaryValueParamCheck.cpp
+++ clang-tidy/performance/UnnecessaryValueParamCheck.cpp
@@ -104,6 +104,8 @@
   if (!IsConstQualified) {
 auto CanonicalType = Param->getType().getCanonicalType();
 if (AllDeclRefExprs.size() == 1 &&
+!utils::decl_ref_expr::hasLoopStmtAncestor(
+**AllDeclRefExprs.begin(), *Function->getBody(), *Result.Context) 
&&
 ((utils::type_traits::hasNonTrivialMoveConstructor(CanonicalType) &&
   utils::decl_ref_expr::isCopyConstructorArgument(
   **AllDeclRefExprs.begin(), *Function->getBody(),


Index: test/clang-tidy/performance-unnecessary-value-param.cpp
===
--- test/clang-tidy/performance-unnecessary-value-param.cpp
+++ test/clang-tidy/performance-unnecessary-value-param.cpp
@@ -225,6 +225,15 @@
   // CHECK-FIXES: F = std::move(E);
 }
 
+// The argument could be moved but is not since copy statement is inside a loop.
+void PositiveNoMoveInsideLoop(ExpensiveMovableType E) {
+  // CHECK-MESSAGES: [[@LINE-1]]:52: warning: the parameter 'E' is copied
+  // CHECK-FIXES: void PositiveNoMoveInsideLoop(const ExpensiveMovableType& E) {
+  for (;;) {
+auto F = E;
+  }
+}
+
 void PositiveConstRefNotMoveConstructible(ExpensiveToCopyType T) {
   // CHECK-MESSAGES: [[@LINE-1]]:63: warning: the parameter 'T' is copied
   // CHECK-FIXES: void PositiveConstRefNotMoveConstructible(const ExpensiveToCopyType& T) {
Index: clang-tidy/utils/DeclRefExprUtils.h
===
--- clang-tidy/utils/DeclRefExprUtils.h
+++ clang-tidy/utils/DeclRefExprUtils.h
@@ -47,6 +47,11 @@
 bool isCopyAssignmentArgument(const DeclRefExpr &DeclRef, const Stmt &Stmt,
   ASTContext &Context);
 
+// Returns true if DeclRefExpr has a loop statement (ForStmt, CXXForRangeStmt,
+// WhileStmt, DoStmt) as ancestor.
+bool hasLoopStmtAncestor(const DeclRefExpr &DeclRef, const Stmt &Stmt,
+ ASTContext &Context);
+
 } // namespace decl_ref_expr
 } // namespace utils
 } // namespace tidy
Index: clang-tidy/utils/DeclRefExprUtils.cpp
==

[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx marked an inline comment as done.
flx added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(&DeclRef),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

alexfh wrote:
> How will this work with lambdas / local classes declared inside a loop? Not 
> sure if this case is going to happen in real code, but we'd better be clear 
> about the limitations of the implementation.
Why would this not work? Could you give an example? The way the function is 
written it handles my the use case for identifying when moving the parameter is 
not safe, so I could also just move it into the UnnecessaryValueParamCheck.


https://reviews.llvm.org/D27187



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


[PATCH] D26991: Hoist redundant load

2016-11-29 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists requested changes to this revision.
mclow.lists added inline comments.
This revision now requires changes to proceed.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

I just realized that we can't do this.
This imposes a requirement that the `value_type` be copy-constructible.

With this in place, we can't search a sequence of move-only types.


https://reviews.llvm.org/D26991



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM with few nits.




Comment at: change-namespace/ChangeNamespace.cpp:434
+assert(Func);
+const Decl *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");

auto



Comment at: change-namespace/ChangeNamespace.cpp:449
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const Decl *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");

auto.



Comment at: change-namespace/ChangeNamespace.cpp:713
+const DeclRefExpr *Ref) {
+SourceRange RefRange = Ref->getSourceRange();
+replaceQualifiedSymbolInDeclContext(Result, UseContext, 
RefRange.getBegin(),

nits: incorrect indentation. Should be two space.


https://reviews.llvm.org/D27208



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


[PATCH] D27211: [clang-format] Implement comment reflowing

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

> for these cases the
>  original Breakable{Line,Block}Comment still breaks the long lines.

Do you intend for this to continue to be the case?


https://reviews.llvm.org/D27211



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 79555.
ioeric marked 3 inline comments as done.
ioeric added a comment.

- Address comments.


https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,41 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "namespace nb {\n"
+  "void f() {\n"
+  "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+  "}\n"
+  "}  // namespace nb\n"
+  "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult &Result,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorag

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 79556.
arphaman added a comment.

The updated diff has the following changes:

- The default value for '-fstrict-return' is now the same across all platforms, 
the Darwin specific -fno-strict-return was removed.
- The 'fno-strict-return' optimisation avoidance can only be done by functions 
that return trivially copyable types.
- A new test verifies that Objective-C++ methods and blocks never get the 
return optimisation regardless of the '-fstrict-return' flag.
- The updated test adds explanation comments and uses Mehdi's advice for LABEL 
checks and common prefix.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163

Files:
  include/clang/AST/Decl.h
  include/clang/Basic/LangOptions.def
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Sema/AnalysisBasedWarnings.h
  include/clang/Sema/Sema.h
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/AnalysisBasedWarnings.cpp
  lib/Sema/Sema.cpp
  test/CodeGenCXX/return.cpp
  test/CodeGenObjCXX/return.mm
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fstrict-return %s 2>&1 | FileCheck -check-prefix=CHECK-STRICT-RETURN %s
+// RUN: %clang -### -S -fno-strict-return %s 2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-RETURN %s
+// CHECK-STRICT-RETURN-NOT: "-fno-strict-return"
+// CHECK-NO-STRICT-RETURN: "-fno-strict-return"
Index: test/CodeGenObjCXX/return.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/return.mm
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -O -o - %s | FileCheck %s
+
+@interface I
+@end
+
+@implementation I
+
+- (int)method {
+}
+
+@end
+
+enum Enum {
+  a
+};
+
+int (^block)(Enum) = ^int(Enum e) {
+  switch (e) {
+  case a:
+return 1;
+  }
+};
+
+// Ensure that both methods and blocks don't use the -fstrict-return undefined
+// behaviour optimization.
+
+// CHECK-NOT: call void @llvm.trap
+// CHECK-NOT: unreachable
Index: test/CodeGenCXX/return.cpp
===
--- test/CodeGenCXX/return.cpp
+++ test/CodeGenCXX/return.cpp
@@ -1,12 +1,105 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -O -o - %s | FileCheck %s --check-prefix=CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - %s | FileCheck --check-prefixes=CHECK,CHECK-COMMON %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -O -o - %s | FileCheck %s --check-prefixes=CHECK-OPT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -Wno-return-type -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -O -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT-OPT,CHECK-COMMON
 
-// CHECK: @_Z9no_return
-// CHECK-OPT: @_Z9no_return
+// CHECK-COMMON-LABEL: @_Z9no_return
 int no_return() {
   // CHECK:  call void @llvm.trap
   // CHECK-NEXT: unreachable
 
   // CHECK-OPT-NOT: call void @llvm.trap
   // CHECK-OPT: unreachable
+
+  // -fno-strict-return should not emit trap + unreachable but it should return
+  // an undefined value instead.
+
+  // CHECK-NOSTRICT: entry:
+  // CHECK-NOSTRICT-NEXT: alloca
+  // CHECK-NOSTRICT-NEXT: load
+  // CHECK-NOSTRICT-NEXT: ret i32
+  // CHECK-NOSTRICT-NEXT: }
+
+  // CHECK-NOSTRICT-OPT: entry:
+  // CHECK-NOSTRICT-OPT: ret i32 undef
+}
+
+enum Enum {
+  A, B
+};
+
+// CHECK-COMMON-LABEL: @_Z21alwaysOptimizedReturn4Enum
+int alwaysOptimizedReturn(Enum e) {
+  switch (e) {
+  case A: return 1;
+  case B: return 2;
+  }
+  // This function covers all the cases of 'Enum', so the undefined behaviour
+  // optimization is allowed even if -fno-strict-return is used.
+
+  // CHECK-NOSTRICT:  call void @llvm.trap()
+  // CHECK-NOSTRICT-NEXT: unreachable
+}
+
+// CHECK-NOSTRICT-LABEL: @_Z23strictlyOptimizedReturn4Enum
+int strictlyOptimizedReturn(Enum e) {
+  switch (e) {
+  case A: return 22;
+  }
+  // Undefined behaviour optimization shouldn't be used when -fno-strict-return
+  // is turned on, as not all enum cases are covered in this function.
+
+  // CHECK-NOSTRICT-NOT: call void @llvm.trap
+  // CHECK-

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: lib/Sema/AnalysisBasedWarnings.cpp:530
+  // Don't need to mark Objective-C methods or blocks since the undefined
+  // behaviour optimization isn't used for them.
+}

mehdi_amini wrote:
> Quuxplusone wrote:
> > This seems like a trap waiting to spring on someone, unless there's a 
> > technical reason that methods and blocks cannot possibly use the same 
> > optimization paths as regular functions. ("Nobody's gotten around to 
> > implementing it yet" is the most obvious nontechnical reason for the 
> > current difference.) Either way, I'd expect this patch to include test 
> > cases for both methods and blocks, to verify that the behavior you expect 
> > is actually the behavior that happens. Basically, it ought to have a 
> > regression test targeting the regression that I'm predicting is going to 
> > spring on someone as soon as they implement optimizations for methods and 
> > blocks.
> > 
> > Also, one dumb question: what about C++ lambdas? are they FunctionDecls 
> > too? test case?
> > This seems like a trap waiting to spring on someone, unless there's a 
> > technical reason that methods and blocks cannot possibly use the same 
> > optimization paths as regular functions.
> 
> The optimization path in LLVM is the same. I think the difference lies in 
> clang IRGen: there is no "unreachable" generated for these so the optimizer 
> can't be aggressive. So this patch is not changing anything for Objective-C 
> methods and blocks, and I expect that we *already* have a test that covers 
> this behavior (if not we should add one).
Mehdi is right, the difference is in IRGen - methods and blocks never get the 
trap and unreachable IR return optmisation. I don't think we have a test for 
this though, so I added a regression test case that verifies this.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 79558.
ioeric added a comment.

- Format code.


https://reviews.llvm.org/D27208

Files:
  change-namespace/ChangeNamespace.cpp
  change-namespace/ChangeNamespace.h
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,40 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code = "namespace na {\n"
+ "class A {\n"
+ "public:\n"
+ "  static void f() {}\n"
+ "};\n"
+ "void a_f() {}\n"
+ "static void s_f() {}\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+ "}\n"
+ "}  // namespace nb\n"
+ "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: change-namespace/ChangeNamespace.h
===
--- change-namespace/ChangeNamespace.h
+++ change-namespace/ChangeNamespace.h
@@ -76,6 +76,10 @@
   void fixUsingShadowDecl(const ast_matchers::MatchFinder::MatchResult &Result,
   const UsingDecl *UsingDeclaration);
 
+  void fixDeclRefExpr(const ast_matchers::MatchFinder::MatchResult &Result,
+  const DeclContext *UseContext, const NamedDecl *From,
+  const DeclRefExpr *Ref);
+
   // Information about moving an old namespace.
   struct MoveNamespace {
 // The start offset of the namespace block being moved in the original
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of

[clang-tools-extra] r288139 - [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Tue Nov 29 08:15:14 2016
New Revision: 288139

URL: http://llvm.org/viewvc/llvm-project?rev=288139&view=rev
Log:
[change-namespace] fix non-calling function references.

Reviewers: hokein

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=288139&r1=288138&r2=288139&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Tue Nov 29 
08:15:14 2016
@@ -369,11 +369,13 @@ void ChangeNamespaceTool::registerMatche
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@ void ChangeNamespaceTool::run(
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-clang::StorageClass::SC_Static &&
+StorageClass::SC_Static &&
 Func->isOutOfLine())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange CalleeRange = Call->getCallee()->getSourceRange();
+SourceRange CalleeRange = Call->getCallee()->getSourceRange();
 replaceQualifiedSymbolInDeclContext(
 Result, Context->getDeclContext(), CalleeRange.getBegin(),
 CalleeRange.getEnd(), llvm::cast(Func));
@@ -698,6 +706,15 @@ void ChangeNamespaceTool::fixUsingShadow
 llvm_unreachable(llvm::toString(std::move(Err)).c_str());
 }
 
+void ChangeNamespaceTool::fixDeclRefExpr(
+const ast_matchers::MatchFinder::MatchResult &Result,
+const DeclContext *UseContext, const NamedDecl *From,
+const DeclRefExpr *Ref) {
+  SourceRange RefRange = Ref->getSourceRange();
+  replaceQualifiedSymbolInDeclContext(Result, UseContext, RefRange.getBegin(),
+  RefRange.getEnd(), From);
+}
+
 void ChangeNamespaceTool::onEndOfTranslationUnit() {
   // Move namespace blocks and insert forward declaration to old namespace.
   for (const auto &FileAndNsMoves : MoveNamespaces) {

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.h?rev=288139&r1=288138&r2=288139&view=diff
===

[PATCH] D27208: [change-namespace] fix non-calling function references.

2016-11-29 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288139: [change-namespace] fix non-calling function 
references. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27208?vs=79558&id=79559#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27208

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.h
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -457,6 +457,40 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, FixNonCallingFunctionReferences) {
+  std::string Code = "namespace na {\n"
+ "class A {\n"
+ "public:\n"
+ "  static void f() {}\n"
+ "};\n"
+ "void a_f() {}\n"
+ "static void s_f() {}\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "auto *ref1 = A::f; auto *ref2 = a_f; auto *ref3 = s_f;\n"
+ "}\n"
+ "}  // namespace nb\n"
+ "}  // namespace na\n";
+  std::string Expected =
+  "namespace na {\n"
+  "class A {\n"
+  "public:\n"
+  "  static void f() {}\n"
+  "};\n"
+  "void a_f() {}\n"
+  "static void s_f() {}\n"
+  "\n"
+  "}  // namespace na\n"
+  "namespace x {\n"
+  "namespace y {\n"
+  "void f() {\n"
+  "auto *ref1 = na::A::f; auto *ref2 = na::a_f; auto *ref3 = na::s_f;\n"
+  "}\n"
+  "}  // namespace y\n"
+  "}  // namespace x\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 TEST_F(ChangeNamespaceTest, MoveAndFixGlobalVariables) {
   std::string Code = "namespace na {\n"
  "int GlobA;\n"
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -369,11 +369,13 @@
 hasAncestor(namespaceDecl(isAnonymous())),
 hasAncestor(cxxRecordDecl(,
hasParent(namespaceDecl()));
-  Finder->addMatcher(
-  decl(forEachDescendant(callExpr(callee(FuncMatcher)).bind("call")),
-   IsInMovedNs, unless(isImplicit()))
-  .bind("dc"),
-  this);
+  Finder->addMatcher(decl(forEachDescendant(expr(anyOf(
+  callExpr(callee(FuncMatcher)).bind("call"),
+  declRefExpr(to(FuncMatcher.bind("func_decl")))
+  .bind("func_ref",
+  IsInMovedNs, unless(isImplicit()))
+ .bind("dc"),
+ this);
 
   auto GlobalVarMatcher = varDecl(
   hasGlobalStorage(), hasParent(namespaceDecl()),
@@ -421,26 +423,32 @@
 assert(Var);
 if (Var->getCanonicalDecl()->isStaticDataMember())
   return;
-const clang::Decl *Context = Result.Nodes.getNodeAs("dc");
+const auto *Context = Result.Nodes.getNodeAs("dc");
 assert(Context && "Empty decl context.");
-clang::SourceRange VarRefRange = VarRef->getSourceRange();
-replaceQualifiedSymbolInDeclContext(
-Result, Context->getDeclContext(), VarRefRange.getBegin(),
-VarRefRange.getEnd(), llvm::cast(Var));
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Var), VarRef);
+  } else if (const auto *FuncRef =
+ Result.Nodes.getNodeAs("func_ref")) {
+const auto *Func = Result.Nodes.getNodeAs("func_decl");
+assert(Func);
+const auto *Context = Result.Nodes.getNodeAs("dc");
+assert(Context && "Empty decl context.");
+fixDeclRefExpr(Result, Context->getDeclContext(),
+   llvm::cast(Func), FuncRef);
   } else {
-const auto *Call = Result.Nodes.getNodeAs("call");
+const auto *Call = Result.Nodes.getNodeAs("call");
 assert(Call != nullptr && "Expecting callback for CallExpr.");
-const clang::FunctionDecl *Func = Call->getDirectCallee();
+const FunctionDecl *Func = Call->getDirectCallee();
 assert(Func != nullptr);
 // Ignore out-of-line static methods since they will be handled by nested
 // name specifiers.
 if (Func->getCanonicalDecl()->getStorageClass() ==
-clang::StorageClass::SC_Static &&
+StorageClass::SC_Static &&
 Func->isOutOfLine())
   return;
-const clang::Dec

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: test/CodeGenCXX/return.cpp:47
+  // CHECK-NOSTRICT-OPT-NEXT: zext
+  // CHECK-NOSTRICT-OPT-NEXT: ret i32
+}

mehdi_amini wrote:
> Document what's going on in the tests please.
> 
I added some comments that help explain what's being tested. I also removed the 
`-fno-strict-return` checks with `-O` (except for the checks in the first 
function) as the non-optimised `-fno-strict-return` tests should be sufficient.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

It's not the directory, but the output file. That's optional since it is a new 
addition and I don't want to invalidate all existing JSON databases.


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D26991: Hoist redundant load

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added inline comments.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

mclow.lists wrote:
> I just realized that we can't do this.
> This imposes a requirement that the `value_type` be copy-constructible.
> 
> With this in place, we can't search a sequence of move-only types.
Ok, I'll remove this change while pushing. I'll change the subject as well, 
because now this patch is just removing the unused code.
Thanks for the review.


https://reviews.llvm.org/D26991



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-11-29 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov updated this revision to Diff 79560.
kromanenkov added a comment.

Thanks for your comments, Artem! Make function name less ambiguous. Also I take 
liberty to update analogical function name.


https://reviews.llvm.org/D25475

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

Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -35,8 +35,7 @@
   clang_analyzer_eval(&A::getPtr == &A::getPtr); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::getPtr == 0); // expected-warning{{FALSE}}
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(&A::m_ptr == &A::m_ptr); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&A::m_ptr == &A::m_ptr); // expected-warning{{TRUE}}
 }
 
 namespace PR15742 {
@@ -62,21 +61,114 @@
   }
 }
 
-// ---
-// FALSE NEGATIVES
-// ---
-
 bool testDereferencing() {
   A obj;
   obj.m_ptr = 0;
 
   A::MemberPointer member = &A::m_ptr;
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(obj.*member == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(obj.*member == 0); // expected-warning{{TRUE}}
 
   member = 0;
 
-  // FIXME: Should emit a null dereference.
-  return obj.*member; // no-warning
+  return obj.*member; // expected-warning{{}}
+}
+
+namespace testPointerToMemberFunction {
+  struct A {
+virtual int foo() { return 1; }
+int bar() { return 2;  }
+  };
+
+  struct B : public A {
+virtual int foo() { return 3; }
+  };
+
+  typedef int (A::*AFnPointer)();
+  typedef int (B::*BFnPointer)();
+
+  void testPointerToMemberCasts() {
+AFnPointer AFP = &A::bar;
+BFnPointer StaticCastedBase2Derived = static_cast(&A::bar),
+   CCastedBase2Derived = (BFnPointer) (&A::bar);
+A a;
+B b;
+
+clang_analyzer_eval((a.*AFP)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval((b.*StaticCastedBase2Derived)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval(((b.*CCastedBase2Derived)() == 2)); // expected-warning{{TRUE}}
+  }
+
+  void testPointerToMemberVirtualCall() {
+A a;
+B b;
+A *APtr = &a;
+AFnPointer AFP = &A::foo;
+
+clang_analyzer_eval((APtr->*AFP)() == 1); // expected-warning{{TRUE}}
+
+APtr = &b;
+
+clang_analyzer_eval((APtr->*AFP)() == 3); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberFunction namespace
+
+namespace testPointerToMemberData {
+  struct A {
+int i;
+  };
+
+  void testPointerToMemberData() {
+int A::*AMdPointer = &A::i;
+A a;
+
+a.i = 42;
+a.*AMdPointer += 1;
+
+clang_analyzer_eval(a.i == 43); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberData namespace
+
+namespace testPointerToMemberMiscCasts {
+struct B {
+  int f;
+};
+
+struct D : public B {
+  int g;
+};
+
+void foo() {
+  D d;
+  d.f = 7;
+
+  int B::* pfb = &B::f;
+  int D::* pfd = pfb;
+  int v = d.*pfd;
+
+  clang_analyzer_eval(v == 7); // expected-warning{{TRUE}}
+}
+} // end of testPointerToMemberMiscCasts namespace
+
+namespace testPointerToMemberMiscCasts2 {
+struct B {
+  int f;
+};
+struct L : public B { };
+struct R : public B { };
+struct D : public L, R { };
+
+void foo() {
+  D d;
+
+  int B::* pb = &B::f;
+  int L::* pl = pb;
+  int R::* pr = pb;
+
+  int D::* pdl = pl;
+  int D::* pdr = pr;
+
+  clang_analyzer_eval(pdl == pdr); // expected-warning{{FALSE}}
+  clang_analyzer_eval(pb == pl); // expected-warning{{TRUE}}
 }
+} // end of testPointerToMemberMiscCasts2 namespace
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -69,6 +69,9 @@
 
   bool isLocType = Loc::isLocType(castTy);
 
+  if (val.getAs())
+return val;
+
   if (Optional LI = val.getAs()) {
 if (isLocType)
   return LI->getLoc();
@@ -335,6 +338,21 @@
 switch (lhs.getSubKind()) {
 default:
   return makeSymExprValNN(state, op, lhs, rhs, resultTy);
+case nonloc::PointerToMemberKind: {
+  assert(rhs.getSubKind() == nonloc::PointerToMemberKind &&
+ "Both SVals should have pointer-to-member-type");
+  auto LPTM = lhs.castAs(),
+   RPTM = rhs.castAs();
+  auto LPTMD = LPTM.getPTMData(), RPTMD = RPTM.getPTMData();
+  switch (op) {
+case BO_EQ:
+  r

[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

In https://reviews.llvm.org/D27138#607786, @joerg wrote:

> It's not the directory, but the output file. That's optional since it is a 
> new addition and I don't want to invalidate all existing JSON databases.


It seems like we're talking past each other. I'm not suggesting to invalidate 
all existing JSON databases. I'm suggesting:

1. if it doesn't exist, have nullptr in the struct
2. if it exists and is empty (""), have the empty string in the struct (and 
potentially give the user an error)
3. if it exists and is non-empty, all is good


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-11-29 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov marked an inline comment as done.
kromanenkov added inline comments.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:217
+
+  llvm::ImmutableList consCXXBase(
+  const CXXBaseSpecifier *CBS,

NoQ wrote:
> Hmm, is it "construct"? Or "constrain"? I think a verbose name wouldn't hurt.
> In fact, i suspect that `consVals` are rather `conSVals`, where `con` stands 
> for "concatenate".
In fact I thought that this entails "consume" :)



Comment at: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:882
+return UndefinedVal();
+  if (const FieldDecl *FD = PTMSV->getDeclAs())
+return state->getLValue(FD, lhs);

NoQ wrote:
> Hmm, do we need to cover `CXXMethodDecl` here? Or is it modeled as a function 
> pointer anyway, so no action is needed? Worth commenting, i think.
AFAIU CXXMethodDecl is processed in SVal::getAsFunctionDecl() so i'm for no 
action.


https://reviews.llvm.org/D25475



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


[PATCH] D26465: [Diag] Optimize DiagnosticIDs::getDiagnosticSeverity

2016-11-29 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart added a comment.

Ping 2


https://reviews.llvm.org/D26465



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


[libcxx] r288143 - [libcxx] remove unused code

2016-11-29 Thread Aditya Kumar via cfe-commits
Author: hiraditya
Date: Tue Nov 29 08:43:42 2016
New Revision: 288143

URL: http://llvm.org/viewvc/llvm-project?rev=288143&view=rev
Log:
[libcxx] remove unused code

The macro _LIBCPP_UNROLL_LOOPS isn't used anywhere
so the code was dead.

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

Modified:
libcxx/trunk/include/algorithm

Modified: libcxx/trunk/include/algorithm
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/algorithm?rev=288143&r1=288142&r2=288143&view=diff
==
--- libcxx/trunk/include/algorithm (original)
+++ libcxx/trunk/include/algorithm Tue Nov 29 08:43:42 2016
@@ -1494,9 +1494,9 @@ __search(_RandomAccessIterator1 __first1
 if (__len1 < __len2)
 return make_pair(__last1, __last1);
 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of 
pattern match can't go beyond here
+
 while (true)
 {
-#if !_LIBCPP_UNROLL_LOOPS
 while (true)
 {
 if (__first1 == __s)
@@ -1505,40 +1505,9 @@ __search(_RandomAccessIterator1 __first1
 break;
 ++__first1;
 }
-#else  // !_LIBCPP_UNROLL_LOOPS
-for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; 
--__loop_unroll)
-{
-if (__pred(*__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-++__first1;
-}
-switch (__s - __first1)
-{
-case 3:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 2:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 1:
-if (__pred(*__first1, *__first2))
-break;
-case 0:
-return make_pair(__last1, __last1);
-}
-__phase2:
-#endif  // !_LIBCPP_UNROLL_LOOPS
+
 _RandomAccessIterator1 __m1 = __first1;
 _RandomAccessIterator2 __m2 = __first2;
-#if !_LIBCPP_UNROLL_LOOPS
  while (true)
  {
  if (++__m2 == __last2)
@@ -1550,43 +1519,6 @@ __search(_RandomAccessIterator1 __first1
  break;
  }
  }
-#else  // !_LIBCPP_UNROLL_LOOPS
-++__m2;
-++__m1;
-for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; 
--__loop_unroll)
-{
-if (!__pred(*__m1, *__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-++__m1;
-++__m2;
-}
-switch (__last2 - __m2)
-{
-case 3:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 2:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 1:
-if (!__pred(*__m1, *__m2))
-break;
-case 0:
-return make_pair(__first1, __first1 + __len2);
-}
-__continue:
-++__first1;
-#endif  // !_LIBCPP_UNROLL_LOOPS
 }
 }
 


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


[PATCH] D26991: Remove unused code

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya retitled this revision from "Hoist redundant load" to "Remove unused 
code".
hiraditya updated this revision to Diff 79565.

https://reviews.llvm.org/D26991

Files:
  include/algorithm

Index: include/algorithm
===
--- include/algorithm
+++ include/algorithm
@@ -1494,51 +1494,20 @@
 if (__len1 < __len2)
 return make_pair(__last1, __last1);
 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
+
 while (true)
 {
-#if !_LIBCPP_UNROLL_LOOPS
 while (true)
 {
 if (__first1 == __s)
 return make_pair(__last1, __last1);
 if (__pred(*__first1, *__first2))
 break;
 ++__first1;
 }
-#else  // !_LIBCPP_UNROLL_LOOPS
-for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (__pred(*__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-++__first1;
-}
-switch (__s - __first1)
-{
-case 3:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 2:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 1:
-if (__pred(*__first1, *__first2))
-break;
-case 0:
-return make_pair(__last1, __last1);
-}
-__phase2:
-#endif  // !_LIBCPP_UNROLL_LOOPS
+
 _RandomAccessIterator1 __m1 = __first1;
 _RandomAccessIterator2 __m2 = __first2;
-#if !_LIBCPP_UNROLL_LOOPS
  while (true)
  {
  if (++__m2 == __last2)
@@ -1550,43 +1519,6 @@
  break;
  }
  }
-#else  // !_LIBCPP_UNROLL_LOOPS
-++__m2;
-++__m1;
-for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (!__pred(*__m1, *__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-++__m1;
-++__m2;
-}
-switch (__last2 - __m2)
-{
-case 3:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 2:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 1:
-if (!__pred(*__m1, *__m2))
-break;
-case 0:
-return make_pair(__first1, __first1 + __len2);
-}
-__continue:
-++__first1;
-#endif  // !_LIBCPP_UNROLL_LOOPS
 }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(&DeclRef),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

flx wrote:
> alexfh wrote:
> > How will this work with lambdas / local classes declared inside a loop? Not 
> > sure if this case is going to happen in real code, but we'd better be clear 
> > about the limitations of the implementation.
> Why would this not work? Could you give an example? The way the function is 
> written it handles my the use case for identifying when moving the parameter 
> is not safe, so I could also just move it into the UnnecessaryValueParamCheck.
I was thinking about a case where a loop this matcher finds is outside of the 
function definition and shouldn't be considered:

  void F() {
for (;;) {
  struct C {
void f(ExpensiveMovableType E) {
  auto F = E;
}
  };
}
  }



https://reviews.llvm.org/D27187



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


[PATCH] D26991: Remove unused code

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288143: [libcxx] remove unused code (authored by hiraditya).

Changed prior to commit:
  https://reviews.llvm.org/D26991?vs=79565&id=79566#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26991

Files:
  libcxx/trunk/include/algorithm

Index: libcxx/trunk/include/algorithm
===
--- libcxx/trunk/include/algorithm
+++ libcxx/trunk/include/algorithm
@@ -1494,51 +1494,20 @@
 if (__len1 < __len2)
 return make_pair(__last1, __last1);
 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1);  // Start of pattern match can't go beyond here
+
 while (true)
 {
-#if !_LIBCPP_UNROLL_LOOPS
 while (true)
 {
 if (__first1 == __s)
 return make_pair(__last1, __last1);
 if (__pred(*__first1, *__first2))
 break;
 ++__first1;
 }
-#else  // !_LIBCPP_UNROLL_LOOPS
-for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (__pred(*__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-if (__pred(*++__first1, *__first2))
-goto __phase2;
-++__first1;
-}
-switch (__s - __first1)
-{
-case 3:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 2:
-if (__pred(*__first1, *__first2))
-break;
-++__first1;
-case 1:
-if (__pred(*__first1, *__first2))
-break;
-case 0:
-return make_pair(__last1, __last1);
-}
-__phase2:
-#endif  // !_LIBCPP_UNROLL_LOOPS
+
 _RandomAccessIterator1 __m1 = __first1;
 _RandomAccessIterator2 __m2 = __first2;
-#if !_LIBCPP_UNROLL_LOOPS
  while (true)
  {
  if (++__m2 == __last2)
@@ -1550,43 +1519,6 @@
  break;
  }
  }
-#else  // !_LIBCPP_UNROLL_LOOPS
-++__m2;
-++__m1;
-for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll)
-{
-if (!__pred(*__m1, *__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-if (!__pred(*++__m1, *++__m2))
-goto __continue;
-++__m1;
-++__m2;
-}
-switch (__last2 - __m2)
-{
-case 3:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 2:
-if (!__pred(*__m1, *__m2))
-break;
-++__m1;
-++__m2;
-case 1:
-if (!__pred(*__m1, *__m2))
-break;
-case 0:
-return make_pair(__first1, __first1 + __len2);
-}
-__continue:
-++__first1;
-#endif  // !_LIBCPP_UNROLL_LOOPS
 }
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.



In https://reviews.llvm.org/D27163#607078, @rsmith wrote:

> A target-specific default for this, simply because there's a lot of code on 
> Darwin that happens to violate this language rule, doesn't make sense to me.
>
> Basing the behavior on whether a `-Wreturn-type` warning would have been 
> emitted seems like an extremely strange heuristic: only optimizing in the 
> cases where we provide the user no hint that we will do so seems incredibly 
> user-hostile.
>
> Regardless of anything else, it does not make any sense to "return" stack 
> garbage when the return type is a C++ class type, particularly one with a 
> non-trivial copy constructor or destructor. A trap at `-O0` is the kindest 
> thing we can do in that case.


Thanks, that makes sense. The updated patch avoids the trap and unreachable 
only for types that are trivially copyable and removes the Darwin specific code.

> In summary, I think it could be reasonable to have such a flag to disable the 
> trap/unreachable *only* for scalar types (or, at a push, trivially-copyable 
> types). But it seems unreasonable to have different defaults for Darwin, or 
> to look at whether a `-Wreturn-type` warning would have fired.

I understand that basing the optimisation avoidance on the analysis done for 
the `-Wreturn-type` warning might not be the best option, and a straightforward 
`-fno-strict-return` might be better as it doesn't use such hidden heuristics. 
However, AFAIK we only had problems with code that would've hit the 
`-Wreturn-type` warning, so it seemed like a good idea to keep the optimisation 
in functions where the analyser has determined that the flow with the no return 
is very unlikely (like in the `alwaysOptimizedReturn` function in the test 
case).  I kept it in this version of the patch, but if you think that the 
`-Wreturn-type` heuristic shouldn't be used I would be willing to remove it and 
go for the straightforward behaviour.

> Alternatively, since it seems you're only interested in the behavior of cases 
> where `-Wreturn-type` would have fired, how about using Clang's tooling 
> support to write a utility to add a return statement to the end of every 
> function where it would fire, and give that to your users to fix their code?

That's an interesting idea, but as John mentioned, some of the code that has 
these issues isn't written by Apple and it seems that it would be very 
difficult to convince code owners to run tooling and to fix such issues. But it 
still sounds like something that we should look into.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27138: Extend CompilationDatabase by a field for the output filename

2016-11-29 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

Which struct are we talking about, `CompileCommandRef` or `CompileCommand`? It 
is a pointer in the former and a plain StringRef in the latter. I don't think 
making it a pointer in both is an advantage, i.e. distinguishing empty input 
from missing field is not valuable in my opinion.


Repository:
  rL LLVM

https://reviews.llvm.org/D27138



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


[PATCH] D26465: [Diag] Optimize DiagnosticIDs::getDiagnosticSeverity

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Is there any way to test this change?

> This saves more than 5% of the parsing time according to perf.

That sounds great. What did you test the parsing on? Will this patch get 
similar improvements for code that compiles without errors and warnings?




Comment at: lib/Basic/DiagnosticIDs.cpp:423
+Mapping = &Pos->State->getOrAddMapping((diag::kind)DiagID);
+  }
 

I think it would be better if you wrap this piece of code in a static function 
that returns `DiagnosticMapping &`, as it should allow you to get rid of all 
these `.` to `->` changes below.


https://reviews.llvm.org/D26465



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


[clang-tools-extra] r288145 - [include-fixer] Don't eat one token too many when replacing a block of includes.

2016-11-29 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Tue Nov 29 09:15:26 2016
New Revision: 288145

URL: http://llvm.org/viewvc/llvm-project?rev=288145&view=rev
Log:
[include-fixer] Don't eat one token too many when replacing a block of includes.

SourceRanges are inclusive token ranges, this was trying to form an
exclusive char range.

Modified:
clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp

Modified: clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp?rev=288145&r1=288144&r2=288145&view=diff
==
--- clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp (original)
+++ clang-tools-extra/trunk/include-fixer/IncludeFixer.cpp Tue Nov 29 09:15:26 
2016
@@ -136,10 +136,10 @@ static void addDiagnosticsForContext(Typ
   const tooling::Replacement &Placed = *Reps->begin();
 
   auto Begin = StartOfFile.getLocWithOffset(Placed.getOffset());
-  auto End = Begin.getLocWithOffset(Placed.getLength());
+  auto End = Begin.getLocWithOffset(std::max(0, (int)Placed.getLength() - 1));
   PartialDiagnostic PD(DiagID, Ctx.getDiagAllocator());
   PD << Context.getHeaderInfos().front().Header
- << FixItHint::CreateReplacement(SourceRange(Begin, End),
+ << FixItHint::CreateReplacement(CharSourceRange::getCharRange(Begin, End),
  Placed.getReplacementText());
   Correction.addExtraDiagnostic(std::move(PD));
 }

Modified: clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp?rev=288145&r1=288144&r2=288145&view=diff
==
--- clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp (original)
+++ clang-tools-extra/trunk/test/include-fixer/yamldb_plugin.cpp Tue Nov 29 
09:15:26 2016
@@ -8,7 +8,8 @@ unknown u;
 // CHECK: FIX-IT: Replace [3:1 - 3:4] with "foo"
 // CHECK: yamldb_plugin.cpp:3:1: note: Add '#include "foo.h"' to provide the 
missing declaration [clang-include-fixer]
 // CHECK: Number FIX-ITs = 1
-// CHECK: FIX-IT: Replace [3:1 - 3:4] with "#include "foo.h"
+// CHECK: FIX-IT: Insert "#include "foo.h"
+// CHECK: " at 3:1
 // CHECK: yamldb_plugin.cpp:4:1:
 // CHECK: error: unknown type name 'unknown'
 // CHECK: Number FIX-ITs = 0


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


[PATCH] D27187: [clang-tidy] Do not move parameter if only DeclRefExpr occurs inside of a loop

2016-11-29 Thread Felix Berger via Phabricator via cfe-commits
flx added inline comments.



Comment at: clang-tidy/utils/DeclRefExprUtils.cpp:127
+  match(findAll(declRefExpr(equalsNode(&DeclRef),
+unless(hasAncestor(stmt(anyOf(
+forStmt(), cxxForRangeStmt(), whileStmt(),

alexfh wrote:
> flx wrote:
> > alexfh wrote:
> > > How will this work with lambdas / local classes declared inside a loop? 
> > > Not sure if this case is going to happen in real code, but we'd better be 
> > > clear about the limitations of the implementation.
> > Why would this not work? Could you give an example? The way the function is 
> > written it handles my the use case for identifying when moving the 
> > parameter is not safe, so I could also just move it into the 
> > UnnecessaryValueParamCheck.
> I was thinking about a case where a loop this matcher finds is outside of the 
> function definition and shouldn't be considered:
> 
>   void F() {
> for (;;) {
>   struct C {
> void f(ExpensiveMovableType E) {
>   auto F = E;
> }
>   };
> }
>   }
> 
This case is not an issue in the check as we're passing f's body statement to 
the hasLoopStmtAncestor function, so the search is scoped to f's body.

If you're concerned about the case where someone calls this with  F's body but 
expects it to be scoped to f I can just move this function into the check and 
make it an implementation detail.


https://reviews.llvm.org/D27187



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

I think you could add fixits for this.




Comment at: clang-tidy/misc/MiscStringCompareCheck.cpp:48
+  Finder->addMatcher(ifStmt(hasCondition(binaryOperator(hasOperatorName("=="),
+hasLHS(strCompare
+ .bind("match"),

Doesn't test RHS.



Comment at: clang-tidy/misc/MiscStringCompareCheck.cpp:54
+  Finder->addMatcher(ifStmt(hasCondition(binaryOperator(hasOperatorName("!="),
+hasLHS(strCompare
+ .bind("match"),

Doesn't test RHS.
Could be combined with the previous case.



Comment at: clang-tidy/misc/MiscStringCompareCheck.h:24
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/misc-string-compare-check.html
+class MiscStringCompareCheck : public ClangTidyCheck {
+public:

Remove `Misc`.

Did you use add_new_check.py to add this check?



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:4
+misc-string-compare
+===
+

Too many `=`.


Repository:
  rL LLVM

https://reviews.llvm.org/D27210



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


[PATCH] D27214: [ObjC] Encode type arguments in property information string constants

2016-11-29 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: rjmccall, ahatanak.
arphaman added a subscriber: cfe-commits.
arphaman set the repository for this revision to rL LLVM.

This patch ensures that Objective-C type arguments are included in the string 
constants that have encoded information about `@property` declarations.


Repository:
  rL LLVM

https://reviews.llvm.org/D27214

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenObjC/objc2-property-encode.m


Index: test/CodeGenObjC/objc2-property-encode.m
===
--- test/CodeGenObjC/objc2-property-encode.m
+++ test/CodeGenObjC/objc2-property-encode.m
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm -o %t %s
 // RUN: grep -e "T@22NSString22" %t
+// RUN: FileCheck %s -input-file=%t
 @interface NSString @end
 
 typedef NSString StoreVersionID ;
@@ -11,3 +12,30 @@
 @implementation Parent
 @dynamic foo;
 @end
+
+// rdar://22496485
+@interface TypeParameters<__covariant ObjectType>
+
+@end
+
+@interface TypeParameters2<__covariant A, __covariant B>
+
+@end
+
+@protocol MyProtocol;
+@class MyClass;
+
+@interface Bar
+
+@property(copy) TypeParameters *p1;
+
+@property(copy) TypeParameters2 *p2;
+
+@end
+
+@implementation Bar
+
+@end
+
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} 
c"T@\22TypeParameters<@\22MyClass\22>\22,C,V_p1\00"
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} 
c"T@\22TypeParameters2<@\22MyClass\22,@\22MyClass\22>\22,C,V_p2\00"
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -34,6 +34,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Capacity.h"
@@ -6275,6 +6276,18 @@
 (FD || EncodingProperty || EncodeClassNames)) {
   S += '"';
   S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString();
+  ArrayRef TypeArgs = OPT->getTypeArgs();
+  if (!TypeArgs.empty()) {
+S += '<';
+for (const auto &I : llvm::enumerate(TypeArgs)) {
+  if (I.Index)
+S += ',';
+  getObjCEncodingForTypeImpl(I.Value, S, ExpandPointedToStructures,
+ ExpandStructures, nullptr, false,
+ EncodingProperty);
+}
+S += '>';
+  }
   for (const auto *I : OPT->quals()) {
 S += '<';
 S += I->getObjCRuntimeNameAsString();


Index: test/CodeGenObjC/objc2-property-encode.m
===
--- test/CodeGenObjC/objc2-property-encode.m
+++ test/CodeGenObjC/objc2-property-encode.m
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple=i686-apple-darwin9 -emit-llvm -o %t %s
 // RUN: grep -e "T@22NSString22" %t
+// RUN: FileCheck %s -input-file=%t
 @interface NSString @end
 
 typedef NSString StoreVersionID ;
@@ -11,3 +12,30 @@
 @implementation Parent
 @dynamic foo;
 @end
+
+// rdar://22496485
+@interface TypeParameters<__covariant ObjectType>
+
+@end
+
+@interface TypeParameters2<__covariant A, __covariant B>
+
+@end
+
+@protocol MyProtocol;
+@class MyClass;
+
+@interface Bar
+
+@property(copy) TypeParameters *p1;
+
+@property(copy) TypeParameters2 *p2;
+
+@end
+
+@implementation Bar
+
+@end
+
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} c"T@\22TypeParameters<@\22MyClass\22>\22,C,V_p1\00"
+// CHECK: @OBJC_PROP_NAME_ATTR_{{.*}} = {{.*}} c"T@\22TypeParameters2<@\22MyClass\22,@\22MyClass\22>\22,C,V_p2\00"
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -34,6 +34,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Support/Capacity.h"
@@ -6275,6 +6276,18 @@
 (FD || EncodingProperty || EncodeClassNames)) {
   S += '"';
   S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString();
+  ArrayRef TypeArgs = OPT->getTypeArgs();
+  if (!TypeArgs.empty()) {
+S += '<';
+for (const auto &I : llvm::enumerate(TypeArgs)) {
+  if (I.Index)
+S += ',';
+  getObjCEncodingForTypeImpl(I.Value, S, ExpandPointedToStructures,
+ ExpandStructures, nullptr, false,
+ EncodingProperty);
+}
+S += '>';
+  }
   for (const auto *I : OPT->quals()) {
 S += '<';
 S += I->getObjCRuntimeNameAsString();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26611: Protect test for dynarray under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288155: Protect test for dynarray under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26611?vs=77809&id=79580#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26611

Files:
  
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp


Index: 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
===
--- 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
+++ 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@
 assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ 
return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) 
+ 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return 
item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }


Index: libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
===
--- libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
+++ libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@
 assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) + 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r288155 - Protect test for dynarray under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:27:45 2016
New Revision: 288155

URL: http://llvm.org/viewvc/llvm-project?rev=288155&view=rev
Log:
Protect test for dynarray under libcpp-no-exceptions

This test expects an exception be thrown.

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


Modified:

libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp

Modified: 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp?rev=288155&r1=288154&r2=288155&view=diff
==
--- 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
 (original)
+++ 
libcxx/trunk/test/libcxx/experimental/containers/sequences/dynarray/dynarray.cons/default.pass.cpp
 Tue Nov 29 10:27:45 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // UNSUPPORTED: c++98, c++03, c++11
 
 // dynarray.cons
@@ -29,6 +28,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 
 using std::experimental::dynarray;
 
@@ -61,12 +62,14 @@ void test ( const T &val, bool DefaultVa
 assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ 
return item == val; } ));
 }
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 void test_bad_length () {
 try { dynarray ( std::numeric_limits::max() / sizeof ( int ) 
+ 1 ); }
 catch ( std::bad_array_length & ) { return ; }
 catch (...) { assert(false); }
 assert ( false );
 }
+#endif
 
 
 int main()
@@ -87,5 +90,7 @@ int main()
 assert ( d1.size() == 20 );
 assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return 
item == 3L; } ));
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 test_bad_length ();
+#endif
 }


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


[libcxx] r288157 - Protect std::{, unordered_}map tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:37:48 2016
New Revision: 288157

URL: http://llvm.org/viewvc/llvm-project?rev=288157&view=rev
Log:
Protect std::{,unordered_}map tests under noexceptions

Skip tests that use exceptions

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


Modified:
libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp

Modified: 
libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp?rev=288157&r1=288156&r2=288157&view=diff
==
--- libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp Tue 
Nov 29 10:37:48 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // class map
@@ -19,6 +18,7 @@
 #include 
 
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -43,6 +43,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -51,6 +52,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -74,6 +76,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -82,6 +85,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -108,6 +112,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -116,6 +121,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -139,6 +145,7 @@ int main()
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
@@ -147,6 +154,7 @@ int main()
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);

Modified: 
libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp?rev=288157&r1=288156&r2=288157&view=diff
==
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp 
(original)
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp 
Tue Nov 29 10:37:48 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template , class Pred = 
equal_to,
@@ -23,6 +22,7 @@
 
 #include "MoveOnly.h"
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -42,6 +42,7 @@ int main()
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -51,6 +52,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map C;
@@ -67,6 +69,7 @@ int main()
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -76,6 +79,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 #if TEST_STD_VER >= 11
 {
@@ -95,6 +99,7 @@ int main()
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -104,6 +109,7 @@ int main()
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map, 
std::equal_to,
@@ -121,6 +127,7 @@ int main()
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -130,6 +137,7 @@ int main()
 {
  

[PATCH] D27093: Protect std::{, unordered_}map tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288157: Protect std::{,unordered_}map tests under 
noexceptions (authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27093?vs=79212&id=79582#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27093

Files:
  libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
  libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp

Index: libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
+++ libcxx/trunk/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template , class Pred = equal_to,
@@ -23,6 +22,7 @@
 
 #include "MoveOnly.h"
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -42,6 +42,7 @@
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -51,6 +52,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map C;
@@ -67,6 +69,7 @@
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -76,6 +79,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 #if TEST_STD_VER >= 11
 {
@@ -95,6 +99,7 @@
 assert(c.size() == 4);
 c.at(1) = "ONE";
 assert(c.at(1) == "ONE");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11) = "eleven";
@@ -104,6 +109,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 {
 typedef std::unordered_map, std::equal_to,
@@ -121,6 +127,7 @@
 const C c(a, a + sizeof(a)/sizeof(a[0]));
 assert(c.size() == 4);
 assert(c.at(1) == "one");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 c.at(11);
@@ -130,6 +137,7 @@
 {
 }
 assert(c.size() == 4);
+#endif
 }
 #endif
 }
Index: libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
+++ libcxx/trunk/test/std/containers/associative/map/map.access/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // class map
@@ -19,6 +18,7 @@
 #include 
 
 #include "min_allocator.h"
+#include "test_macros.h"
 
 int main()
 {
@@ -43,14 +43,16 @@
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
 assert(false);
 }
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -74,14 +76,16 @@
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
 assert(false);
 }
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -108,14 +112,16 @@
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
 assert(false);
 }
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
@@ -139,14 +145,16 @@
 assert(m.at(3) == 3.5);
 assert(m.at(4) == 4.5);
 assert(m.at(5) == 5.5);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 m.at(6);
 assert(false);
 }
 catch (std::out_of_range&)
 {
 }
+#endif
 assert(m.at(7) == 7.5);
 assert(m.at(8) == 8.5);
 assert(m.size() == 7);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r288156 - Protect locale tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:31:40 2016
New Revision: 288156

URL: http://llvm.org/viewvc/llvm-project?rev=288156&view=rev
Log:
Protect locale tests under noexceptions

Skip tests that expect exceptions be thrown.

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


Modified:

libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp

libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp

libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp

libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp

Modified: 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp?rev=288156&r1=288155&r2=288156&view=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // wstring_convert
@@ -29,6 +28,7 @@ int main()
 static_assert(!std::is_convertible::value, "");
 static_assert( std::is_constructible::value, "");
 #endif
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 Myconv myconv;
 try
@@ -48,10 +48,12 @@ int main()
 {
 }
 }
+#endif
 {
 Myconv myconv("byte error");
 std::string bs = myconv.to_bytes(L"\xDA83");
 assert(bs == "byte error");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 myconv.from_bytes('\xA5');
@@ -60,6 +62,7 @@ int main()
 catch (const std::range_error&)
 {
 }
+#endif
 }
 {
 Myconv myconv("byte error", L"wide error");

Modified: 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp?rev=288156&r1=288155&r2=288156&view=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  const Facet& use_facet(const locale& loc);
@@ -15,6 +14,8 @@
 #include 
 #include 
 
+#include "test_macros.h"
+
 int facet_count = 0;
 
 struct my_facet
@@ -32,6 +33,7 @@ std::locale::id my_facet::id;
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 const my_facet& f = std::use_facet(std::locale());
@@ -41,6 +43,7 @@ int main()
 catch (std::bad_cast&)
 {
 }
+#endif
 const my_facet* fp = 0;
 {
 std::locale loc(std::locale(), new my_facet);

Modified: 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp?rev=288156&r1=288155&r2=288156&view=diff
==
--- 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
 Tue Nov 29 10:31:40 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // REQUIRES: locale.ru_RU.UTF-8
 // REQUIRES: locale.zh_CN.UTF-8
 
@@ -22,6 +21,8 @@
 #include "count_new.hpp"
 #include "platform_support.h" // locale name macros
 
+#include "test_macros.h"
+
 
 void check(const std::locale& loc)
 {
@@ -70,6 +71,7 @@ int main()
 check(loc3);
 assert(!(loc == loc3));
 assert(loc != loc3);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::locale((const char*)0);
@@ -86,6 +88,7 @@ int main()
 catch (std::runtime_error&)
 {
 }
+#endif
 std::locale ok("");
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));

Modified: 
libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp?rev

[PATCH] D27096: Protect locale tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288156: Protect locale tests under noexceptions (authored by 
rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27096?vs=79219&id=79581#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27096

Files:
  
libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
  
libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp

Index: libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale/locale.members/combine.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  locale combine(const locale& other) const;
@@ -18,6 +17,8 @@
 
 #include "count_new.hpp"
 
+#include "test_macros.h"
+
 void check(const std::locale& loc)
 {
 assert(std::has_facet >(loc));
@@ -78,6 +79,7 @@
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 {
 std::locale loc;
@@ -93,4 +95,5 @@
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
 }
+#endif
 }
Index: libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // REQUIRES: locale.ru_RU.UTF-8
 // REQUIRES: locale.zh_CN.UTF-8
 
@@ -22,6 +21,8 @@
 #include "count_new.hpp"
 #include "platform_support.h" // locale name macros
 
+#include "test_macros.h"
+
 
 void check(const std::locale& loc)
 {
@@ -70,6 +71,7 @@
 check(loc3);
 assert(!(loc == loc3));
 assert(loc != loc3);
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 std::locale((const char*)0);
@@ -86,6 +88,7 @@
 catch (std::runtime_error&)
 {
 }
+#endif
 std::locale ok("");
 }
 assert(globalMemCounter.checkOutstandingNewEq(0));
Index: libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale.global.templates/use_facet.pass.cpp
@@ -7,14 +7,15 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // template  const Facet& use_facet(const locale& loc);
 
 #include 
 #include 
 
+#include "test_macros.h"
+
 int facet_count = 0;
 
 struct my_facet
@@ -32,6 +33,7 @@
 
 int main()
 {
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 const my_facet& f = std::use_facet(std::locale());
@@ -41,6 +43,7 @@
 catch (std::bad_cast&)
 {
 }
+#endif
 const my_facet* fp = 0;
 {
 std::locale loc(std::locale(), new my_facet);
Index: libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
===
--- libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
+++ libcxx/trunk/test/std/localization/locales/locale.convenience/conversions/conversions.string/ctor_err_string.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // wstring_convert
@@ -29,6 +28,7 @@
 static_assert(!std::is_convertible::value, "");
 static_assert( std::is_constructible::value, "");
 #endif
+#ifndef TEST_HAS_NO_EXCEPTIONS
 {
 Myconv myconv;
 try
@@ -48,18 +48,21 @@
 {
 }
 }
+#endif
 {
 Myconv myconv("byte error");
 std::string bs = myconv.to_bytes(L"\xDA83");
 assert(bs == "byte error");
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
 {
 myconv.from_bytes('\xA5');
 assert(false);
 }
 catch (const std::range_error&)
 {
 }
+#endif
 }
 {
 Myconv myconv("byte error", L"wide error");
___
cfe-commits mailing list
cfe

[libcxx] r288158 - Protect std::string tests under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 10:40:19 2016
New Revision: 288158

URL: http://llvm.org/viewvc/llvm-project?rev=288158&view=rev
Log:
Protect std::string tests under libcpp-no-exceptions

Skip tests that expect an exception be thrown and/or disable
unreachable catch handlers.

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


Modified:
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp

libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp?rev=288158&r1=288157&r2=288158&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp 
Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type());
 assert(s.size() == s.capacity());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 S::allocator_type::throw_after = INT_MAX;
 }
 

Modified: 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp?rev=288158&r1=288157&r2=288158&view=diff
==
--- 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
 Tue Nov 29 10:40:19 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,7 +23,7 @@ template 
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
@@ -33,10 +32,20 @@ test(const S& s, typename S::size_type p
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()


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


[PATCH] D26612: Protect std::string tests under libcpp-no-exceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288158: Protect std::string tests under libcpp-no-exceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D26612?vs=78012&id=79583#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D26612

Files:
  libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
  
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp


Index: 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
===
--- 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
+++ 
libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,19 +23,29 @@
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
 assert(pos <= s.size());
 typename S::size_type rlen = std::min(n, s.size() - pos);
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()
Index: 
libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type());
 assert(s.size() == s.capacity());
 }
+#ifndef TEST_HAS_NO_EXCEPTIONS
 catch (...)
 {
 assert(false);
 }
+#endif
 S::allocator_type::throw_after = INT_MAX;
 }
 


Index: libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.ops/string_substr/substr.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // basic_string substr(size_type pos = 0, size_type n = npos) const;
@@ -24,19 +23,29 @@
 void
 test(const S& s, typename S::size_type pos, typename S::size_type n)
 {
-try
+if (pos <= s.size())
 {
 S str = s.substr(pos, n);
 LIBCPP_ASSERT(str.__invariants());
 assert(pos <= s.size());
 typename S::size_type rlen = std::min(n, s.size() - pos);
 assert(str.size() == rlen);
 assert(S::traits_type::compare(s.data()+pos, str.data(), rlen) == 0);
 }
-catch (std::out_of_range&)
+#ifndef TEST_HAS_NO_EXCEPTIONS
+else
 {
-assert(pos > s.size());
+try
+{
+S str = s.substr(pos, n);
+assert(false);
+}
+catch (std::out_of_range&)
+{
+assert(pos > s.size());
+}
 }
+#endif
 }
 
 int main()
Index: libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
===
--- libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
+++ libcxx/trunk/test/std/strings/basic.string/string.capacity/capacity.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // size_type capacity() const;
@@ -18,21 +17,27 @@
 #include "test_allocator.h"
 #include "min_allocator.h"
 
+#include "test_macros.h"
+
 template 
 void
 test(S s)
 {
 S::allocator_type::throw_after = 0;
+#ifndef TEST_HAS_NO_EXCEPTIONS
 try
+#endif
 {
 while (s.size() < s.capacity())
 s.push_back(typename S::value_type()

[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

That's excellent. Thank you for this work, Sean!




Comment at: tools/clang-import-test/CMakeLists.txt:19
+  )
\ No newline at end of file


Please add a newline here.



Comment at: tools/clang-import-test/clang-import-test.cpp:106
+
+const char *LineEnd = nullptr;
+

How about something like this:
```
StringRef Remain(LineBegin, Buffer->getBufferEnd() - LineBegin);
size_t EndPos = Remain.find_first_of("\r\n");
StringRef Line = (EndPos == StringRef::npos) ? Remain : StringRef(LineBegin, 
EndPos);
llvm::errs() << Line << "\n";
llvm::errs().indent(LocColumn) << "^\n";
```
?



Comment at: tools/clang-import-test/clang-import-test.cpp:115
+
+fprintf(stderr, "%s\n", LineString.c_str());
+std::string Space(LocColumn, ' ');

Why do we use `fprintf` instead of `llvm::errs()`?



Comment at: tools/clang-import-test/clang-import-test.cpp:130
+
+  SmallVector DiagText;
+  Info.FormatDiagnostic(DiagText);

SmallString? So, you will not need to push_back.



Comment at: tools/clang-import-test/clang-import-test.cpp:143
+if (!Invalid) {
+  llvm::errs() << Ref.str().c_str() << '\n';
+}

No need in `c_str()` here.



Comment at: tools/clang-import-test/clang-import-test.cpp:152
+class TestExternalASTSource : public ExternalASTSource {
+private:  llvm::ArrayRef ImportCIs;
+  std::map> ForwardImporters;

Please add a newline here.



Comment at: tools/clang-import-test/clang-import-test.cpp:162
+  const bool MinimalImport = true;
+  ForwardImporters.emplace(std::make_pair(
+  ImportCI,

`ForwardImporters[ImportCI] = ...llvm::make_unique<>`?



Comment at: tools/clang-import-test/clang-import-test.cpp:179
+  DeclarationName Name) override {
+std::vector Decls;
+

SmallVector?



Comment at: tools/clang-import-test/clang-import-test.cpp:181
+
+if (llvm::isa(DC)) {
+  for (CompilerInstance *I : ImportCIs) {

In LLVM code, qualifiers for llvm-style casts are not commonly used.



Comment at: tools/clang-import-test/clang-import-test.cpp:222
+   SmallVectorImpl &Result) override {
+
+  }

Extra spaces.



Comment at: tools/clang-import-test/clang-import-test.cpp:236
+  std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
+ [](std::string &s) -> const char * { return s.data(); });
+

`[](const std::string &s)`



Comment at: tools/clang-import-test/clang-import-test.cpp:238
+
+  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
+ &ClangArgv.data()[ClangArgv.size()],

`ClangArgv.begin(), ClangArgv.end()`



Comment at: tools/clang-import-test/clang-import-test.cpp:327
+}
+}
+

// end namespace


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2016-11-29 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Thank you Kareem, It looks mostly good, but I'd like to have some functional 
tests in ASTMerge for this patch.




Comment at: lib/AST/ASTImporter.cpp:4299
+  if (ImportDeclParts(D, DC, LexicalDC, Name, AlreadyImported, Loc))
+return NULL;
+  assert(DC && "Null DeclContext after importing decl parts");

nullptr



Comment at: lib/AST/ASTImporter.cpp:4323
+  for (UsingShadowDecl *I : D->shadows()) {
+UsingShadowDecl *SD = cast(Importer.Import(I));
+ToD->addShadowDecl(SD);

This will assert if import fails. We need to use `cast_or_null` and check for 
null returns. (If this is the result of my misleading code, sorry for this.)



Comment at: lib/AST/ASTImporter.cpp:4335
+  if (ImportDeclParts(D, DC, LexicalDC, Name, AlreadyImported, Loc))
+return NULL;
+  assert(DC && "Null DeclContext after importing decl parts");

nullptr



Comment at: lib/AST/ASTImporter.cpp:4342
+Importer.getToContext(), DC, Loc,
+cast(Importer.Import(D->getUsingDecl())),
+cast_or_null(Importer.Import(D->getTargetDecl(;

This will assert if import fails. We need to use cast_or_null and check for 
null returns.


https://reviews.llvm.org/D27181



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


r288163 - [OpenCL] Prevent generation of globals in non-constant AS for OpenCL.

2016-11-29 Thread Anastasia Stulova via cfe-commits
Author: stulova
Date: Tue Nov 29 11:01:19 2016
New Revision: 288163

URL: http://llvm.org/viewvc/llvm-project?rev=288163&view=rev
Log:
[OpenCL] Prevent generation of globals in non-constant AS for OpenCL.

Avoid using shortcut for const qualified non-constant address space
aggregate variables while generating them on the stack such that
the alloca object is used instead of a global variable containing
initializer.

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


Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=288163&r1=288162&r2=288163&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Nov 29 11:01:19 2016
@@ -948,8 +948,12 @@ CodeGenFunction::EmitAutoVarAlloca(const
   // If the variable's a const type, and it's neither an NRVO
   // candidate nor a __block variable and has no mutable members,
   // emit it as a global instead.
-  if (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef &&
-  CGM.isTypeConstant(Ty, true)) {
+  // Exception is if a variable is located in non-constant address space
+  // in OpenCL.
+  if ((!getLangOpts().OpenCL ||
+   Ty.getAddressSpace() == LangAS::opencl_constant) &&
+  (CGM.getCodeGenOpts().MergeAllConstants && !NRVO && !isByRef &&
+   CGM.isTypeConstant(Ty, true))) {
 EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage);
 
 // Signal this condition to later callbacks.

Modified: cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl?rev=288163&r1=288162&r2=288163&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/constant-addr-space-globals.cl Tue Nov 29 
11:01:19 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -cl-opt-disable -ffake-address-space-map -emit-llvm -o - 
| FileCheck %s
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -cl-opt-disable 
-ffake-address-space-map -emit-llvm -o - | FileCheck %s
 
 // CHECK: @array = addrspace({{[0-9]+}}) constant
 __constant float array[2] = {0.0f, 1.0f};
@@ -6,3 +6,22 @@ __constant float array[2] = {0.0f, 1.0f}
 kernel void test(global float *out) {
   *out = array[0];
 }
+
+// Test that we don't use directly initializers for const aggregates
+// but create a copy in the original address space (unless a variable itself is
+// in the constant address space).
+
+void foo(constant const int *p1, const int *p2, const int *p3);
+// CHECK: @k.arr1 = internal addrspace(3) constant [3 x i32] [i32 1, i32 2, 
i32 3]
+// CHECK: @k.arr2 = private unnamed_addr addrspace(3) constant [3 x i32] [i32 
4, i32 5, i32 6]
+// CHECK: @k.arr3 = private unnamed_addr addrspace(3) constant [3 x i32] [i32 
7, i32 8, i32 9]
+kernel void k(void) {
+  // CHECK-NOT: %arr1 = alloca [3 x i32]
+  constant const int arr1[] = {1, 2, 3};
+  // CHECK: %arr2 = alloca [3 x i32]
+  const int arr2[] = {4, 5, 6};
+  // CHECK: %arr3 = alloca [3 x i32]
+  int arr3[] = {7, 8, 9};
+
+  foo(arr1, arr2, arr3);
+}


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


[PATCH] D27095: Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
rogfer01 updated this revision to Diff 79589.
rogfer01 added a comment.

Add missing assertions in the original test.


https://reviews.llvm.org/D27095

Files:
  test/std/containers/sequences/array/at.pass.cpp


Index: test/std/containers/sequences/array/at.pass.cpp
===
--- test/std/containers/sequences/array/at.pass.cpp
+++ test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


Index: test/std/containers/sequences/array/at.pass.cpp
===
--- test/std/containers/sequences/array/at.pass.cpp
+++ test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26960: [docs] Use x86_64 and i386 instead of x86 as arch for triples.

2016-11-29 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

Ping. This is a two-line documentation fix, but I want to make sure x86_64 and 
i386 are valid for arch in target triples in all cases.


https://reviews.llvm.org/D26960



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


[PATCH] D27095: Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL288165: Protect std::array tests under noexceptions 
(authored by rogfer01).

Changed prior to commit:
  https://reviews.llvm.org/D27095?vs=79589&id=79591#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27095

Files:
  libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp


Index: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


Index: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
===
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
@@ -7,7 +7,6 @@
 //
 //===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r288165 - Protect std::array tests under noexceptions

2016-11-29 Thread Roger Ferrer Ibanez via cfe-commits
Author: rogfer01
Date: Tue Nov 29 11:10:29 2016
New Revision: 288165

URL: http://llvm.org/viewvc/llvm-project?rev=288165&view=rev
Log:
Protect std::array tests under noexceptions

Skip tests that expect exceptions be thrown. Also add missing asserts.

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


Modified:
libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp

Modified: libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp?rev=288165&r1=288164&r2=288165&view=diff
==
--- libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp (original)
+++ libcxx/trunk/test/std/containers/sequences/array/at.pass.cpp Tue Nov 29 
11:10:29 2016
@@ -7,7 +7,6 @@
 //
 
//===--===//
 
-// XFAIL: libcpp-no-exceptions
 // 
 
 // reference operator[] (size_type)
@@ -40,8 +39,14 @@ int main()
 r2 = 7.5;
 assert(c.back() == 7.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 {
 typedef double T;
@@ -53,8 +58,14 @@ int main()
 C::const_reference r2 = c.at(2);
 assert(r2 == 3.5);
 
-try { (void) c.at(3); }
+#ifndef TEST_HAS_NO_EXCEPTIONS
+try
+{
+(void) c.at(3);
+assert(false);
+}
 catch (const std::out_of_range &) {}
+#endif
 }
 
 #if TEST_STD_VER > 11


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


Re: Embedded Bitcode in Object Files

2016-11-29 Thread Nico Weber via cfe-commits
It looks like patches 1 and  2 made it but 3 and 4 didn't. Do you no longer
need them?

On Mon, Feb 29, 2016 at 2:08 PM, Steven Wu via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Ping. I don't know who is the best review for the patches. Thanks for
> Rafael looking at the LLVM change. Richard, do you have any opinions on the
> clang changes?
>
> Thanks
>
> Steven
>
> > On Feb 18, 2016, at 9:57 AM, Steven Wu  wrote:
> >
> > Hi all
> >
> > I put up some patches for embedding bitcode inside the object file
> (-fembed-bitcode) option. As I described in the dev list before, the new
> option can create normal object file with bitcode embedded in a special
> section. You can easily recreate the same object file with the embedded
> bitcode in it.
> >
> > I split the patch into several parts:
> > llvm patch:
> > http://reviews.llvm.org/D17388: Introduce the section for embedding
> bitcode in MachO file.
> >
> > There are four clang patches:
> > http://reviews.llvm.org/D17390: Implementing the clang driver for the
> new option.
> > http://reviews.llvm.org/D17392: Teach clang how to embed bitcode into
> the object file.
> > http://reviews.llvm.org/D17393: Slightly tweak the bitcode emitted in
> embed bitcode stage 1.
> > http://reviews.llvm.org/D17394: Reduce the amount of option gets
> embedded in the bitcode by introducing a whitelist and a blacklist.
> >
> > Let me know if anyone is interested in helping reviewing these changes.
> >
> > Thanks
> >
> > Steven
> >
> >
> >
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26991: Remove unused code

2016-11-29 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya added inline comments.



Comment at: libcxx/include/algorithm:1499
+// Load the first element from __first2 outside the loop because it is 
loop invariant
+typename iterator_traits<_RandomAccessIterator1>::value_type 
__firstElement2 = *__first2;
+

hiraditya wrote:
> mclow.lists wrote:
> > I just realized that we can't do this.
> > This imposes a requirement that the `value_type` be copy-constructible.
> > 
> > With this in place, we can't search a sequence of move-only types.
> Ok, I'll remove this change while pushing. I'll change the subject as well, 
> because now this patch is just removing the unused code.
> Thanks for the review.
Are we allowed to call __search on a type which is not copy-constructible?


Repository:
  rL LLVM

https://reviews.llvm.org/D26991



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


[PATCH] D27181: [ASTImporter] Support for importing UsingDecl and UsingShadowDecl

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

Looks good, but I have a concern about the underlying branch's apparently 
inconsistent initialization of `DeclarationNameInfo`.  Aleksei, could you 
clarify how that code works?  Should we have a helper function so we don't have 
to carefully repeat this pattern everywhere?




Comment at: lib/AST/ASTImporter.cpp:4305
+  DeclarationNameInfo NameInfo(Name, 
Importer.Import(D->getNameInfo().getLoc()));
+  ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
+

I've seen this pattern before, in [[ https://reviews.llvm.org/D27033 | D20733 
]], at ASTImporter.cpp:6488:
```
  DeclarationNameInfo NameInfo(E->getName(), E->getNameLoc());
  ImportDeclarationNameLoc(E->getNameInfo(), NameInfo);
```
That code didn't do the `Import` during the initialization of the 
`DeclarationNameInfo`.  Is either of these incorrect?


https://reviews.llvm.org/D27181



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


[PATCH] D27033: [ASTImporter] Support importing UnresolvedLookupExpr nodes

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

Marked the place I was talking about in D27181 




Comment at: lib/AST/ASTImporter.cpp:6489
+  DeclarationNameInfo NameInfo(E->getName(), E->getNameLoc());
+  ImportDeclarationNameLoc(E->getNameInfo(), NameInfo);
+

Commented in [[ https://reviews.llvm.org/D27181 | D27181 ]] that usage of 
`ImportDeclarationNameLoc` look different in different places.


https://reviews.llvm.org/D27033



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


[PATCH] D26916: [ObjC] Avoid a @try/@finally/@autoreleasepool fixit when parsing an expression

2016-11-29 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

Thanks for the explanation, LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D26916



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe added a comment.

In https://reviews.llvm.org/D27180#607433, @hfinkel wrote:

> This seems like a great idea. btw, do you know about Cling 
> (https://root.cern.ch/cling)?


Hal, thank you for your interest!  Yes, Cling is what I was referring to when I 
mentioned the ROOT project.  Vassil Vassilev, the developer of Cling, is also 
on the reviewer list.  I had the pleasure of talking to Vassil a few years ago 
at a LLVM Developer Meeting and the idea of creating common infrastructure 
between LLDB and Cling has been rolling around in the back of my head since 
then.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D21695: [clang] Version support for UBSan handlers

2016-11-29 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added a comment.

Ping!


https://reviews.llvm.org/D21695



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


[clang-tools-extra] r288175 - Fix some Clang-tidy modernize-use-default and Include What You Use warnings; other minor fixes (NFC).

2016-11-29 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Tue Nov 29 12:24:01 2016
New Revision: 288175

URL: http://llvm.org/viewvc/llvm-project?rev=288175&view=rev
Log:
Fix some Clang-tidy modernize-use-default and Include What You Use warnings; 
other minor fixes (NFC).

This preparation to remove SetVector.h dependency on SmallSet.h.

Modified:
clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
clang-tools-extra/trunk/pp-trace/PPCallbacksTracker.h

Modified: clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=288175&r1=288174&r2=288175&view=diff
==
--- clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp (original)
+++ clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp Tue Nov 29 12:24:01 
2016
@@ -18,10 +18,16 @@
 #include "USRFinder.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceLocation.h"
-#include "clang/Index/USRGeneration.h"
+#include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Lexer.h"
-#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
+#include 
 
 using namespace llvm;
 
@@ -29,6 +35,7 @@ namespace clang {
 namespace rename {
 
 namespace {
+
 // \brief This visitor recursively searches for all instances of a USR in a
 // translation unit and stores them for later usage.
 class USRLocFindingASTVisitor
@@ -140,6 +147,7 @@ private:
   std::vector LocationsFound;
   const ASTContext &Context;
 };
+
 } // namespace
 
 std::vector

Modified: clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp?rev=288175&r1=288174&r2=288175&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/AvoidBindCheck.cpp Tue Nov 29 
12:24:01 2016
@@ -1,4 +1,4 @@
-//===--- AvoidBindCheck.cpp - clang-tidy===//
+//===--- AvoidBindCheck.cpp - 
clang-tidy---===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,12 +6,25 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
+
 #include "AvoidBindCheck.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/Lexer.h"
-#include 
-#include 
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Casting.h"
+#include "llvm/Support/Regex.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+#include 
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -20,6 +33,7 @@ namespace tidy {
 namespace modernize {
 
 namespace {
+
 enum BindArgumentKind { BK_Temporary, BK_Placeholder, BK_CallExpr, BK_Other };
 
 struct BindArgument {

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp?rev=288175&r1=288174&r2=288175&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertCheck.cpp Tue Nov 
29 12:24:01 2016
@@ -8,11 +8,21 @@
 
//===--===//
 
 #include "LoopConvertCheck.h"
-#include "../utils/Matchers.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h" 
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/Casting.h"
+#include 
+#include 
+#include 
 
-using namespace clang;
 using namespace clang::ast_matchers;
 using namespace llvm;
 

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConve

Re: Upgrade and fix clang-format-vs

2016-11-29 Thread Hans Wennborg via cfe-commits
Very nice! I've tried this out and confirmed that the built plugin
also works with older Visual Studio versions.

Some comments below:

> --- /dev/null
> +++ b/tools/clang-format-vs/.gitignore
> @@ -0,0 +1,11 @@
> +# Visual Studio files
> +.vs/
> +/packages/
> +/ClangFormat/obj/
> +/ClangFormat/bin/

Should there really be a leading slash in these paths? Same below.

> +
> +# Generated and copied files
> +/ClangFormat/Key.snk
> +/ClangFormat/license.txt
> +/ClangFormat/clang-format.exe
> +/ClangFormat/source.extension.vsixmanifest
> diff --git a/tools/clang-format-vs/CMakeLists.txt 
> b/tools/clang-format-vs/CMakeLists.txt
> index fd0d6b0..90f89d8 100644
> --- a/tools/clang-format-vs/CMakeLists.txt
> +++ b/tools/clang-format-vs/CMakeLists.txt
> @@ -18,8 +18,13 @@ if (BUILD_CLANG_FORMAT_VS_PLUGIN)
>configure_file("source.extension.vsixmanifest.in"
>
> "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest")
>
> -  add_custom_target(clang_format_vsix ALL
> -  devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release
> +  find_program(NUGET_EXE nuget PATHS ${NUGET_EXE_PATH})
> +  if (NOT NUGET_EXE)
> + message(FATAL_ERROR "Could not find nuget.exe. Download from 
> https://www.nuget.org/nuget.exe and add to PATH or pass path via 
> NUGET_EXE_PATH var")

Can you break this string over multiple lines? I know there are pretty
long lines in this file already, but it would be good to not make it
worse.

Maybe it could be clarified that NUGET_EXE_PATH is the path to a
directory containing nuget.exe, not to the file itself (I ran into
this). Maybe NUGET_EXE_DIR would be a better name?

> +  endif()
> +
> +  add_custom_target(clang_format_vsix ALL
> +  ${NUGET_EXE} restore "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" & 
> devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release

Is '&' a CMake thing, or should that be '&&'? Also, any chance of
breaking these long lines?

>DEPENDS clang_format_exe_for_vsix 
> "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest"
>COMMAND ${CMAKE_COMMAND} -E copy_if_different
>"${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/bin/Release/ClangFormat.vsix"
> diff --git a/tools/clang-format-vs/README.txt 
> b/tools/clang-format-vs/README.txt
> index b23355d..44a071b 100644
> --- a/tools/clang-format-vs/README.txt
> +++ b/tools/clang-format-vs/README.txt
> @@ -2,13 +2,23 @@ This directory contains a VSPackage project to generate a 
> Visual Studio extensio
>  for clang-format.
>
>  Build prerequisites are:
> -- Visual Studio 2013 Professional
> -- Visual Studio 2013 SDK
> -- Visual Studio 2010 Professional (?)
> -- Visual Studio 2010 SDK (?)
> +- Visual Studio 2015
> +- Extensions SDK (you'll be prompted to install it if you open 
> ClangFormat.sln)

A very nice simplification :-)

>
> -The extension is built using CMake by setting BUILD_CLANG_FORMAT_VS_PLUGIN=ON
> -when configuring a Clang build, and building the clang_format_vsix target.
> +The extension is built using CMake to generate the usual LLLVM.sln by setting

An L too much in LLLVM.sln?


On Mon, Nov 28, 2016 at 8:00 PM, Antonio Maiorano  wrote:
> I've attached a patch that works as discussed. When running CMake with
> -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON, it will look for nuget.exe in PATH, or
> you can pass in DNUGET_EXE_PATH=C:\nuget, for e.g.
>
>
> On Mon, 28 Nov 2016 at 14:31 Antonio Maiorano  wrote:
>>
>> Great, I'll get this working soon and attach a new patch :)
>>
>> On Mon, 28 Nov 2016 at 14:27 Hans Wennborg  wrote:
>>>
>>> On Mon, Nov 28, 2016 at 11:11 AM, Antonio Maiorano 
>>> wrote:
>>> >> It's built with the script in utils/release/build_llvm_package.bat
>>> > which I run manually on my machine once every few weeks.
>>> >
>>> > Okay, that's good news. So the simplest path to success would be to
>>> > require
>>> > the user to either pass the path to CMake via an arg like
>>> > -DNUGET_EXE_PATH,
>>> > or if it's not defined, to assume it's already in PATH. This is the
>>> > most
>>> > future-proof solution as it will work with future versions of VS (2017
>>> > RC
>>> > just came out).
>>> >
>>> > I can still look into whether a vsix built with VS 2015 references will
>>> > continue to work in older versions of VS, but even if this works, I
>>> > feel
>>> > like it's a temporary solution at best. There are other advantages to
>>> > using
>>> > NuGet here: it would allow us to more easily pin/upgrade which
>>> > assemblies we
>>> > want to use over time.
>>> >
>>> > If you're okay with it, I'll make the changes necessary to use
>>> > -DNUGET_EXE_PATH, if defined, otherwise assume it's on PATH. This
>>> > should be
>>> > a simple change at this point.
>>>
>>> That sounds good to me. There are already a bunch of prerequisites for
>>> building the plugin, so adding this one doesn't seem unreasonable.
>>> Especially since it seems it will simplify things to the point that
>>> they might even work elsewhere than my own machine :-)
>>>
>>>

[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe marked 11 inline comments as done.
spyffe added a comment.

Thank you, Alex!  I've responded in a few places inline below, and will update 
this patch momentarily.




Comment at: tools/clang-import-test/clang-import-test.cpp:106
+
+const char *LineEnd = nullptr;
+

a.sidorin wrote:
> How about something like this:
> ```
> StringRef Remain(LineBegin, Buffer->getBufferEnd() - LineBegin);
> size_t EndPos = Remain.find_first_of("\r\n");
> StringRef Line = (EndPos == StringRef::npos) ? Remain : StringRef(LineBegin, 
> EndPos);
> llvm::errs() << Line << "\n";
> llvm::errs().indent(LocColumn) << "^\n";
> ```
> ?
I'm going to think about this a little more.  Personally I find the loop more 
readable.
That said StringRef instead of std::string seems an obvious win:
```
llvm::StringRef LineString(LineBegin, LineEnd - LineBegin);
``` 



Comment at: tools/clang-import-test/clang-import-test.cpp:152
+class TestExternalASTSource : public ExternalASTSource {
+private:  llvm::ArrayRef ImportCIs;
+  std::map> ForwardImporters;

a.sidorin wrote:
> Please add a newline here.
I just ran clang-format on the whole file.  Sorry for the noise.



Comment at: tools/clang-import-test/clang-import-test.cpp:222
+   SmallVectorImpl &Result) override {
+
+  }

a.sidorin wrote:
> Extra spaces.
Sigh.  Yes, I had a preliminary implementation of this in mind, but decided to 
split that out into a separate patch.



Comment at: tools/clang-import-test/clang-import-test.cpp:238
+
+  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
+ &ClangArgv.data()[ClangArgv.size()],

a.sidorin wrote:
> `ClangArgv.begin(), ClangArgv.end()`
```
.../llvm/tools/clang/tools/clang-import-test/clang-import-test.cpp:236:44: 
error: no viable conversion from 'iterator' (aka '__wrap_iter') 
to 'const char *const *'
  CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.begin(), ClangArgv.end(),
   ^
.../llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h:139:49: note: 
passing argument to parameter 'ArgBegin' here
 const char* const *ArgBegin,
^
```


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-11-29 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 79605.
spyffe marked 2 inline comments as done.
spyffe added a comment.

Updated to reflect Aleksei's comments.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180

Files:
  test/Import/empty-struct/Inputs/S.c
  test/Import/empty-struct/test.c
  tools/CMakeLists.txt
  tools/clang-import-test/CMakeLists.txt
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ tools/clang-import-test/clang-import-test.cpp
@@ -0,0 +1,342 @@
+//===-- import-test.cpp - ASTImporter/ExternalASTSource testbed ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTImporter.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TargetInfo.h"
+#include "clang/Basic/TargetOptions.h"
+#include "clang/CodeGen/ModuleBuilder.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Parse/ParseAST.h"
+
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/Signals.h"
+
+#include 
+#include 
+
+using namespace clang;
+
+static llvm::cl::opt Expression(
+"expression", llvm::cl::Required,
+llvm::cl::desc("Path to a file containing the expression to parse"));
+
+static llvm::cl::list
+Imports("import", llvm::cl::ZeroOrMore,
+llvm::cl::desc("Path to a file containing declarations to import"));
+
+static llvm::cl::list
+ClangArgs("-Xcc", llvm::cl::ZeroOrMore,
+  llvm::cl::desc("Argument to pass to the CompilerInvocation"),
+  llvm::cl::CommaSeparated);
+
+static llvm::cl::opt LogLookups(
+"log-lookups",
+llvm::cl::desc("Print each lookup performed on behalf of the expression"));
+
+namespace {
+
+class TestDiagnosticConsumer : public DiagnosticConsumer {
+private:
+  std::unique_ptr Passthrough;
+  const LangOptions *LangOpts = nullptr;
+
+public:
+  TestDiagnosticConsumer()
+  : Passthrough(llvm::make_unique()) {}
+
+  virtual void BeginSourceFile(const LangOptions &LangOpts,
+   const Preprocessor *PP = nullptr) override {
+this->LangOpts = &LangOpts;
+return Passthrough->BeginSourceFile(LangOpts, PP);
+  }
+
+  virtual void EndSourceFile() override {
+this->LangOpts = nullptr;
+Passthrough->EndSourceFile();
+  }
+
+  virtual void finish() override { Passthrough->finish(); }
+
+  virtual bool IncludeInDiagnosticCounts() const override {
+return Passthrough->IncludeInDiagnosticCounts();
+  }
+
+private:
+  static void PrintSourceForLocation(const SourceLocation &Loc,
+ SourceManager &SM) {
+bool Invalid = true;
+const char *LocData = SM.getCharacterData(Loc, &Invalid);
+if (Invalid) {
+  return;
+}
+unsigned LocColumn = SM.getSpellingColumnNumber(Loc, &Invalid) - 1;
+if (Invalid) {
+  return;
+}
+FileID FID = SM.getFileID(Loc);
+llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, Loc, &Invalid);
+if (Invalid) {
+  return;
+}
+
+assert(LocData >= Buffer->getBufferStart() &&
+   LocData < Buffer->getBufferEnd());
+
+const char *LineBegin = LocData - LocColumn;
+
+if (LineBegin < Buffer->getBufferStart()) {
+  LineBegin = Buffer->getBufferStart();
+}
+
+const char *LineEnd = nullptr;
+
+for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' &&
+  LineEnd < Buffer->getBufferEnd();
+ ++LineEnd)
+  ;
+
+llvm::StringRef LineString(LineBegin, LineEnd - LineBegin);
+
+llvm::errs() << LineString << '\n';
+std::string Space(LocColumn, ' ');
+llvm::errs() << Space.c_str() << '\n';
+  }
+
+  virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const Diagnostic &Info) override {
+if (Info.hasSourceManager() && LangOpts) {
+  SourceManager &SM = Info.getSourceManager();
+
+  if (Info.getLocation().isValid()) {
+Info.getLocation().print(llvm::errs(), SM);
+llvm::errs() << ": ";
+  }
+
+  SmallString<16> DiagText;
+  Info.FormatDiagnostic(DiagText);
+  llvm::errs() << DiagText << '\n';
+
+  if (Info.getLocation().isValid()) {
+PrintSourceForLocation(Info.getLocation(), SM);
+  }
+
+  for (const CharSourceRange &Range : Info.getRanges()) {
+bool Invalid = true;
+StringR

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).




Comment at: docs/clang-tidy/checks/misc-string-compare.rst:8
+
+A common mistake is to use the string's compare method instead of using the 
+equality or inequality operators. The compare method is intended for sorting

Please enclose compare in ``. Probably will be good idea to add (). Same below.



Comment at: docs/clang-tidy/checks/misc-string-compare.rst:10
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns -1, 0 or 1 depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check

Please enclose -1, 0 and 1 in `.


Repository:
  rL LLVM

https://reviews.llvm.org/D27210



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Mads Ravn via Phabricator via cfe-commits
madsravn removed rL LLVM as the repository for this revision.
madsravn updated this revision to Diff 79610.
madsravn added a comment.

Updated the patch to include changes suggested by comments.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscStringCompareCheck.cpp
  clang-tidy/misc/MiscStringCompareCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+#include 
+
+void Test() {
+  std::string str1{"a"};
+  std::string str2{"b"};
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+}
+
+void Valid() {
+std::string str1{"a"};
+std::string str2{"b"};
+if(str1 == str2) {}
+if(str1 != str2) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,31 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's compare method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns -1, 0 or 1 depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses compare to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -22,6 +22,7 @@
 #include "InefficientAlgorithmCheck.h"
 #include "MacroParenthesesCheck.h"
 #include "MacroRepeatedSideEffectsCheck.h"
+#include "MiscStringCompareCheck.h"
 #include "MisplacedConstCheck.h"
 #include "MisplacedWideningCastCheck.h"
 #include "MoveConstantArgumentCheck.h"
@@ -105,6 +106,7 @@
 CheckFactories.registerCheck(
 "misc-sizeof-expression");
 CheckFactories.registerCheck("misc-static-assert");
+CheckFactories.registerCheck("misc-string-compare");
 CheckFactories.registerCheck(
 "misc-string-constructor");
 CheckFactories.registerCheck(
Index: clang-tidy/misc/MiscStringCompareCheck.h
===
--- clang-tidy/misc/MiscStringCompareCheck.h
+++ clang-tidy/misc/MiscStringCompareCheck.h
@@ -0,0 +1,36 @@
+//===--- MiscStringCompareCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef MISC_STRING_COMPARE_CHECK_H
+#define MISC_STRING_COMPARE_CHECK_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace mis

[PATCH] D21695: [clang] Version support for UBSan handlers

2016-11-29 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a reviewer: vsk.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks for working on this. LGTM with a nit.




Comment at: lib/CodeGen/CGExpr.cpp:2506
+  assert(CheckHandler >= 0 &&
+ CheckHandler < sizeof(SanitizerHandlers) / 
sizeof(*SanitizerHandlers));
+  const StringRef CheckName = SanitizerHandlers[CheckHandler].Name;

Use llvm::array_lengthof? Also, I don't think the >= 0 check is really 
necessary, but I'll leave it up to you to decide.


https://reviews.llvm.org/D21695



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


r288193 - Support constant expression evaluation for wchar_t versions of simple string

2016-11-29 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Tue Nov 29 13:45:17 2016
New Revision: 288193

URL: http://llvm.org/viewvc/llvm-project?rev=288193&view=rev
Log:
Support constant expression evaluation for wchar_t versions of simple string
functions, in order to support constexpr std::char_traits.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constexpr-string.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=288193&r1=288192&r2=288193&view=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Nov 29 13:45:17 2016
@@ -29,6 +29,7 @@
 //  f -> float
 //  d -> double
 //  z -> size_t
+//  w -> wchar_t
 //  F -> constant CFString
 //  G -> id
 //  H -> SEL
@@ -456,6 +457,12 @@ BUILTIN(__builtin_strpbrk, "c*cC*cC*", "
 BUILTIN(__builtin_strrchr, "c*cC*i", "nF")
 BUILTIN(__builtin_strspn, "zcC*cC*", "nF")
 BUILTIN(__builtin_strstr, "c*cC*cC*", "nF")
+BUILTIN(__builtin_wcschr, "w*wC*w", "nF")
+BUILTIN(__builtin_wcscmp, "iwC*wC*", "nF")
+BUILTIN(__builtin_wcslen, "zwC*", "nF")
+BUILTIN(__builtin_wcsncmp, "iwC*wC*z", "nF")
+BUILTIN(__builtin_wmemchr, "w*wC*wz", "nF")
+BUILTIN(__builtin_wmemcmp, "iwC*wC*z", "nF")
 BUILTIN(__builtin_return_address, "v*IUi", "n")
 BUILTIN(__builtin_extract_return_addr, "v*v*", "n")
 BUILTIN(__builtin_frame_address, "v*IUi", "n")
@@ -830,6 +837,15 @@ LIBBUILTIN(isupper, "ii", "fnU", "ctype.
 LIBBUILTIN(isxdigit, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
 LIBBUILTIN(tolower, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
 LIBBUILTIN(toupper, "ii", "fnU", "ctype.h", ALL_LANGUAGES)
+// C99 wchar.h
+// FIXME: This list is incomplete. We should cover at least the functions that
+// take format strings.
+LIBBUILTIN(wcschr,  "w*wC*w",   "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcscmp,  "iwC*wC*",  "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcslen,  "zwC*", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wcsncmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemchr, "w*wC*wz",  "f", "wchar.h", ALL_LANGUAGES)
+LIBBUILTIN(wmemcmp, "iwC*wC*z", "f", "wchar.h", ALL_LANGUAGES)
 
 // C99
 // In some systems setjmp is a macro that expands to _setjmp. We undefine

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=288193&r1=288192&r2=288193&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Nov 29 13:45:17 2016
@@ -8554,6 +8554,10 @@ static QualType DecodeTypeFromStr(const
 assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'z'!");
 Type = Context.getSizeType();
 break;
+  case 'w':  // wchar_t.
+assert(HowLong == 0 && !Signed && !Unsigned && "Bad modifiers for 'w'!");
+Type = Context.getWideCharType();
+break;
   case 'F':
 Type = Context.getCFConstantStringType();
 break;

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=288193&r1=288192&r2=288193&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 29 13:45:17 2016
@@ -5346,16 +5346,20 @@ bool PointerExprEvaluator::VisitBuiltinC
   }
 
   case Builtin::BIstrchr:
+  case Builtin::BIwcschr:
   case Builtin::BImemchr:
+  case Builtin::BIwmemchr:
 if (Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_constexpr_invalid_function)
 << /*isConstexpr*/0 << /*isConstructor*/0
-<< (BuiltinOp == Builtin::BIstrchr ? "'strchr'" : "'memchr'");
+<< (std::string("'") + Info.Ctx.BuiltinInfo.getName(BuiltinOp) + "'");
 else
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strchr:
-  case Builtin::BI__builtin_memchr: {
+  case Builtin::BI__builtin_wcschr:
+  case Builtin::BI__builtin_memchr:
+  case Builtin::BI__builtin_wmemchr: {
 if (!Visit(E->getArg(0)))
   return false;
 APSInt Desired;
@@ -5363,29 +5367,51 @@ bool PointerExprEvaluator::VisitBuiltinC
   return false;
 uint64_t MaxLength = uint64_t(-1);
 if (BuiltinOp != Builtin::BIstrchr &&
-BuiltinOp != Builtin::BI__builtin_strchr) {
+BuiltinOp != Builtin::BIwcschr &&
+BuiltinOp != Builtin::BI__builtin_strchr &&
+BuiltinOp != Builtin::BI__builtin_wcschr) {
   APSInt N;
   if (!EvaluateInteger(E->getArg(2), N, Info))
 return false;
   MaxLength = N.getExtValue();
 }
 
-QualType CharTy = Info.Ctx.CharTy;
-bool IsStrchr = (BuiltinOp != Builtin::BImemchr &&

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

Please run clang-format on all new files.




Comment at: test/clang-tidy/misc-string-compare.cpp:3
+
+#include 
+

clang-tidy tests don't #include system headers.
Declare the bits you need instead.
See test/clang-tidy/misc-string-constructor.cpp for an example.



Comment at: test/clang-tidy/misc-string-compare.cpp:9
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test 
equality of strings; use the string equality operator instead 
[misc-string-compare]

Some other test ideas:

```
if (str1.compare("foo")) {}

return str1.compare(str2) == 0;

func(str1.compare(str2) != 0);

if (str2.empty() || str1.compare(str2) != 0) {}
```


https://reviews.llvm.org/D27210



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


[PATCH] D27049: [OpenCL] Refactor out ReadPipe/WritePipe

2016-11-29 Thread Yaron Keren via Phabricator via cfe-commits
yaron.keren accepted this revision.
yaron.keren added a comment.
This revision is now accepted and ready to land.

LGTM after fixing the inline comment




Comment at: lib/Serialization/ASTReader.cpp:5804
 QualType ElementType = readType(*Loc.F, Record, Idx);
-return Context.getReadPipeType(ElementType);
+unsigned ReadOnly = Record[1];
+if (ReadOnly)

  return Context,getPipeType(ElementType, ReadOnly)



Repository:
  rL LLVM

https://reviews.llvm.org/D27049



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


Re: Upgrade and fix clang-format-vs

2016-11-29 Thread Hans Wennborg via cfe-commits
On Tue, Nov 29, 2016 at 12:01 PM, Antonio Maiorano  wrote:
> On Tue, 29 Nov 2016 at 13:42 Hans Wennborg  wrote:
>>
>> Very nice! I've tried this out and confirmed that the built plugin
>> also works with older Visual Studio versions.
>>
>> Some comments below:
>>
>> > --- /dev/null
>> > +++ b/tools/clang-format-vs/.gitignore
>> > @@ -0,0 +1,11 @@
>> > +# Visual Studio files
>> > +.vs/
>> > +/packages/
>> > +/ClangFormat/obj/
>> > +/ClangFormat/bin/
>>
>> Should there really be a leading slash in these paths? Same below.
>
>
> Without the leading slash, then it would match "ClangFormat/obj" anywhere in
> the tree, rather than explicitly the one and only folder from the root. In
> this case, it wouldn't matter much. If you prefer, I could just ignore
> "obj/" and "bin/", etc, although I'd rather be explicit for Key.snk,
> license.txt, etc.

Interesting. I was just comparing with LLVM's root .gitignore, which
doesn't have leading slashes for many dirs. Checking the gitignore
doc, it sounds like you've got it right :-)


>> > +# Generated and copied files
>> > +/ClangFormat/Key.snk
>> > +/ClangFormat/license.txt
>> > +/ClangFormat/clang-format.exe
>> > +/ClangFormat/source.extension.vsixmanifest
>> > diff --git a/tools/clang-format-vs/CMakeLists.txt
>> > b/tools/clang-format-vs/CMakeLists.txt
>> > index fd0d6b0..90f89d8 100644
>> > --- a/tools/clang-format-vs/CMakeLists.txt
>> > +++ b/tools/clang-format-vs/CMakeLists.txt
>> > @@ -18,8 +18,13 @@ if (BUILD_CLANG_FORMAT_VS_PLUGIN)
>> >configure_file("source.extension.vsixmanifest.in"
>> >
>> > "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest")
>> >
>> > -  add_custom_target(clang_format_vsix ALL
>> > -  devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build
>> > Release
>> > +  find_program(NUGET_EXE nuget PATHS ${NUGET_EXE_PATH})
>> > +  if (NOT NUGET_EXE)
>> > + message(FATAL_ERROR "Could not find nuget.exe. Download from
>> > https://www.nuget.org/nuget.exe and add to PATH or pass path via
>> > NUGET_EXE_PATH var")
>>
>> Can you break this string over multiple lines? I know there are pretty
>> long lines in this file already, but it would be good to not make it
>> worse.
>
>
> Sure thing, I'll see what I can do :)
>
>>
>>
>> Maybe it could be clarified that NUGET_EXE_PATH is the path to a
>> directory containing nuget.exe, not to the file itself (I ran into
>> this). Maybe NUGET_EXE_DIR would be a better name?
>
>
> That would be a better name, will make that change.
>
>>
>>
>> > +  endif()
>> > +
>> > +  add_custom_target(clang_format_vsix ALL
>> > +  ${NUGET_EXE} restore "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" &
>> > devenv "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat.sln" /Build Release
>>
>> Is '&' a CMake thing, or should that be '&&'? Also, any chance of
>> breaking these long lines?
>
>
> '&' is a cmd.exe thing, but I can use '&&' - in fact, the latter only runs
> the 2nd command if the first succeeds, while using '&' always runs both.
> I'll make the change, and will try to shorten this line as well.
>
>>
>>
>> >DEPENDS clang_format_exe_for_vsix
>> > "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/source.extension.vsixmanifest"
>> >COMMAND ${CMAKE_COMMAND} -E copy_if_different
>> >
>> > "${CMAKE_CURRENT_SOURCE_DIR}/ClangFormat/bin/Release/ClangFormat.vsix"
>> > diff --git a/tools/clang-format-vs/README.txt
>> > b/tools/clang-format-vs/README.txt
>> > index b23355d..44a071b 100644
>> > --- a/tools/clang-format-vs/README.txt
>> > +++ b/tools/clang-format-vs/README.txt
>> > @@ -2,13 +2,23 @@ This directory contains a VSPackage project to
>> > generate a Visual Studio extensio
>> >  for clang-format.
>> >
>> >  Build prerequisites are:
>> > -- Visual Studio 2013 Professional
>> > -- Visual Studio 2013 SDK
>> > -- Visual Studio 2010 Professional (?)
>> > -- Visual Studio 2010 SDK (?)
>> > +- Visual Studio 2015
>> > +- Extensions SDK (you'll be prompted to install it if you open
>> > ClangFormat.sln)
>>
>> A very nice simplification :-)
>
>
> Thanks :)
>
>>
>>
>> >
>> > -The extension is built using CMake by setting
>> > BUILD_CLANG_FORMAT_VS_PLUGIN=ON
>> > -when configuring a Clang build, and building the clang_format_vsix
>> > target.
>> > +The extension is built using CMake to generate the usual LLLVM.sln by
>> > setting
>>
>> An L too much in LLLVM.sln?
>
>
> You know, that extra L in 'L'egendary LLVM? ;) Will remove!
>
> Will update patch soon!
>
>>
>>
>> On Mon, Nov 28, 2016 at 8:00 PM, Antonio Maiorano 
>> wrote:
>> > I've attached a patch that works as discussed. When running CMake with
>> > -DBUILD_CLANG_FORMAT_VS_PLUGIN=ON, it will look for nuget.exe in PATH,
>> > or
>> > you can pass in DNUGET_EXE_PATH=C:\nuget, for e.g.
>> >
>> >
>> > On Mon, 28 Nov 2016 at 14:31 Antonio Maiorano 
>> > wrote:
>> >>
>> >> Great, I'll get this working soon and attach a new patch :)
>> >>
>> >> On Mon, 28 Nov 2016 at 14:27 Hans Wennborg  wrote:
>> >>>
>> >>> On Mon, Nov 28, 2016 at 11:11 AM, Antonio Maiorano
>> >>> 
>> >

r288197 - Don't declare IsEnumDeclComplete as extern

2016-11-29 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Tue Nov 29 14:46:24 2016
New Revision: 288197

URL: http://llvm.org/viewvc/llvm-project?rev=288197&view=rev
Log:
Don't declare IsEnumDeclComplete as extern

Otherwise MSVC and clang-cl will see "extern inline" after merging
redeclarations and emit it in all TUs that include Type.h and Decl.h.

Noticed by inspection, since it's always the first thing to get emitted.

Modified:
cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=288197&r1=288196&r2=288197&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Nov 29 14:46:24 2016
@@ -5805,8 +5805,8 @@ inline bool Type::isNullPtrType() const
   return false;
 }
 
-extern bool IsEnumDeclComplete(EnumDecl *);
-extern bool IsEnumDeclScoped(EnumDecl *);
+bool IsEnumDeclComplete(EnumDecl *);
+bool IsEnumDeclScoped(EnumDecl *);
 
 inline bool Type::isIntegerType() const {
   if (const BuiltinType *BT = dyn_cast(CanonicalType))


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


[PATCH] D26920: [libc++] Add validation to Stage 2 of num_get

2016-11-29 Thread Eric van Gyzen via Phabricator via cfe-commits
vangyzen updated this revision to Diff 79625.
vangyzen added a comment.
Herald added a subscriber: emaste.

Restore support for a sign character preceding a "nan"

I accidentally broke +nan and -nan.  Add unit test cases for these,
and update my change to support them.


https://reviews.llvm.org/D26920

Files:
  include/locale
  
test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp

Index: test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
===
--- test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
+++ test/std/localization/locale.categories/category.numeric/locale.num.get/facet.num.get.members/get_double.pass.cpp
@@ -136,6 +136,30 @@
 assert(v == INFINITY);
 }
 {
+const char str[] = "+Inf";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(v == INFINITY);
+}
+{
+const char str[] = "+iNF";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(v == INFINITY);
+}
+{
 const char str[] = "-inf";
 hex(ios);
 std::ios_base::iostate err = ios.goodbit;
@@ -184,6 +208,30 @@
 assert(std::isnan(v));
 }
 {
+const char str[] = "+NaN";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(std::isnan(v));
+}
+{
+const char str[] = "-nAn";
+hex(ios);
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(iter.base() == str+sizeof(str)-1);
+assert(err == ios.goodbit);
+assert(std::isnan(v));
+}
+{
 v = -1;
 const char str[] = "123_456_78_9;125";
 std::ios_base::iostate err = ios.goodbit;
@@ -208,6 +256,19 @@
 assert(v == 2);
 }
 {
+// http://cplusplus.github.io/LWG/lwg-active.html#2381
+v = -1;
+const char str[] = "0x1a.bp+07p";
+std::ios_base::iostate err = ios.goodbit;
+input_iterator iter =
+f.get(input_iterator(str),
+  input_iterator(str+sizeof(str)),
+  ios, err, v);
+assert(err == ios.goodbit);
+assert(iter.base() == str+sizeof(str)-2);
+assert(v == 0x1a.bp+07);
+}
+{
 v = -1;
 const char str[] = "1.79779e+309"; // unrepresentable
 std::ios_base::iostate err = ios.goodbit;
Index: include/locale
===
--- include/locale
+++ include/locale
@@ -505,17 +505,67 @@
 return -1;
 }
 if (__x == 'x' || __x == 'X')
-__exp = 'P';
+{
+unsigned __sign = (*__a == '-') + (*__a == '+');
+if (__a_end == __a + __sign + 1 && __a[__sign] == '0')
+__exp = 'P';
+else
+return -1;
+}
 else if ((__x & 0x5F) == __exp)
 {
+if (__exp & 0x80)
+return -1;
 __exp |= 0x80;
 if (__in_units)
 {
 __in_units = false;
 if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
 *__g_end++ = __dc;
 }
 }
+else if (__f > 9)
+{
+if (__x == 'P' || __x == 'p')
+return -1;
+unsigned __sign = (*__a == '-') + (*__a == '+');
+if (__x == 'I' || __x == 'i')
+{
+if (__a_end != __a + __sign)// start of Inf
+return -1;
+}
+else if (__x == 'N' || __x == 'n')
+{
+bool __ok =
+(__a_end == __a + __sign)   // start of NaN
+||
+(__a_end == __a + __sign + 2 && // end of NaN
+(__a[__sign  ] & 0x5F) == 'N' &&
+(__a[__sign+1] & 0x5F) == 'A')
+||
+(__a_end == __a + __sign + 1 && // middle of Inf
+(__a[__sign]

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-11-29 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 79624.
madsravn added a comment.

Updated per comments


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,29 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+#include 
+
+void Test() {
+  std::string str1{"a"};
+  std::string str2{"b"};
+
+  if(str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(!str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) == 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(str1.compare(str2) != 0) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 == str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if(0 != str1.compare(str2)) {}
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: do not use compare to test equality of strings; use the string equality operator instead [misc-string-compare]
+
+}
+
+void Valid() {
+std::string str1{"a"};
+std::string str2{"b"};
+if(str1 == str2) {}
+if(str1 != str2) {}
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operators. The compare method is intended for sorting
+functions and thus returns ``-1``, ``0`` or ``1`` depending on the lexicographical 
+relationship between the strings compared. If an equality or inequality check
+can suffice, that is recommended.
+
+Examples:
+
+.. code-block:: c++
+
+  std::string str1{"a"};
+  std::string str2{"b"};
+  
+  if(str1.compare(str2)) {} // use str1 != str2 instead
+  
+  if(!str1.compare(str2)) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) == 0) {} // use str1 == str2 instead
+  
+  if(str1.compare(str2) != 0) {} // use str1 != str2 instead
+
+  if(0 == str1.compare(str2)) {} // use str1 == str2 instead
+
+  if(0 != str1.compare(str2)) {} // use str1 != str2 instead
+
+The above code examples shows the list of if-statements that this check will
+give a warning for. All of them uses ``compare`` to check if equality or 
+inequality of two strings instead of using the correct operators.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -80,6 +80,7 @@
misc-sizeof-container
misc-sizeof-expression
misc-static-assert
+   misc-string-compare
misc-string-constructor
misc-string-integer-assignment
misc-string-literal-with-embedded-nul
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -75,6 +75,11 @@
 
 - `misc-pointer-and-integral-operation` check was removed.
 
+- New `misc-string-compare
+  `_ check
+
+  Warns about using ``compare`` to test for string equality or ineqaulity.
+
 - New `misc-use-after-move
   `_ check
 
Index: clang-tidy/misc/StringCompareCheck.h
===
--- clang-tidy/misc/StringCompareCheck.h
+++ clang-tidy/misc/StringCompareCheck.h
@@ -0,0 +1,36 @@
+//===--- StringCompareCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===

[PATCH] D26979: Do not hard-code locale data in unit tests: get it from the OS instead

2016-11-29 Thread Eric van Gyzen via Phabricator via cfe-commits
vangyzen added a comment.

@EricWF Do you have time and interest to review this again?


https://reviews.llvm.org/D26979



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 79627.
malcolm.parsons added a comment.

Handle templated member functions too.


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,72 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B &b6 = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b6 = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+
+  S s;
+  const B *b8 = s.template_member_get();
+
+  auto i2 = template_value_cast(d);
+  int i3 = max(i1, i2);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -136,3 +136,64 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  &b4 = 

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons marked an inline comment as done.
malcolm.parsons added a comment.

In https://reviews.llvm.org/D27166#606772, @Eugene.Zelenko wrote:

> It'll be worth to mention enhancement in Release Notes.


They already say this:

- The `modernize-use-auto 
`_ check 
now warns about variable declarations that are initialized with a cast.

Does that cover it?


https://reviews.llvm.org/D27166



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


[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection

2016-11-29 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 79629.
danielcdh marked an inline comment as done.
danielcdh added a comment.

Change the flag to -fprof-debug, which is more concise. The flag name is still 
open for discussion.


https://reviews.llvm.org/D25435

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROF-DEBUG %s
+// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-PROF-DEBUG %s
+// CHECK-PROF-DEBUG: -fprof-debug
+// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -538,6 +538,7 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
+  Opts.ProfDebug = Args.hasFlag(OPT_fprof_debug, OPT_fno_prof_debug, false);
 
   setPGOInstrumentor(Opts, Args, Diags);
   Opts.InstrProfileOutput =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5508,6 +5508,10 @@
   A->render(Args, CmdArgs);
   }
 
+  if (Args.hasFlag(options::OPT_fprof_debug,
+   options::OPT_fno_prof_debug, false))
+CmdArgs.push_back("-fprof-debug");
+
   // -fbuiltin is default unless -mkernel is used.
   bool UseBuiltins =
   Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2739,9 +2739,10 @@
   }
   // No need to replicate the linkage name if it isn't different from the
   // subprogram name, no need to have it at all unless coverage is enabled or
-  // debug is set to more than just line tables.
+  // debug is set to more than just line tables or extra debug info is needed.
   if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
   !CGM.getCodeGenOpts().EmitGcovNotes &&
+  !CGM.getCodeGenOpts().ProfDebug &&
   DebugKind <= 
codegenoptions::DebugLineTablesOnly))
 LinkageName = StringRef();
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -256,6 +256,9 @@
 /// Whether copy relocations support is available when building as PIE.
 CODEGENOPT(PIECopyRelocations, 1, 0)
 
+/// Whether emit extra debug info for sample pgo profile collection.
+CODEGENOPT(ProfDebug, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -509,6 +509,12 @@
 HelpText<"Enable sample-based profile guided optimizations">;
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
 Alias;
+def fprof_debug : Flag<["-"], "fprof-debug">, Group,
+Flags<[CC1Option]>,
+HelpText<"Emit extra debug info to make sample profile more accurate.">;
+def fno_prof_debug : Flag<["-"], "fno-prof-debug">, Group,
+Flags<[DriverOption]>,
+HelpText<"Do not emit extra debug info for sample profiler.">;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[DriverOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overriden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-prof-debug -fprof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-PROF-DEBUG %s
+// RUN: %clang -### -S -fprof-debug -fno-prof-debug %s 2>&1 | FileCheck -check-prefix=CHECK-NO-PROF-DEBUG %s
+// CHECK-PROF-DEBUG: -fprof-debug
+// CHECK-NO-PROF-DEBUG-NOT: -fprof-debug
Index: lib/Frontend/CompilerInvocation.cpp
=

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D27166#608339, @malcolm.parsons wrote:

> In https://reviews.llvm.org/D27166#606772, @Eugene.Zelenko wrote:
>
> > It'll be worth to mention enhancement in Release Notes.
>
>
> They already say this:
>
> - The `modernize-use-auto 
> `_ 
> check now warns about variable declarations that are initialized with a cast.
>
>   Does that cover it?


I'm not very sure, because cats may be interpreted as C++ language constructs 
only, but not framework provided ones.


https://reviews.llvm.org/D27166



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


[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-11-29 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 79632.
malcolm.parsons added a comment.

Add to release notes


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,72 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B &b6 = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b6 = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+
+  S s;
+  const B *b8 = s.template_member_get();
+
+  auto i2 = template_value_cast(d);
+  int i3 = max(i1, i2);
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -136,3 +136,64 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto  

  1   2   >