[PATCH] D39930: [CMake] Use libc++ and compiler-rt as default libraries in Fuchsia toolchain

2017-11-17 Thread Roland McGrath via Phabricator via cfe-commits
mcgrathr accepted this revision.
mcgrathr added a comment.
This revision is now accepted and ready to land.

LGTM with comment added but if a different approach will be required for 
multiple Linux targets (which we all treat as "hostish") then it's worth at 
least thinking about that now.




Comment at: cmake/caches/Fuchsia-stage2.cmake:44
 
+set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")

It's not completely obvious (to me) that these apply to the "default target" 
build but not to the other LLVM_RUNTIME_TARGETS builds.
A comment here would be good.

We recently discussed enabling other *-linux targets (AFAIK we might as well 
enable {x86_64,aarch64}-linux regardless of host, even for Mac hosts).  We'd 
want these settings for those too.  Would that have to be done differently than 
thsi?


Repository:
  rL LLVM

https://reviews.llvm.org/D39930



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


r318582 - [AST] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2017-11-17 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Fri Nov 17 17:47:41 2017
New Revision: 318582

URL: http://llvm.org/viewvc/llvm-project?rev=318582=rev
Log:
[AST] Fix some Clang-tidy modernize and Include What You Use warnings; other 
minor fixes (NFC).

Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/lib/AST/ExprCXX.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=318582=318581=318582=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Fri Nov 17 17:47:41 2017
@@ -1,4 +1,4 @@
-//===--- ExprCXX.h - Classes for representing expressions ---*- C++ 
-*-===//
+//===- ExprCXX.h - Classes for representing expressions -*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,31 +6,57 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Defines the clang::Expr interface and subclasses for C++ 
expressions.
-///
+//
 
//===--===//
 
 #ifndef LLVM_CLANG_AST_EXPRCXX_H
 #define LLVM_CLANG_AST_EXPRCXX_H
 
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclarationName.h"
 #include "clang/AST/Expr.h"
-#include "clang/AST/LambdaCapture.h"
+#include "clang/AST/NestedNameSpecifier.h"
+#include "clang/AST/OperationKinds.h"
+#include "clang/AST/Stmt.h"
 #include "clang/AST/TemplateBase.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/UnresolvedSet.h"
+#include "clang/Basic/ExceptionSpecificationType.h"
 #include "clang/Basic/ExpressionTraits.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/Lambda.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/OperatorKinds.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/TypeTraits.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/PointerUnion.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/TrailingObjects.h"
+#include 
+#include 
+#include 
+#include 
 
 namespace clang {
 
-class CXXTemporary;
-class MSPropertyDecl;
-class TemplateArgumentListInfo;
-class UuidAttr;
+class ASTContext;
+class DeclAccessPair;
+class IdentifierInfo;
+class LambdaCapture;
+class NonTypeTemplateParmDecl;
+class TemplateParameterList;
 
 //======//
 // C++ Expressions.
@@ -52,23 +78,28 @@ class UuidAttr;
 class CXXOperatorCallExpr : public CallExpr {
   /// \brief The overloaded operator.
   OverloadedOperatorKind Operator;
+
   SourceRange Range;
 
   // Only meaningful for floating point types.
   FPOptions FPFeatures;
 
   SourceRange getSourceRangeImpl() const LLVM_READONLY;
+
 public:
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
+
   CXXOperatorCallExpr(ASTContext& C, OverloadedOperatorKind Op, Expr *fn,
   ArrayRef args, QualType t, ExprValueKind VK,
   SourceLocation operatorloc, FPOptions FPFeatures)
-: CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
-  Operator(Op), FPFeatures(FPFeatures) {
+  : CallExpr(C, CXXOperatorCallExprClass, fn, args, t, VK, operatorloc),
+Operator(Op), FPFeatures(FPFeatures) {
 Range = getSourceRangeImpl();
   }
-  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty) :
-CallExpr(C, CXXOperatorCallExprClass, Empty) { }
 
+  explicit CXXOperatorCallExpr(ASTContext& C, EmptyShell Empty)
+  : CallExpr(C, CXXOperatorCallExprClass, Empty) {}
 
   /// \brief Returns the kind of overloaded operator that this
   /// expression refers to.
@@ -120,9 +151,6 @@ public:
   bool isFPContractableWithinStatement() const {
 return FPFeatures.allowFPContractWithinStatement();
   }
-
-  friend class ASTStmtReader;
-  friend class ASTStmtWriter;
 };
 
 /// Represents a call to a member function that
@@ -137,10 +165,10 @@ class CXXMemberCallExpr : public CallExp
 public:
   CXXMemberCallExpr(ASTContext , Expr *fn, ArrayRef args,
 QualType t, ExprValueKind VK, SourceLocation RP)
-: CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
+  : CallExpr(C, CXXMemberCallExprClass, fn, args, t, VK, RP) {}
 
   CXXMemberCallExpr(ASTContext , EmptyShell Empty)
-: CallExpr(C, CXXMemberCallExprClass, Empty) { }
+  : CallExpr(C, CXXMemberCallExprClass, Empty) {}
 
   /// \brief Retrieves the implicit object argument for the member call.
   ///
@@ -183,7 +211,7 @@ public:
   : CallExpr(C, 

Re: r318536 - [OPENMP] Codegen for `target simd` construct.

2017-11-17 Thread Hans Wennborg via cfe-commits
Ah ok. Thanks for checking!

On Fri, Nov 17, 2017 at 4:59 PM, Alexey Bataev  wrote:
> No, it is caused by some other changes. Seems to me, somebody changed the
> interface of functions, but forgot to remove the variables that are not used
> anymore.
> The changes look good to me, thanks.
>
> Best regards,
> Alexey Bataev
>
> 17 нояб. 2017 г., в 19:50, Hans Wennborg  написал(а):
>
> I think this caused some unused variable warnings:
>
> ../tools/clang/lib/CodeGen/CGStmtOpenMP.cpp:360:25: warning: unused
> variable 'ExtInfo' [-Wunused-variable]
>  FunctionType::ExtInfo ExtInfo;
>^
> 1 warning generated.
> [3049/3507] Building CXX object
> tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGStmt.cpp.o
> ../tools/clang/lib/CodeGen/CGStmt.cpp:2271:25: warning: unused
> variable 'ExtInfo' [-Wunused-variable]
>  FunctionType::ExtInfo ExtInfo;
>^
> 1 warning generated.
> [3068/3507] Building CXX object
> tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGOpenMPRuntime.cpp.o
> ../tools/clang/lib/CodeGen/CGOpenMPRuntime.cpp:3926:25: warning:
> unused variable 'Info' [-Wunused-variable]
>  FunctionType::ExtInfo Info;
>^
>
> I removed them in r318578. Can you double check I got it right?
>
> On Fri, Nov 17, 2017 at 9:57 AM, Alexey Bataev via cfe-commits
>  wrote:
>
> Author: abataev
>
> Date: Fri Nov 17 09:57:25 2017
>
> New Revision: 318536
>
>
> URL:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D318536%26view%3Drev=02%7C01%7Ca.bataev%40hotmail.com%7Cf4ef7fcb3bb84d89ab1c08d52e1e4eba%7C84df9e7fe9f640afb435%7C1%7C0%7C636465630063980137=uJ6ho4BYg2T%2F40DDY6R4fjyJXz6Do8zvKHKNp%2FUiByA%3D=0
>
> Log:
>
> [OPENMP] Codegen for `target simd` construct.
>
>
> Added codegen support for `target simd` directive.
>
>
> Added:
>
>cfe/trunk/test/OpenMP/target_simd_codegen.cpp
>
>cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
>
>cfe/trunk/test/OpenMP/target_simd_codegen_registration_naming.cpp
>
> Modified:
>
>cfe/trunk/lib/Basic/OpenMPKinds.cpp
>
>cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>
>cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>
>cfe/trunk/lib/CodeGen/CodeGenFunction.h
>
>cfe/trunk/lib/Sema/SemaOpenMP.cpp
>
>
> Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
>
> URL:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FBasic%2FOpenMPKinds.cpp%3Frev%3D318536%26r1%3D318535%26r2%3D318536%26view%3Ddiff=02%7C01%7Ca.bataev%40hotmail.com%7Cf4ef7fcb3bb84d89ab1c08d52e1e4eba%7C84df9e7fe9f640afb435%7C1%7C0%7C636465630063980137=R5LQErjcOslr6ByQ7X6lGD8LxymZERvN0V2unJOepJ4%3D=0
>
> ==
>
> --- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
>
> +++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Fri Nov 17 09:57:25 2017
>
> @@ -894,6 +894,9 @@ void clang::getOpenMPCaptureRegions(
>
>   case OMPD_teams_distribute:
>
> CaptureRegions.push_back(OMPD_teams);
>
> break;
>
> +  case OMPD_target_simd:
>
> +CaptureRegions.push_back(OMPD_target);
>
> +break;
>
>   case OMPD_teams:
>
>   case OMPD_simd:
>
>   case OMPD_for:
>
> @@ -909,7 +912,6 @@ void clang::getOpenMPCaptureRegions(
>
>   case OMPD_atomic:
>
>   case OMPD_target_data:
>
>   case OMPD_target:
>
> -  case OMPD_target_simd:
>
>   case OMPD_task:
>
>   case OMPD_taskloop:
>
>   case OMPD_taskloop_simd:
>
>
> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
>
> URL:
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fcfe%2Ftrunk%2Flib%2FCodeGen%2FCGOpenMPRuntime.cpp%3Frev%3D318536%26r1%3D318535%26r2%3D318536%26view%3Ddiff=02%7C01%7Ca.bataev%40hotmail.com%7Cf4ef7fcb3bb84d89ab1c08d52e1e4eba%7C84df9e7fe9f640afb435%7C1%7C0%7C636465630063980137=pO6lKXqeqrDLSGwVODPiyUK%2BQGaF0lkIrW3F%2BYA6rcE%3D=0
>
> ==
>
> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
>
> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Nov 17 09:57:25 2017
>
> @@ -7131,6 +7131,10 @@ void CGOpenMPRuntime::scanForTargetRegio
>
>   CodeGenFunction::EmitOMPTargetParallelForSimdDeviceFunction(
>
>   CGM, ParentName, cast(*S));
>
>   break;
>
> +case Stmt::OMPTargetSimdDirectiveClass:
>
> +  CodeGenFunction::EmitOMPTargetSimdDeviceFunction(
>
> +  CGM, ParentName, cast(*S));
>
> +  break;
>
> default:
>
>   llvm_unreachable("Unknown target directive for OpenMP device
> codegen.");
>
> }
>
>
> Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
>
> URL:
> 

[PATCH] D40108: [clang-tidy] Adding Fuchsia checkers to clang-tidy

2017-11-17 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:63
+
+  Warns if a function is declared or called with default arguments.
+

I think will be good idea to change to //function// to //function or method//. 
Same in documentation.



Comment at: docs/clang-tidy/checks/fuchsia-default-arguments.rst:8
+
+Example: The declaration:
+

I briefly look on other checks documentation, so will be good idea to use just 
//Example:// or //For example, the declaration:// . But will be good idea to 
hear opinion of native English speaker.


https://reviews.llvm.org/D40108



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


Re: r318536 - [OPENMP] Codegen for `target simd` construct.

2017-11-17 Thread Hans Wennborg via cfe-commits
I think this caused some unused variable warnings:

../tools/clang/lib/CodeGen/CGStmtOpenMP.cpp:360:25: warning: unused
variable 'ExtInfo' [-Wunused-variable]
  FunctionType::ExtInfo ExtInfo;
^
1 warning generated.
[3049/3507] Building CXX object
tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGStmt.cpp.o
../tools/clang/lib/CodeGen/CGStmt.cpp:2271:25: warning: unused
variable 'ExtInfo' [-Wunused-variable]
  FunctionType::ExtInfo ExtInfo;
^
1 warning generated.
[3068/3507] Building CXX object
tools/clang/lib/CodeGen/CMakeFiles/clangCodeGen.dir/CGOpenMPRuntime.cpp.o
../tools/clang/lib/CodeGen/CGOpenMPRuntime.cpp:3926:25: warning:
unused variable 'Info' [-Wunused-variable]
  FunctionType::ExtInfo Info;
^

I removed them in r318578. Can you double check I got it right?

On Fri, Nov 17, 2017 at 9:57 AM, Alexey Bataev via cfe-commits
 wrote:
> Author: abataev
> Date: Fri Nov 17 09:57:25 2017
> New Revision: 318536
>
> URL: http://llvm.org/viewvc/llvm-project?rev=318536=rev
> Log:
> [OPENMP] Codegen for `target simd` construct.
>
> Added codegen support for `target simd` directive.
>
> Added:
> cfe/trunk/test/OpenMP/target_simd_codegen.cpp
> cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
> cfe/trunk/test/OpenMP/target_simd_codegen_registration_naming.cpp
> Modified:
> cfe/trunk/lib/Basic/OpenMPKinds.cpp
> cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
> cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/Sema/SemaOpenMP.cpp
>
> Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=318536=318535=318536=diff
> ==
> --- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
> +++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Fri Nov 17 09:57:25 2017
> @@ -894,6 +894,9 @@ void clang::getOpenMPCaptureRegions(
>case OMPD_teams_distribute:
>  CaptureRegions.push_back(OMPD_teams);
>  break;
> +  case OMPD_target_simd:
> +CaptureRegions.push_back(OMPD_target);
> +break;
>case OMPD_teams:
>case OMPD_simd:
>case OMPD_for:
> @@ -909,7 +912,6 @@ void clang::getOpenMPCaptureRegions(
>case OMPD_atomic:
>case OMPD_target_data:
>case OMPD_target:
> -  case OMPD_target_simd:
>case OMPD_task:
>case OMPD_taskloop:
>case OMPD_taskloop_simd:
>
> Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=318536=318535=318536=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Nov 17 09:57:25 2017
> @@ -7131,6 +7131,10 @@ void CGOpenMPRuntime::scanForTargetRegio
>CodeGenFunction::EmitOMPTargetParallelForSimdDeviceFunction(
>CGM, ParentName, cast(*S));
>break;
> +case Stmt::OMPTargetSimdDirectiveClass:
> +  CodeGenFunction::EmitOMPTargetSimdDeviceFunction(
> +  CGM, ParentName, cast(*S));
> +  break;
>  default:
>llvm_unreachable("Unknown target directive for OpenMP device 
> codegen.");
>  }
>
> Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=318536=318535=318536=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Fri Nov 17 09:57:25 2017
> @@ -138,6 +138,10 @@ public:
>
>  } // namespace
>
> +static void emitCommonOMPTargetDirective(CodeGenFunction ,
> + const OMPExecutableDirective ,
> + const RegionCodeGenTy );
> +
>  LValue CodeGenFunction::EmitOMPSharedLValue(const Expr *E) {
>if (auto *OrigDRE = dyn_cast(E)) {
>  if (auto *OrigVD = dyn_cast(OrigDRE->getDecl())) {
> @@ -1536,83 +1540,90 @@ static void emitOMPLoopBodyWithStopPoint
>CGF.EmitStopPoint();
>  }
>
> -void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective ) {
> -  auto & = [](CodeGenFunction , PrePostActionTy &) {
> -OMPLoopScope PreInitScope(CGF, S);
> -// if (PreCond) {
> -//   for (IV in 0..LastIteration) BODY;
> -//   ;
> -// }
> -//
> -
> -// Emit: if (PreCond) - begin.
> -// If the condition constant folds and can be elided, avoid emitting the
> -// whole loop.
> -bool CondConstant;
> -llvm::BasicBlock *ContBlock = nullptr;
> -if (CGF.ConstantFoldsToSimpleInteger(S.getPreCond(), CondConstant)) {
> -  if (!CondConstant)
> -return;
> -} else {
> -  auto *ThenBlock = CGF.createBasicBlock("simd.if.then");
> -  

r318578 - Fix some -Wunused-variable warnings

2017-11-17 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Fri Nov 17 16:49:18 2017
New Revision: 318578

URL: http://llvm.org/viewvc/llvm-project?rev=318578=rev
Log:
Fix some -Wunused-variable warnings

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=318578=318577=318578=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Nov 17 16:49:18 2017
@@ -3923,7 +3923,6 @@ static llvm::Value *emitDestructorsFunct
 ImplicitParamDecl::Other);
   Args.push_back();
   Args.push_back();
-  FunctionType::ExtInfo Info;
   auto  =
   CGM.getTypes().arrangeBuiltinFunctionDeclaration(KmpInt32Ty, Args);
   auto *DestructorFnTy = CGM.getTypes().GetFunctionType(DestructorFnInfo);

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=318578=318577=318578=diff
==
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Fri Nov 17 16:49:18 2017
@@ -2268,7 +2268,6 @@ CodeGenFunction::GenerateCapturedStmtFun
   Args.append(CD->param_begin(), CD->param_end());
 
   // Create the function declaration.
-  FunctionType::ExtInfo ExtInfo;
   const CGFunctionInfo  =
 CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args);
   llvm::FunctionType *FuncLLVMTy = CGM.getTypes().GetFunctionType(FuncInfo);

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=318578=318577=318578=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Fri Nov 17 16:49:18 2017
@@ -357,7 +357,6 @@ static llvm::Function *emitOutlinedFunct
   CD->param_end());
 
   // Create the function declaration.
-  FunctionType::ExtInfo ExtInfo;
   const CGFunctionInfo  =
   CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, TargetArgs);
   llvm::FunctionType *FuncLLVMTy = CGM.getTypes().GetFunctionType(FuncInfo);


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


[PATCH] D40108: [clang-tidy] Adding Fuchsia checkers to clang-tidy

2017-11-17 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett added a comment.

In https://reviews.llvm.org/D40108#928224, @Eugene.Zelenko wrote:

>




> I think it should use project-specific prefix, since it's open source 
> project. Google may have different coding guidelines for other projects.

Reasonable. It makes sense to consider it on a check-by-check basis too, I'd 
think.


https://reviews.llvm.org/D40108



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


[PATCH] D40108: [clang-tidy] Adding Fuchsia checkers to clang-tidy

2017-11-17 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 123446.
juliehockett marked 2 inline comments as done.
juliehockett added a comment.

Updated docs and added tests to check class methods.


https://reviews.llvm.org/D40108

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/DefaultArgumentsCheck.cpp
  clang-tidy/fuchsia/DefaultArgumentsCheck.h
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-default-arguments.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/fuchsia-default-arguments.cpp

Index: test/clang-tidy/fuchsia-default-arguments.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-default-arguments.cpp
@@ -0,0 +1,27 @@
+// RUN: %check_clang_tidy %s fuchsia-default-arguments %t
+
+int foo(int value = 5) { return value; }
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: declaring functions which use default arguments is disallowed [fuchsia-default-arguments]
+
+int f() {
+  foo();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: calling functions which use default arguments is disallowed [fuchsia-default-arguments]
+  // CHECK-NEXT: note: the default parameter was declared here:
+  // CHECK-NEXT: int foo(int value = 5) { return value; }
+}
+
+// Negatives.
+int bar(int value) { return value; }
+
+int n() {
+  foo(0);
+  bar(0);
+}
+
+class Baz {
+public:
+  int a(int value = 5) { return value; }
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: declaring functions which use default arguments is disallowed [fuchsia-default-arguments]
+
+  int b(int value) { return value; }
+};
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -61,6 +61,7 @@
 ``cert-``  Checks related to CERT Secure Coding Guidelines.
 ``cppcoreguidelines-`` Checks related to C++ Core Guidelines.
 ``clang-analyzer-``Clang Static Analyzer checks.
+``fuchsia-``   Checks related to Fuchsia coding conventions.
 ``google-``Checks related to Google coding conventions.
 ``hicpp-`` Checks related to High Integrity C++ Coding Standard.
 ``llvm-``  Checks related to the LLVM coding conventions.
@@ -669,4 +670,3 @@
 * To apply suggested fixes ``-fix`` can be passed as an argument. This gathers
   all changes in a temporary directory and applies them. Passing ``-format``
   will run clang-format over changed lines.
-
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cppcoreguidelines-pro-type-vararg
cppcoreguidelines-slicing
cppcoreguidelines-special-member-functions
+   fuchsia-default-arguments
google-build-explicit-make-pair
google-build-namespaces
google-build-using-namespace
Index: docs/clang-tidy/checks/fuchsia-default-arguments.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-default-arguments.rst
@@ -0,0 +1,25 @@
+.. title:: clang-tidy - fuchsia-default-arguments
+
+fuchsia-default-arguments
+=
+
+Warns if a function is declared or called with default arguments.
+
+Example: The declaration:
+
+.. code-block:: c++
+
+  int foo(int value = 5) { return value; }
+
+will cause a warning.
+
+If a function with default arguments is already defined, calling it with no
+arguments will also cause a warning. Calling it without defaults will not cause
+a warning:
+
+.. code-block:: c++
+
+  foo();  // warning
+  foo(0); // no warning
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,6 +57,11 @@
 Improvements to clang-tidy
 --
 
+- New `fuchsia-default-arguments
+  `_ check
+
+  Warns if a function is declared or called with default arguments.
+
 - New `objc-property-declaration
   `_ check
 
@@ -67,8 +72,8 @@
 - New `google-objc-global-variable-declaration
   `_ check
 
-  Add new check for Objective-C code to ensure global 
-  variables follow the naming convention of 'k[A-Z].*' (for constants) 
+  Add new check for Objective-C code to ensure global
+  variables follow the naming convention of 'k[A-Z].*' (for constants)
   or 'g[A-Z].*' (for variables).
 
 - New module `objc` for Objective-C style checks.
@@ 

[PATCH] D40195: [libunwind][CMake] Provide option to disable instalation of the library

2017-11-17 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318569: [libunwind][CMake] Provide option to disable 
instalation of the library (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D40195?vs=123413=123440#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40195

Files:
  libunwind/trunk/CMakeLists.txt
  libunwind/trunk/src/CMakeLists.txt


Index: libunwind/trunk/src/CMakeLists.txt
===
--- libunwind/trunk/src/CMakeLists.txt
+++ libunwind/trunk/src/CMakeLists.txt
@@ -132,7 +132,16 @@
 # Add a meta-target for both libraries.
 add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
 
-install(TARGETS ${LIBUNWIND_TARGETS}
-  LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX})
+if (LIBUNWIND_INSTALL_LIBRARY)
+  install(TARGETS ${LIBUNWIND_TARGETS}
+LIBRARY DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
+ARCHIVE DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
+endif()
 
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
+  add_custom_target(install-unwind
+DEPENDS unwind
+COMMAND "${CMAKE_COMMAND}"
+-DCMAKE_INSTALL_COMPONENT=unwind
+-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
+endif()
Index: libunwind/trunk/CMakeLists.txt
===
--- libunwind/trunk/CMakeLists.txt
+++ libunwind/trunk/CMakeLists.txt
@@ -135,6 +135,7 @@
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")


Index: libunwind/trunk/src/CMakeLists.txt
===
--- libunwind/trunk/src/CMakeLists.txt
+++ libunwind/trunk/src/CMakeLists.txt
@@ -132,7 +132,16 @@
 # Add a meta-target for both libraries.
 add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
 
-install(TARGETS ${LIBUNWIND_TARGETS}
-  LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX})
+if (LIBUNWIND_INSTALL_LIBRARY)
+  install(TARGETS ${LIBUNWIND_TARGETS}
+LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
+ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
+endif()
 
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
+  add_custom_target(install-unwind
+DEPENDS unwind
+COMMAND "${CMAKE_COMMAND}"
+-DCMAKE_INSTALL_COMPONENT=unwind
+-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
+endif()
Index: libunwind/trunk/CMakeLists.txt
===
--- libunwind/trunk/CMakeLists.txt
+++ libunwind/trunk/CMakeLists.txt
@@ -135,6 +135,7 @@
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r318569 - [libunwind][CMake] Provide option to disable instalation of the library

2017-11-17 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Nov 17 15:29:46 2017
New Revision: 318569

URL: http://llvm.org/viewvc/llvm-project?rev=318569=rev
Log:
[libunwind][CMake] Provide option to disable instalation of the library

This is useful in cases where we only build static library and
libunwind.a is combined with libc++abi.a into a single archive in which
case we don't want to have libunwind.a installed separately. The same
option is already provided by libcxx CMake build.

This change also adds the install-unwind target for consistency with the
libcxxabi and libcxx CMake build.

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

Modified:
libunwind/trunk/CMakeLists.txt
libunwind/trunk/src/CMakeLists.txt

Modified: libunwind/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/CMakeLists.txt?rev=318569=318568=318569=diff
==
--- libunwind/trunk/CMakeLists.txt (original)
+++ libunwind/trunk/CMakeLists.txt Fri Nov 17 15:29:46 2017
@@ -135,6 +135,7 @@ option(LIBUNWIND_INCLUDE_DOCS "Build the
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

Modified: libunwind/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/CMakeLists.txt?rev=318569=318568=318569=diff
==
--- libunwind/trunk/src/CMakeLists.txt (original)
+++ libunwind/trunk/src/CMakeLists.txt Fri Nov 17 15:29:46 2017
@@ -132,7 +132,16 @@ endif()
 # Add a meta-target for both libraries.
 add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
 
-install(TARGETS ${LIBUNWIND_TARGETS}
-  LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX})
+if (LIBUNWIND_INSTALL_LIBRARY)
+  install(TARGETS ${LIBUNWIND_TARGETS}
+LIBRARY DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
+ARCHIVE DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
+endif()
 
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
+  add_custom_target(install-unwind
+DEPENDS unwind
+COMMAND "${CMAKE_COMMAND}"
+-DCMAKE_INSTALL_COMPONENT=unwind
+-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
+endif()


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


[PATCH] D40194: [libcxxabi][CMake] Provide option to disable installing of the library

2017-11-17 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318568: [libcxxabi][CMake] Provide option to disable 
installing of the library (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D40194?vs=123412=123439#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40194

Files:
  libcxxabi/trunk/CMakeLists.txt
  libcxxabi/trunk/src/CMakeLists.txt


Index: libcxxabi/trunk/CMakeLists.txt
===
--- libcxxabi/trunk/CMakeLists.txt
+++ libcxxabi/trunk/CMakeLists.txt
@@ -69,6 +69,7 @@
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit 
tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
Index: libcxxabi/trunk/src/CMakeLists.txt
===
--- libcxxabi/trunk/src/CMakeLists.txt
+++ libcxxabi/trunk/src/CMakeLists.txt
@@ -179,12 +179,14 @@
 # Add a meta-target for both libraries.
 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
 
-install(TARGETS ${LIBCXXABI_TARGETS}
-  LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  )
+if (LIBCXXABI_INSTALL_LIBRARY)
+  install(TARGETS ${LIBCXXABI_TARGETS}
+LIBRARY DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+ARCHIVE DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+)
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
   add_custom_target(install-cxxabi
 DEPENDS cxxabi
 COMMAND "${CMAKE_COMMAND}"


Index: libcxxabi/trunk/CMakeLists.txt
===
--- libcxxabi/trunk/CMakeLists.txt
+++ libcxxabi/trunk/CMakeLists.txt
@@ -69,6 +69,7 @@
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
Index: libcxxabi/trunk/src/CMakeLists.txt
===
--- libcxxabi/trunk/src/CMakeLists.txt
+++ libcxxabi/trunk/src/CMakeLists.txt
@@ -179,12 +179,14 @@
 # Add a meta-target for both libraries.
 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
 
-install(TARGETS ${LIBCXXABI_TARGETS}
-  LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
-  ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
-  )
+if (LIBCXXABI_INSTALL_LIBRARY)
+  install(TARGETS ${LIBCXXABI_TARGETS}
+LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+)
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
   add_custom_target(install-cxxabi
 DEPENDS cxxabi
 COMMAND "${CMAKE_COMMAND}"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r318568 - [libcxxabi][CMake] Provide option to disable installing of the library

2017-11-17 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Nov 17 15:25:09 2017
New Revision: 318568

URL: http://llvm.org/viewvc/llvm-project?rev=318568=rev
Log:
[libcxxabi][CMake] Provide option to disable installing of the library

This is useful in cases where we only build static library and
libc++abi.a is combined with libc++.a into a single archive in which
case we don't want to have libc++abi.a installed separately. The same
option is already provided by libcxx CMake build.

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

Modified:
libcxxabi/trunk/CMakeLists.txt
libcxxabi/trunk/src/CMakeLists.txt

Modified: libcxxabi/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/CMakeLists.txt?rev=318568=318567=318568=diff
==
--- libcxxabi/trunk/CMakeLists.txt (original)
+++ libcxxabi/trunk/CMakeLists.txt Fri Nov 17 15:25:09 2017
@@ -69,6 +69,7 @@ option(LIBCXXABI_BUILD_32_BITS "Build 32
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit 
tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=318568=318567=318568=diff
==
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Fri Nov 17 15:25:09 2017
@@ -179,12 +179,14 @@ endif()
 # Add a meta-target for both libraries.
 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
 
-install(TARGETS ${LIBCXXABI_TARGETS}
-  LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  )
+if (LIBCXXABI_INSTALL_LIBRARY)
+  install(TARGETS ${LIBCXXABI_TARGETS}
+LIBRARY DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+ARCHIVE DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+)
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
   add_custom_target(install-cxxabi
 DEPENDS cxxabi
 COMMAND "${CMAKE_COMMAND}"


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


[PATCH] D39964: Change code owner for Clang Static Analyzer to Devin Coughlin.

2017-11-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318567: Change code owner for Clang Static Analyzer to Devin 
Coughlin. (authored by zaks).

Changed prior to commit:
  https://reviews.llvm.org/D39964?vs=122678=123435#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D39964

Files:
  cfe/trunk/CODE_OWNERS.TXT


Index: cfe/trunk/CODE_OWNERS.TXT
===
--- cfe/trunk/CODE_OWNERS.TXT
+++ cfe/trunk/CODE_OWNERS.TXT
@@ -25,6 +25,10 @@
 E: echri...@gmail.com
 D: Debug Information, inline assembly
 
+N: Devin Coughlin
+E: dcough...@apple.com
+D: Clang Static Analyzer
+
 N: Doug Gregor
 E: dgre...@apple.com
 D: Emeritus owner
@@ -41,10 +45,6 @@
 E: an...@korobeynikov.info
 D: Exception handling, Windows codegen, ARM EABI
 
-N: Anna Zaks
-E: ga...@apple.com
-D: Clang Static Analyzer
-
 N: John McCall
 E: rjmcc...@apple.com
 D: Clang LLVM IR generation


Index: cfe/trunk/CODE_OWNERS.TXT
===
--- cfe/trunk/CODE_OWNERS.TXT
+++ cfe/trunk/CODE_OWNERS.TXT
@@ -25,6 +25,10 @@
 E: echri...@gmail.com
 D: Debug Information, inline assembly
 
+N: Devin Coughlin
+E: dcough...@apple.com
+D: Clang Static Analyzer
+
 N: Doug Gregor
 E: dgre...@apple.com
 D: Emeritus owner
@@ -41,10 +45,6 @@
 E: an...@korobeynikov.info
 D: Exception handling, Windows codegen, ARM EABI
 
-N: Anna Zaks
-E: ga...@apple.com
-D: Clang Static Analyzer
-
 N: John McCall
 E: rjmcc...@apple.com
 D: Clang LLVM IR generation
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r318567 - Change code owner for Clang Static Analyzer to Devin Coughlin.

2017-11-17 Thread Anna Zaks via cfe-commits
Author: zaks
Date: Fri Nov 17 15:19:04 2017
New Revision: 318567

URL: http://llvm.org/viewvc/llvm-project?rev=318567=rev
Log:
Change code owner for Clang Static Analyzer to Devin Coughlin.

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

Modified:
cfe/trunk/CODE_OWNERS.TXT

Modified: cfe/trunk/CODE_OWNERS.TXT
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CODE_OWNERS.TXT?rev=318567=318566=318567=diff
==
--- cfe/trunk/CODE_OWNERS.TXT (original)
+++ cfe/trunk/CODE_OWNERS.TXT Fri Nov 17 15:19:04 2017
@@ -25,6 +25,10 @@ N: Eric Christopher
 E: echri...@gmail.com
 D: Debug Information, inline assembly
 
+N: Devin Coughlin
+E: dcough...@apple.com
+D: Clang Static Analyzer
+
 N: Doug Gregor
 E: dgre...@apple.com
 D: Emeritus owner
@@ -41,10 +45,6 @@ N: Anton Korobeynikov
 E: an...@korobeynikov.info
 D: Exception handling, Windows codegen, ARM EABI
 
-N: Anna Zaks
-E: ga...@apple.com
-D: Clang Static Analyzer
-
 N: John McCall
 E: rjmcc...@apple.com
 D: Clang LLVM IR generation


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


[PATCH] D39930: [CMake] Use libc++ and compiler-rt as default libraries in Fuchsia toolchain

2017-11-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 123432.

Repository:
  rL LLVM

https://reviews.llvm.org/D39930

Files:
  cmake/caches/Fuchsia-stage2.cmake


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -17,6 +17,8 @@
   set(LLVM_ENABLE_LLD ON CACHE BOOL "")
   set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 endif()
+set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
+set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 
 # This is a "Does your linker support it?" option that only applies
 # to x86-64 ELF targets.  All Fuchsia target linkers do support it.
@@ -39,13 +41,24 @@
   set(BUILTINS_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 endforeach()
 
+set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBUNWIND_INSTALL_LIBRARY OFF CACHE BOOL "")
+set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
+set(LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
+set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+
 set(LLVM_RUNTIME_TARGETS 
"default;x86_64-fuchsia;aarch64-fuchsia;x86_64-fuchsia-asan:x86_64-fuchsia;aarch64-fuchsia-asan:aarch64-fuchsia"
 CACHE STRING "")
 foreach(target x86_64;aarch64)
   set(RUNTIMES_${target}-fuchsia_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL 
"")
   set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
   set(RUNTIMES_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
   set(RUNTIMES_${target}-fuchsia_UNIX 1 CACHE BOOL "")
-  set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")


Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -17,6 +17,8 @@
   set(LLVM_ENABLE_LLD ON CACHE BOOL "")
   set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 endif()
+set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
+set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
 
 # This is a "Does your linker support it?" option that only applies
 # to x86-64 ELF targets.  All Fuchsia target linkers do support it.
@@ -39,13 +41,24 @@
   set(BUILTINS_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
 endforeach()
 
+set(LIBUNWIND_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBUNWIND_INSTALL_LIBRARY OFF CACHE BOOL "")
+set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+set(LIBCXXABI_ENABLE_STATIC_UNWINDER ON CACHE BOOL "")
+set(LIBCXXABI_INSTALL_LIBRARY OFF CACHE BOOL "")
+set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+set(LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
+set(LIBCXX_ENABLE_STATIC_ABI_LIBRARY ON CACHE BOOL "")
+
 set(LLVM_RUNTIME_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia;x86_64-fuchsia-asan:x86_64-fuchsia;aarch64-fuchsia-asan:aarch64-fuchsia" CACHE STRING "")
 foreach(target x86_64;aarch64)
   set(RUNTIMES_${target}-fuchsia_CMAKE_BUILD_WITH_INSTALL_RPATH ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} CACHE PATH "")
   set(RUNTIMES_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
   set(RUNTIMES_${target}-fuchsia_UNIX 1 CACHE BOOL "")
-  set(RUNTIMES_${target}-fuchsia_LLVM_ENABLE_LIBCXX ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBUNWIND_ENABLE_STATIC OFF CACHE BOOL "")
   set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] r318563 - [CMake][libcxxabi] Support merging objects when statically linking unwinder

2017-11-17 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Fri Nov 17 14:49:39 2017
New Revision: 318563

URL: http://llvm.org/viewvc/llvm-project?rev=318563=rev
Log:
[CMake][libcxxabi] Support merging objects when statically linking unwinder

When using LLVM unwinder and static unwinder option is set, merge
libunwind and libc++abi objects into a single archive. libc++ already
supports merging libc++abi.a and libc++.a into a single archive; with
this change, it is possible to also include libunwind.a in the same
archive which is useful when doing static link and using libc++ as
a default C++ library and compiler-rt as a default runtime library.

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

Modified:
libcxxabi/trunk/src/CMakeLists.txt

Modified: libcxxabi/trunk/src/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/CMakeLists.txt?rev=318563=318562=318563=diff
==
--- libcxxabi/trunk/src/CMakeLists.txt (original)
+++ libcxxabi/trunk/src/CMakeLists.txt Fri Nov 17 14:49:39 2017
@@ -151,7 +151,13 @@ endif()
 
 # Build the static library.
 if (LIBCXXABI_ENABLE_STATIC)
-  add_library(cxxabi_static STATIC $)
+  set(cxxabi_static_sources $)
+  if (LIBCXXABI_USE_LLVM_UNWINDER AND LIBCXXABI_ENABLE_STATIC_UNWINDER)
+if (TARGET unwind_static OR HAVE_LIBUNWIND)
+  list(APPEND cxxabi_static_sources $)
+endif()
+  endif()
+  add_library(cxxabi_static STATIC ${cxxabi_static_sources})
   target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES})
   set_target_properties(cxxabi_static
 PROPERTIES


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


[PATCH] D39953: [CodeGen] Do not lookup for cached TBAA metadata nodes twice

2017-11-17 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I think having a primary function that handles the caching logic makes some 
sense.  I think there might be some cases that intentionally don't cache their 
normal result, though, so it might be harder than you think.  Up to you whether 
you want to continue.


Repository:
  rL LLVM

https://reviews.llvm.org/D39953



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


[PATCH] D40144: Implement `std::launder`

2017-11-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists updated this revision to Diff 123422.
mclow.lists marked an inline comment as done.
mclow.lists added a comment.

Move the `launder` function into the main libc++ namespace.
Call `__builtin_launder` when available.
Check to see when it's available (for gcc and clang)


https://reviews.llvm.org/D40144

Files:
  include/__config
  include/new
  
test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
  test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
  www/cxx1z_status.html

Index: www/cxx1z_status.html
===
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -104,6 +104,7 @@
 	https://wg21.link/p0083r3;>p0083r3LWGSplicing Maps and SetsOulu
 	https://wg21.link/p0084r2;>p0084r2LWGEmplace Return TypeOuluComplete4.0
 	https://wg21.link/p0088r3;>p0088r3LWGVariant: a type-safe union for C++17OuluComplete4.0
+	https://wg21.link/p0137r1;>p0137r1CWGCore Issue 1776: Replacement of class objects containing reference membersOuluComplete6.0
 	https://wg21.link/p0163r0;>p0163r0LWGshared_ptr::weak_typeOuluComplete3.9
 	https://wg21.link/p0174r2;>p0174r2LWGDeprecating Vestigial Library Parts in C++17Oulu
 	https://wg21.link/p0175r1;>p0175r1LWGSynopses for the C libraryOulu
Index: test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.types.fail.cpp
@@ -0,0 +1,34 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+// The program is ill-formed if T is a function type or cv void.
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+void foo() {}
+
+int main ()
+{
+void *p = nullptr;
+(void) std::launder((   void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((const  void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((  volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+(void) std::launder((const volatile void *) nullptr);  // expected-error-re@new:* {{static_assert failed{{.*}} "Can't launder cv-void"}}
+
+(void) std::launder(foo);  // expected-error-re@new:* 1 {{static_assert failed{{.*}} "Can't launder functions"}}
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.pass.cpp
@@ -0,0 +1,35 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+
+// 
+
+// template  constexpr T* launder(T* p) noexcept;
+
+// UNSUPPORTED: c++98, c++03, c++11, c++14
+
+#include 
+#include 
+
+#include "test_macros.h"
+
+constexpr int gi = 5;
+constexpr float gf = 8.f;
+
+int main() {
+	static_assert(std::launder() == , "" );
+	static_assert(std::launder() == , "" );
+
+  	const int *i = 
+  	const float *f = 
+static_assert(std::is_same::value, "");
+static_assert(std::is_same::value, "");
+
+	assert(std::launder(i) == i);
+	assert(std::launder(f) == f);
+}
Index: test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
===
--- test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
+++ test/std/language.support/support.dynamic/ptr.launder/launder.nodiscard.fail.cpp
@@ -0,0 +1,27 @@
+// -*- C++ -*-
+//===--===//
+//
+// 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.

[PATCH] D40198: [CUDA] Tweak CUDA wrappers to make cuda-9 work with libc++

2017-11-17 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added a subscriber: sanjoy.
Herald added a reviewer: EricWF.

CUDA-9 headers check for specific libc++ version and ifdef out
some of the definitions we need if LIBCPP_VERSION >= 3800.


https://reviews.llvm.org/D40198

Files:
  clang/lib/Headers/__clang_cuda_runtime_wrapper.h


Index: clang/lib/Headers/__clang_cuda_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ clang/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -270,12 +270,18 @@
 // include guard from math.h wrapper from libstdc++. We have to undo the header
 // guard temporarily to get the definitions we need.
 #pragma push_macro("_GLIBCXX_MATH_H")
+#pragma push_macro("_LIBCPP_VERSION")
 #if CUDA_VERSION >= 9000
 #undef _GLIBCXX_MATH_H
+// We also need to undo another guard that checks for libc++ 3.8+
+#ifdef _LIBCPP_VERSION
+#define _LIBCPP_VERSION 3700
+#endif
 #endif
 
 #include "math_functions.hpp"
 #pragma pop_macro("_GLIBCXX_MATH_H")
+#pragma pop_macro("_LIBCPP_VERSION")
 #pragma pop_macro("__GNUC__")
 #pragma pop_macro("signbit")
 


Index: clang/lib/Headers/__clang_cuda_runtime_wrapper.h
===
--- clang/lib/Headers/__clang_cuda_runtime_wrapper.h
+++ clang/lib/Headers/__clang_cuda_runtime_wrapper.h
@@ -270,12 +270,18 @@
 // include guard from math.h wrapper from libstdc++. We have to undo the header
 // guard temporarily to get the definitions we need.
 #pragma push_macro("_GLIBCXX_MATH_H")
+#pragma push_macro("_LIBCPP_VERSION")
 #if CUDA_VERSION >= 9000
 #undef _GLIBCXX_MATH_H
+// We also need to undo another guard that checks for libc++ 3.8+
+#ifdef _LIBCPP_VERSION
+#define _LIBCPP_VERSION 3700
+#endif
 #endif
 
 #include "math_functions.hpp"
 #pragma pop_macro("_GLIBCXX_MATH_H")
+#pragma pop_macro("_LIBCPP_VERSION")
 #pragma pop_macro("__GNUC__")
 #pragma pop_macro("signbit")
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40144: Implement `std::launder`

2017-11-17 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists marked an inline comment as done.
mclow.lists added inline comments.



Comment at: include/new:174
+_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
+constexpr _Tp* launder(_Tp* __p) noexcept { return __p;}
+#endif

efriedma wrote:
> efriedma wrote:
> > How is the compiler supposed to know that "std::__1::launder()" has special 
> > semantics?
> Oh, wait, is this actually not in the __1 namespace?  Sort of hard to tell 
> because the patch wasn't posted with enough context.
> 
> It isn't exactly great to special-case functions named "std::launder"... but 
> wouldn't be the first name in the std namespace which has special compiler 
> semantics.
I'm about to move it into the _1 namespace. Since it's calling a compiler 
intrinsic, it doesn't need to be in a special place.



https://reviews.llvm.org/D40144



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


r318562 - [cmake] Use llvm-lit directory when provided for stand-alone build

2017-11-17 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Fri Nov 17 14:21:23 2017
New Revision: 318562

URL: http://llvm.org/viewvc/llvm-project?rev=318562=rev
Log:
[cmake] Use llvm-lit directory when provided for stand-alone build

After the recent lit test changes, clang attempts to run its tests
via llvm-lit by default. However, the llvm-lit binary is not present
when performing stand-alone build resulting in a failure out of the box.

To solve that, add the llvm-lit directory to CMake when performing
a stand-alone build and LLVM sources are provided. This includes
the CMake rules generating the llvm-lit binary and effectively makes
it possible for clang to use it.

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

Modified:
cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=318562=318561=318562=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Fri Nov 17 14:21:23 2017
@@ -132,6 +132,9 @@ Please install Python or specify the PYT
 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
   # Note: path not really used, except for checking if lit was found
   set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
+  if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
+  endif()
   if(NOT LLVM_UTILS_PROVIDED)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)


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


[PATCH] D40142: [cmake] Use llvm-lit directory when provided for stand-alone build

2017-11-17 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318562: [cmake] Use llvm-lit directory when provided for 
stand-alone build (authored by mgorny).

Changed prior to commit:
  https://reviews.llvm.org/D40142?vs=123219=123419#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40142

Files:
  cfe/trunk/CMakeLists.txt


Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -132,6 +132,9 @@
 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
   # Note: path not really used, except for checking if lit was found
   set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
+  if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
+  endif()
   if(NOT LLVM_UTILS_PROVIDED)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)


Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -132,6 +132,9 @@
 if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
   # Note: path not really used, except for checking if lit was found
   set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
+  if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/llvm-lit)
+add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/llvm-lit utils/llvm-lit)
+  endif()
   if(NOT LLVM_UTILS_PROVIDED)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
 add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/count utils/count)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r318559 - Fix coverage test on Windows bot

2017-11-17 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Nov 17 13:55:23 2017
New Revision: 318559

URL: http://llvm.org/viewvc/llvm-project?rev=318559=rev
Log:
Fix coverage test on Windows bot

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

Modified: cfe/trunk/test/Driver/coverage.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/coverage.c?rev=318559=318558=318559=diff
==
--- cfe/trunk/test/Driver/coverage.c (original)
+++ cfe/trunk/test/Driver/coverage.c Fri Nov 17 13:55:23 2017
@@ -1,7 +1,7 @@
 // Test coverage flag.
 // REQUIRES: system-windows
 //
-// RUN: %clang_cl -### -coverage %s -o foo/bar.o 2>&1 | FileCheck 
-check-prefix=CLANG-CL-COVERAGE %s
+// RUN: %clang_cl -Wno-msvc-not-found -### -coverage %s -o foo/bar.o 2>&1 | 
FileCheck -check-prefix=CLANG-CL-COVERAGE %s
 // CLANG-CL-COVERAGE-NOT: error:
 // CLANG-CL-COVERAGE-NOT: warning:
 // CLANG-CL-COVERAGE-NOT: argument unused


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


[PATCH] D40195: [libunwind][CMake] Provide option to disable instalation of the library

2017-11-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D40195



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


[PATCH] D40194: [libcxxabi][CMake] Provide option to disable installing of the library

2017-11-17 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D40194



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


[PATCH] D40195: [libunwind][CMake] Provide option to disable instalation of the library

2017-11-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added a subscriber: mgorny.

This is useful in cases where we only build static library and
libunwind.a is combined with libc++abi.a into a single archive in which
case we don't want to have libunwind.a installed separately. The same
option is already provided by libcxx CMake build.

  

This change also adds the install-unwind target for consistency with the
libcxxabi and libcxx CMake build.


Repository:
  rL LLVM

https://reviews.llvm.org/D40195

Files:
  CMakeLists.txt
  src/CMakeLists.txt


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -132,7 +132,16 @@
 # Add a meta-target for both libraries.
 add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
 
-install(TARGETS ${LIBUNWIND_TARGETS}
-  LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX})
+if (LIBUNWIND_INSTALL_LIBRARY)
+  install(TARGETS ${LIBUNWIND_TARGETS}
+LIBRARY DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
+ARCHIVE DESTINATION 
${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
+endif()
 
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
+  add_custom_target(install-unwind
+DEPENDS unwind
+COMMAND "${CMAKE_COMMAND}"
+-DCMAKE_INSTALL_COMPONENT=unwind
+-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
+endif()
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -135,6 +135,7 @@
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -132,7 +132,16 @@
 # Add a meta-target for both libraries.
 add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
 
-install(TARGETS ${LIBUNWIND_TARGETS}
-  LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX}
-  ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX})
+if (LIBUNWIND_INSTALL_LIBRARY)
+  install(TARGETS ${LIBUNWIND_TARGETS}
+LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind
+ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind)
+endif()
 
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY)
+  add_custom_target(install-unwind
+DEPENDS unwind
+COMMAND "${CMAKE_COMMAND}"
+-DCMAKE_INSTALL_COMPONENT=unwind
+-P "${LIBCXXABI_BINARY_DIR}/cmake_install.cmake")
+endif()
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -135,6 +135,7 @@
 
 set(LIBUNWIND_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBUNWIND_INSTALL_LIBRARY "Install the libunwind library." ON)
 set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40194: [libcxxabi][CMake] Provide option to disable installing of the library

2017-11-17 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
Herald added a subscriber: mgorny.

This is useful in cases where we only build static library and
libc++abi.a is combined with libc++.a into a single archive in which
case we don't want to have libc++abi.a installed separately. The same
option is already provided by libcxx CMake build.


Repository:
  rL LLVM

https://reviews.llvm.org/D40194

Files:
  CMakeLists.txt
  src/CMakeLists.txt


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -173,12 +173,14 @@
 # Add a meta-target for both libraries.
 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
 
-install(TARGETS ${LIBCXXABI_TARGETS}
-  LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} 
COMPONENT cxxabi
-  )
+if (LIBCXXABI_INSTALL_LIBRARY)
+  install(TARGETS ${LIBCXXABI_TARGETS}
+LIBRARY DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+ARCHIVE DESTINATION 
${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+)
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
   add_custom_target(install-cxxabi
 DEPENDS cxxabi
 COMMAND "${CMAKE_COMMAND}"
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -69,6 +69,7 @@
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit 
tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross 
compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -173,12 +173,14 @@
 # Add a meta-target for both libraries.
 add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS})
 
-install(TARGETS ${LIBCXXABI_TARGETS}
-  LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
-  ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
-  )
+if (LIBCXXABI_INSTALL_LIBRARY)
+  install(TARGETS ${LIBCXXABI_TARGETS}
+LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi
+)
+endif()
 
-if (NOT CMAKE_CONFIGURATION_TYPES)
+if (NOT CMAKE_CONFIGURATION_TYPES AND LIBCXXABI_INSTALL_LIBRARY)
   add_custom_target(install-cxxabi
 DEPENDS cxxabi
 COMMAND "${CMAKE_COMMAND}"
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -69,6 +69,7 @@
 option(LIBCXXABI_INCLUDE_TESTS "Generate build targets for the libc++abi unit tests." ${LLVM_INCLUDE_TESTS})
 set(LIBCXXABI_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING
 "Define suffix of library directory name (32/64)")
+option(LIBCXXABI_INSTALL_LIBRARY "Install the libc++abi library." ON)
 set(LIBCXXABI_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
 set(LIBCXXABI_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
 set(LIBCXXABI_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40185: Loosen -Wempty-body warning.

2017-11-17 Thread Reid Kleckner via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318556: Loosen -Wempty-body warning (authored by rnk).

Changed prior to commit:
  https://reviews.llvm.org/D40185?vs=123406=123410#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40185

Files:
  cfe/trunk/include/clang/Sema/Sema.h
  cfe/trunk/lib/Parse/ParseStmt.cpp
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/lib/Sema/SemaStmt.cpp
  cfe/trunk/test/SemaCXX/warn-empty-body.cpp


Index: cfe/trunk/test/SemaCXX/warn-empty-body.cpp
===
--- cfe/trunk/test/SemaCXX/warn-empty-body.cpp
+++ cfe/trunk/test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} 
expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} 
expected-note{{separate line}}}
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11821,7 +11821,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);
Index: cfe/trunk/lib/Parse/ParseStmt.cpp
===
--- cfe/trunk/lib/Parse/ParseStmt.cpp
+++ cfe/trunk/lib/Parse/ParseStmt.cpp
@@ -1101,6 +1101,7 @@
 
   // Otherwise the condition is valid or the rparen is present.
   T.consumeClose();
+  Cond.setRParenLoc(T.getCloseLocation());
 
   // Check for extraneous ')'s to catch things like "if (foo())) {".  We know
   // that all callers are looking for a statement after the condition, so ")"
Index: cfe/trunk/include/clang/Sema/Sema.h
===
--- cfe/trunk/include/clang/Sema/Sema.h
+++ cfe/trunk/include/clang/Sema/Sema.h
@@ -9690,6 +9690,7 @@
   class ConditionResult {
 Decl *ConditionVar;
 FullExprArg Condition;
+SourceLocation RParenLoc;
 bool Invalid;
 bool HasKnownValue;
 bool KnownValue;
@@ -9713,6 +9714,9 @@
   return std::make_pair(cast_or_null(ConditionVar),
 Condition.get());
 }
+
+void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
+
 llvm::Optional getKnownValue() const {
   if (!HasKnownValue)
 return None;


Index: cfe/trunk/test/SemaCXX/warn-empty-body.cpp
===
--- cfe/trunk/test/SemaCXX/warn-empty-body.cpp
+++ cfe/trunk/test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} expected-note{{separate line}}}
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11821,7 +11821,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: cfe/trunk/lib/Sema/SemaStmt.cpp
===
--- cfe/trunk/lib/Sema/SemaStmt.cpp
+++ cfe/trunk/lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, 

r318556 - Loosen -Wempty-body warning

2017-11-17 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Nov 17 13:33:28 2017
New Revision: 318556

URL: http://llvm.org/viewvc/llvm-project?rev=318556=rev
Log:
Loosen -Wempty-body warning

Do not show it when `if` or `else` come from macros.
E.g.,

#define USED(A) if (A); else
#define SOME_IF(A) if (A)

void test() {
  // No warnings are shown in those cases now.
  USED(0);
  SOME_IF(0);
}

Patch by Ilya Biryukov!

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/SemaCXX/warn-empty-body.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=318556=318555=318556=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Nov 17 13:33:28 2017
@@ -9690,6 +9690,7 @@ public:
   class ConditionResult {
 Decl *ConditionVar;
 FullExprArg Condition;
+SourceLocation RParenLoc;
 bool Invalid;
 bool HasKnownValue;
 bool KnownValue;
@@ -9713,6 +9714,9 @@ public:
   return std::make_pair(cast_or_null(ConditionVar),
 Condition.get());
 }
+
+void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
+
 llvm::Optional getKnownValue() const {
   if (!HasKnownValue)
 return None;

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=318556=318555=318556=diff
==
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Fri Nov 17 13:33:28 2017
@@ -1101,6 +1101,7 @@ bool Parser::ParseParenExprOrCondition(S
 
   // Otherwise the condition is valid or the rparen is present.
   T.consumeClose();
+  Cond.setRParenLoc(T.getCloseLocation());
 
   // Check for extraneous ')'s to catch things like "if (foo())) {".  We know
   // that all callers are looking for a statement after the condition, so ")"

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=318556=318555=318556=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 17 13:33:28 2017
@@ -11821,7 +11821,7 @@ static bool ShouldDiagnoseEmptyStmtBody(
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=318556=318555=318556=diff
==
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Fri Nov 17 13:33:28 2017
@@ -530,8 +530,7 @@ Sema::ActOnIfStmt(SourceLocation IfLoc,
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);

Modified: cfe/trunk/test/SemaCXX/warn-empty-body.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-empty-body.cpp?rev=318556=318555=318556=diff
==
--- cfe/trunk/test/SemaCXX/warn-empty-body.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-empty-body.cpp Fri Nov 17 13:33:28 2017
@@ -301,3 +301,14 @@ void test7(int x, int y) {
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} 
expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} 
expected-note{{separate line}}}
+}


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


[PATCH] D40185: Loosen -Wempty-body warning.

2017-11-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk updated this revision to Diff 123406.
rnk added a comment.

- minor tweak


https://reviews.llvm.org/D40185

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/SemaCXX/warn-empty-body.cpp


Index: clang/test/SemaCXX/warn-empty-body.cpp
===
--- clang/test/SemaCXX/warn-empty-body.cpp
+++ clang/test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} 
expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} 
expected-note{{separate line}}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11815,7 +11815,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1101,6 +1101,7 @@
 
   // Otherwise the condition is valid or the rparen is present.
   T.consumeClose();
+  Cond.setRParenLoc(T.getCloseLocation());
 
   // Check for extraneous ')'s to catch things like "if (foo())) {".  We know
   // that all callers are looking for a statement after the condition, so ")"
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -9690,6 +9690,7 @@
   class ConditionResult {
 Decl *ConditionVar;
 FullExprArg Condition;
+SourceLocation RParenLoc;
 bool Invalid;
 bool HasKnownValue;
 bool KnownValue;
@@ -9713,6 +9714,9 @@
   return std::make_pair(cast_or_null(ConditionVar),
 Condition.get());
 }
+
+void setRParenLoc(SourceLocation Loc) { RParenLoc = Loc; }
+
 llvm::Optional getKnownValue() const {
   if (!HasKnownValue)
 return None;


Index: clang/test/SemaCXX/warn-empty-body.cpp
===
--- clang/test/SemaCXX/warn-empty-body.cpp
+++ clang/test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} expected-note{{separate line}}}
+}
Index: clang/lib/Sema/SemaStmt.cpp
===
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -11815,7 +11815,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ 

[PATCH] D40185: Loosen -Wempty-body warning.

2017-11-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

I'll go ahead and land this as requested to unblock things. Thanks for the 
patch, sorry for the trouble!




Comment at: lib/Sema/SemaChecking.cpp:11818
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );

I see, this fixes the else macro case. 


https://reviews.llvm.org/D40185



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


[PATCH] D39627: Fix vtable not receiving hidden visibility when using push(visibility)

2017-11-17 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich updated this revision to Diff 123399.
jakehehrlich added a comment.

1. Added a ForDefinition parameter to setGlobalVisibility and merged visibility 
setting behaviors for setGlobalVisibility and setLinkageAndVisibilityForGV
2. Renamed setLinkageAndVisibilityForGV to setLinkageForGV
3. refactored calls to these two functions to match their new form.


Repository:
  rL LLVM

https://reviews.llvm.org/D39627

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGVTT.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGen/push-hidden-visibility-subclass.cpp

Index: test/CodeGen/push-hidden-visibility-subclass.cpp
===
--- /dev/null
+++ test/CodeGen/push-hidden-visibility-subclass.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang -S -emit-llvm -o %t %s
+// RUN: FileCheck --input-file=%t %s
+
+#pragma GCC visibility push(hidden)
+
+struct Base {
+  virtual ~Base() = default;
+  virtual void* Alloc() = 0;
+};
+
+class Child : public Base {
+public:
+  Child() = default;
+  void* Alloc();
+};
+
+void test() {
+  Child x;
+}
+
+// CHECK: @_ZTV5Child = external hidden unnamed_addr constant
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1527,7 +1527,7 @@
 VTable->setComdat(CGM.getModule().getOrInsertComdat(VTable->getName()));
 
   // Set the right visibility.
-  CGM.setGlobalVisibility(VTable, RD);
+  CGM.setGlobalVisibility(VTable, RD, ForDefinition);
 
   // Use pointer alignment for the vtable. Otherwise we would align them based
   // on the size of the initializer which doesn't make sense as only single
@@ -1637,6 +1637,7 @@
   VTable = CGM.CreateOrReplaceCXXRuntimeVariable(
   Name, VTableType, llvm::GlobalValue::ExternalLinkage);
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  CGM.setGlobalVisibility(VTable, RD, NotForDefinition);
 
   if (RD->hasAttr())
 VTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -710,7 +710,8 @@
   llvm::ConstantInt *getSize(CharUnits numChars);
 
   /// Set the visibility for the given LLVM GlobalValue.
-  void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
+  void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D,
+   ForDefinition_t IsForDefinition) const;
 
   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
   /// variable declaration D.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -662,16 +662,18 @@
 }
 
 void CodeGenModule::setGlobalVisibility(llvm::GlobalValue *GV,
-const NamedDecl *D) const {
+const NamedDecl *D,
+ForDefinition_t IsForDefinition) const {
   // Internal definitions always have default visibility.
   if (GV->hasLocalLinkage()) {
 GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
 return;
   }
 
   // Set visibility for definitions.
   LinkageInfo LV = D->getLinkageAndVisibility();
-  if (LV.isVisibilityExplicit() || !GV->hasAvailableExternallyLinkage())
+  if (LV.isVisibilityExplicit() ||
+  (IsForDefinition && !GV->hasAvailableExternallyLinkage()))
 GV->setVisibility(GetLLVMVisibility(LV.getVisibility()));
 }
 
@@ -1052,7 +1054,7 @@
 void CodeGenModule::SetCommonAttributes(const Decl *D,
 llvm::GlobalValue *GV) {
   if (const auto *ND = dyn_cast_or_null(D))
-setGlobalVisibility(GV, ND);
+setGlobalVisibility(GV, ND, ForDefinition);
   else
 GV->setVisibility(llvm::GlobalValue::DefaultVisibility);
 
@@ -1108,8 +1110,8 @@
   setNonAliasAttributes(D, F);
 }
 
-static void setLinkageAndVisibilityForGV(llvm::GlobalValue *GV,
- const NamedDecl *ND) {
+static void setLinkageForGV(llvm::GlobalValue *GV,
+const NamedDecl *ND) {
   // Set linkage and visibility in case we never see a definition.
   LinkageInfo LV = ND->getLinkageAndVisibility();
   if (!isExternallyVisible(LV.getLinkage())) {
@@ -1125,10 +1127,6 @@
   // separate linkage types for this.
   GV->setLinkage(llvm::GlobalValue::ExternalWeakLinkage);
 }
-
-// Set visibility on a declaration only if it's explicit.
-if (LV.isVisibilityExplicit())
-  GV->setVisibility(CodeGenModule::GetLLVMVisibility(LV.getVisibility()));
   }
 }
 
@@ -1197,7 +1195,8 @@
   // Only a few attributes are set on declarations; these may later be
   // 

[PATCH] D40141: [ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles

2017-11-17 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
arphaman marked an inline comment as done.
Closed by commit rL318552: [ObjC][ARC] Honor noescape attribute for 
-Warc-retain-cycles (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D40141?vs=123211=123401#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40141

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/SemaObjC/warn-retain-cycle.m


Index: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
===
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m
@@ -198,3 +198,15 @@
};
 
 }
+
+typedef void (^a_block_t)(void);
+
+@interface HonorNoEscape
+- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block;
+@end
+
+void testNoEscape(HonorNoEscape *obj) {
+  [obj addStuffUsingBlock:^{
+(void)obj; // ok.
+  }];
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11652,9 +11652,15 @@
   }
 
   // Check whether the receiver is captured by any of the arguments.
-  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i)
-if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner))
+  const ObjCMethodDecl *MD = msg->getMethodDecl();
+  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) {
+if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) {
+  // noescape blocks should not be retained by the method.
+  if (MD && MD->parameters()[i]->hasAttr())
+continue;
   return diagnoseRetainCycle(*this, capturer, owner);
+}
+  }
 }
 
 /// Check a property assign to see if it's likely to cause a retain cycle.


Index: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
===
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m
@@ -198,3 +198,15 @@
};
 
 }
+
+typedef void (^a_block_t)(void);
+
+@interface HonorNoEscape
+- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block;
+@end
+
+void testNoEscape(HonorNoEscape *obj) {
+  [obj addStuffUsingBlock:^{
+(void)obj; // ok.
+  }];
+}
Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -11652,9 +11652,15 @@
   }
 
   // Check whether the receiver is captured by any of the arguments.
-  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i)
-if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner))
+  const ObjCMethodDecl *MD = msg->getMethodDecl();
+  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) {
+if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) {
+  // noescape blocks should not be retained by the method.
+  if (MD && MD->parameters()[i]->hasAttr())
+continue;
   return diagnoseRetainCycle(*this, capturer, owner);
+}
+  }
 }
 
 /// Check a property assign to see if it's likely to cause a retain cycle.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r318552 - [ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles

2017-11-17 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Fri Nov 17 12:44:25 2017
New Revision: 318552

URL: http://llvm.org/viewvc/llvm-project?rev=318552=rev
Log:
[ObjC][ARC] Honor noescape attribute for -Warc-retain-cycles

rdar://35409566

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

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaObjC/warn-retain-cycle.m

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=318552=318551=318552=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Nov 17 12:44:25 2017
@@ -11652,9 +11652,15 @@ void Sema::checkRetainCycles(ObjCMessage
   }
 
   // Check whether the receiver is captured by any of the arguments.
-  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i)
-if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner))
+  const ObjCMethodDecl *MD = msg->getMethodDecl();
+  for (unsigned i = 0, e = msg->getNumArgs(); i != e; ++i) {
+if (Expr *capturer = findCapturingExpr(*this, msg->getArg(i), owner)) {
+  // noescape blocks should not be retained by the method.
+  if (MD && MD->parameters()[i]->hasAttr())
+continue;
   return diagnoseRetainCycle(*this, capturer, owner);
+}
+  }
 }
 
 /// Check a property assign to see if it's likely to cause a retain cycle.

Modified: cfe/trunk/test/SemaObjC/warn-retain-cycle.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-retain-cycle.m?rev=318552=318551=318552=diff
==
--- cfe/trunk/test/SemaObjC/warn-retain-cycle.m (original)
+++ cfe/trunk/test/SemaObjC/warn-retain-cycle.m Fri Nov 17 12:44:25 2017
@@ -198,3 +198,15 @@ __block void(^myBlock)(void) = ^{
};
 
 }
+
+typedef void (^a_block_t)(void);
+
+@interface HonorNoEscape
+- (void)addStuffUsingBlock:(__attribute__((noescape)) a_block_t)block;
+@end
+
+void testNoEscape(HonorNoEscape *obj) {
+  [obj addStuffUsingBlock:^{
+(void)obj; // ok.
+  }];
+}


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


[PATCH] D39611: [CodeGen] change const-ness of complex calls

2017-11-17 Thread Eli Friedman via Phabricator via cfe-commits
efriedma accepted this revision.
efriedma added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D39611



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


[PATCH] D39438: [analyzer] Diagnose stack leaks via block captures

2017-11-17 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap updated this revision to Diff 123392.
alexshap added a comment.
Herald added a subscriber: a.sidorin.

adjust the messages, more uses of auto


Repository:
  rL LLVM

https://reviews.llvm.org/D39438

Files:
  lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  test/Analysis/stack-capture-leak-arc.mm
  test/Analysis/stack-capture-leak-no-arc.mm

Index: test/Analysis/stack-capture-leak-no-arc.mm
===
--- test/Analysis/stack-capture-leak-no-arc.mm
+++ test/Analysis/stack-capture-leak-no-arc.mm
@@ -0,0 +1,37 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -verify %s
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+extern dispatch_queue_t queue;
+
+void test_block_inside_block_async_no_leak() {
+  int x = 123;
+  int *p = 
+  void (^inner)(void) = ^void(void) {
+int y = x;
+++y; 
+  };
+  // Block_copy(...) copies the captured block ("inner") too,
+  // there is no leak in this case.
+  dispatch_async(queue, ^void(void) {
+int z = x;
+++z;
+inner(); 
+  }); // no-warning
+}
+
+dispatch_block_t test_block_inside_block_async_leak() {
+  int x = 123;
+  void (^inner)(void) = ^void(void) {
+int y = x;
+++y; 
+  };
+  void (^outer)(void) = ^void(void) {
+int z = x;
+++z;
+inner(); 
+  }; 
+  return outer; // expected-warning-re{{Address of stack-allocated block declared on line {{.+}} is captured by a returned block}}
+}
+
Index: test/Analysis/stack-capture-leak-arc.mm
===
--- test/Analysis/stack-capture-leak-arc.mm
+++ test/Analysis/stack-capture-leak-arc.mm
@@ -0,0 +1,175 @@
+// RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -analyzer-checker=core -fblocks -fobjc-arc -verify %s
+
+typedef struct dispatch_queue_s *dispatch_queue_t;
+typedef void (^dispatch_block_t)(void);
+void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
+typedef long dispatch_once_t;
+void dispatch_once(dispatch_once_t *predicate, dispatch_block_t block);
+typedef long dispatch_time_t;
+void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
+
+extern dispatch_queue_t queue;
+extern dispatch_once_t *predicate;
+extern dispatch_time_t when;
+
+void test_block_expr_async() {
+  int x = 123;
+  int *p = 
+
+  dispatch_async(queue, ^{
+*p = 321;
+  });
+  // expected-warning@-3 {{Address of stack memory associated with local variable 'x' \
+is captured by an asynchronously-executed block}}
+}
+
+void test_block_expr_once_no_leak() {
+  int x = 123;
+  int *p = 
+  // synchronous, no warning
+  dispatch_once(predicate, ^{
+*p = 321;
+  });
+}
+
+void test_block_expr_after() {
+  int x = 123;
+  int *p = 
+  dispatch_after(when, queue, ^{
+*p = 321;
+  });
+  // expected-warning@-3 {{Address of stack memory associated with local variable 'x' \
+is captured by an asynchronously-executed block}}
+}
+
+void test_block_expr_async_no_leak() {
+  int x = 123;
+  int *p = 
+  // no leak
+  dispatch_async(queue, ^{
+int y = x;
+++y;
+  });
+}
+
+void test_block_var_async() {
+  int x = 123;
+  int *p = 
+  void (^b)(void) = ^void(void) {
+*p = 1; 
+  };
+  dispatch_async(queue, b);
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'x' \
+is captured by an asynchronously-executed block}}
+}
+
+void test_block_with_ref_async() {
+  int x = 123;
+  int  = x;
+  void (^b)(void) = ^void(void) {
+r = 1; 
+  };
+  dispatch_async(queue, b);
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'x' \
+is captured by an asynchronously-executed block}}
+}
+
+dispatch_block_t get_leaking_block() {
+  int leaked_x = 791;
+  int *p = _x;
+  return ^void(void) {
+*p = 1; 
+  };
+  // expected-warning@-3 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by a returned block}}
+}
+
+void test_returned_from_func_block_async() {
+  dispatch_async(queue, get_leaking_block());
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'leaked_x' \
+is captured by an asynchronously-executed block}}
+}
+
+// synchronous, no leak
+void test_block_var_once() {
+  int x = 123;
+  int *p = 
+  void (^b)(void) = ^void(void) {
+*p = 1; 
+  };
+  dispatch_once(predicate, b); // no-warning
+}
+
+void test_block_var_after() {
+  int x = 123;
+  int *p = 
+  void (^b)(void) = ^void(void) {
+*p = 1; 
+  };
+  dispatch_after(when, queue, b);
+  // expected-warning@-1 {{Address of stack memory associated with local variable 'x' \
+is captured by an asynchronously-executed block}}
+}
+
+void test_block_var_async_no_leak() {
+  int x = 123;
+  int *p = 
+  void (^b)(void) = ^void(void) {
+int y = x;
+++y; 
+  };
+  dispatch_async(queue, 

r318545 - [CodeGen] Compute the objc EH vtable address point using inbounds GEP.

2017-11-17 Thread Ahmed Bougacha via cfe-commits
Author: ab
Date: Fri Nov 17 11:46:47 2017
New Revision: 318545

URL: http://llvm.org/viewvc/llvm-project?rev=318545=rev
Log:
[CodeGen] Compute the objc EH vtable address point using inbounds GEP.

The object is provided by the objc runtime and is never visible in the
module itself, but even so, the address point we compute points into it,
and "+16" is guaranteed not to overflow.

This matches the c++ vtable IRGen.

Note that I'm not entirely convinced the 'i8*' type is correct here: at
the IR level, we're accessing memory that's outside the global object.
But we don't control the allocation, so it's not obviously wrong either.
But either way, this is only in a global initializer, so I don't think
it's going to be mucked with.  Filed PR35352 to discuss that.

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/test/CodeGenObjC/attr-exception.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=318545=318544=318545=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Fri Nov 17 11:46:47 2017
@@ -7558,8 +7558,9 @@ CGObjCNonFragileABIMac::GetInterfaceEHTy
   llvm::Value *VTableIdx = llvm::ConstantInt::get(CGM.Int32Ty, 2);
   ConstantInitBuilder builder(CGM);
   auto values = builder.beginStruct(ObjCTypes.EHTypeTy);
-  values.add(llvm::ConstantExpr::getGetElementPtr(VTableGV->getValueType(),
-  VTableGV, VTableIdx));
+  values.add(
+llvm::ConstantExpr::getInBoundsGetElementPtr(VTableGV->getValueType(),
+ VTableGV, VTableIdx));
   values.add(GetClassName(ClassName));
   values.add(GetClassGlobal(ID, /*metaclass*/ false, NotForDefinition));
 

Modified: cfe/trunk/test/CodeGenObjC/attr-exception.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/attr-exception.m?rev=318545=318544=318545=diff
==
--- cfe/trunk/test/CodeGenObjC/attr-exception.m (original)
+++ cfe/trunk/test/CodeGenObjC/attr-exception.m Fri Nov 17 11:46:47 2017
@@ -13,8 +13,8 @@ __attribute__((objc_exception))
 
 @implementation A
 @end
-// CHECK: @"OBJC_EHTYPE_$_A" = global {{%.*}} { i8** getelementptr (i8*, i8** 
@objc_ehtype_vtable, i32 2)
-// CHECK-HIDDEN: @"OBJC_EHTYPE_$_A" = hidden global {{%.*}} { i8** 
getelementptr (i8*, i8** @objc_ehtype_vtable, i32 2)
+// CHECK: @"OBJC_EHTYPE_$_A" = global {{%.*}} { i8** getelementptr inbounds 
(i8*, i8** @objc_ehtype_vtable, i32 2)
+// CHECK-HIDDEN: @"OBJC_EHTYPE_$_A" = hidden global {{%.*}} { i8** 
getelementptr inbounds (i8*, i8** @objc_ehtype_vtable, i32 2)
 
 __attribute__((objc_exception))
 __attribute__((visibility("default")))
@@ -23,5 +23,5 @@ __attribute__((visibility("default")))
 
 @implementation B
 @end
-// CHECK: @"OBJC_EHTYPE_$_B" = global {{%.*}} { i8** getelementptr (i8*, i8** 
@objc_ehtype_vtable, i32 2)
-// CHECK-HIDDEN: @"OBJC_EHTYPE_$_B" = global {{%.*}} { i8** getelementptr 
(i8*, i8** @objc_ehtype_vtable, i32 2)
+// CHECK: @"OBJC_EHTYPE_$_B" = global {{%.*}} { i8** getelementptr inbounds 
(i8*, i8** @objc_ehtype_vtable, i32 2)
+// CHECK-HIDDEN: @"OBJC_EHTYPE_$_B" = global {{%.*}} { i8** getelementptr 
inbounds (i8*, i8** @objc_ehtype_vtable, i32 2)


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


[PATCH] D35894: [clangd] Code hover for Clangd

2017-11-17 Thread William Enright via Phabricator via cfe-commits
Nebiroth marked 6 inline comments as done.
Nebiroth added inline comments.



Comment at: clangd/ClangdUnit.cpp:981
+}
+
 if (isSearchedLocation(FID, Offset)) {

malaperle wrote:
> I think we need to do a check that the computed SourceRange is valid 
> (isValid) in case we get it wrong. Otherwise, it might not go well later when 
> we use the SourceLocation to convert to lines, etc.
Do we just output a default Range values when SR isn't valid?


https://reviews.llvm.org/D35894



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


[clang-tools-extra] r318544 - [clangd] Release the old preamble before building a new one.

2017-11-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Nov 17 11:05:56 2017
New Revision: 318544

URL: http://llvm.org/viewvc/llvm-project?rev=318544=rev
Log:
[clangd] Release the old preamble before building a new one.

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=318544=318543=318544=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Fri Nov 17 11:05:56 2017
@@ -1245,7 +1245,9 @@ CppFile::deferRebuild(StringRef NewConte
   // Don't let this CppFile die before rebuild is finished.
   std::shared_ptr That = shared_from_this();
   auto FinishRebuild = [OldPreamble, VFS, RequestRebuildCounter, PCHs,
-That](std::string NewContents)
+That](std::string NewContents) mutable // 'mutable' to
+   // allow 
changing
+   // OldPreamble.
   -> llvm::Optional {
 // Only one execution of this method is possible at a time.
 // RebuildGuard will wait for any ongoing rebuilds to finish and will put 
us
@@ -1276,14 +1278,19 @@ CppFile::deferRebuild(StringRef NewConte
 llvm::MemoryBuffer::getMemBufferCopy(NewContents, That->FileName);
 
 // A helper function to rebuild the preamble or reuse the existing one. 
Does
-// not mutate any fields, only does the actual computation.
-auto DoRebuildPreamble = [&]() -> std::shared_ptr {
+// not mutate any fields of CppFile, only does the actual computation.
+// Lamdba is marked mutable to call reset() on OldPreamble.
+auto DoRebuildPreamble =
+[&]() mutable -> std::shared_ptr {
   auto Bounds =
   ComputePreambleBounds(*CI->getLangOpts(), ContentsBuffer.get(), 0);
   if (OldPreamble && OldPreamble->Preamble.CanReuse(
  *CI, ContentsBuffer.get(), Bounds, VFS.get())) {
 return OldPreamble;
   }
+  // We won't need the OldPreamble anymore, release it so it can be deleted
+  // (if there are no other references to it).
+  OldPreamble.reset();
 
   trace::Span Tracer(llvm::Twine("Preamble: ") + That->FileName);
   std::vector PreambleDiags;


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


[PATCH] D40185: Loosen -Wempty-body warning.

2017-11-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk requested changes to this revision.
rnk added a comment.
This revision now requires changes to proceed.

Why does passing the rparen location for the if condition fix the warning for 
IF_ELSE? I assumed that would refer to the else clause semicolon.


https://reviews.llvm.org/D40185



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


[PATCH] D40187: [OpenMP] Initial implementation of code generation for pragma 'teams distribute parallel for' on host

2017-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rL LLVM

https://reviews.llvm.org/D40187



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


[PATCH] D39964: Change code owner for Clang Static Analyzer to Devin Coughlin.

2017-11-17 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks Anna!


https://reviews.llvm.org/D39964



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


[PATCH] D40185: Loosen -Wempty-body warning.

2017-11-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.

Do not show it when `if` or `else` come from macros.
E.g.,

  #define USED(A) if (A); else
  #define SOME_IF(A) if (A)
  
  void test() {
// No warnings are shown in those cases now.
USED(0);
SOME_IF(0);
  }


https://reviews.llvm.org/D40185

Files:
  include/clang/Sema/Sema.h
  lib/Parse/ParseStmt.cpp
  lib/Sema/SemaChecking.cpp
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/warn-empty-body.cpp


Index: test/SemaCXX/warn-empty-body.cpp
===
--- test/SemaCXX/warn-empty-body.cpp
+++ test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} 
expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} 
expected-note{{separate line}}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11815,7 +11815,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: lib/Parse/ParseStmt.cpp
===
--- lib/Parse/ParseStmt.cpp
+++ lib/Parse/ParseStmt.cpp
@@ -1101,6 +1101,7 @@
 
   // Otherwise the condition is valid or the rparen is present.
   T.consumeClose();
+  Cond.setRParLoc(T.getCloseLocation());
 
   // Check for extraneous ')'s to catch things like "if (foo())) {".  We know
   // that all callers are looking for a statement after the condition, so ")"
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -9690,6 +9690,7 @@
   class ConditionResult {
 Decl *ConditionVar;
 FullExprArg Condition;
+SourceLocation RParenLoc;
 bool Invalid;
 bool HasKnownValue;
 bool KnownValue;
@@ -9713,6 +9714,11 @@
   return std::make_pair(cast_or_null(ConditionVar),
 Condition.get());
 }
+
+void setRParLoc(SourceLocation Loc) {
+  RParenLoc = Loc;
+}
+
 llvm::Optional getKnownValue() const {
   if (!HasKnownValue)
 return None;


Index: test/SemaCXX/warn-empty-body.cpp
===
--- test/SemaCXX/warn-empty-body.cpp
+++ test/SemaCXX/warn-empty-body.cpp
@@ -301,3 +301,14 @@
   if (x) IDENTITY(); // no-warning
 }
 
+#define SOME_IF(A) if (A)
+#define IF_ELSE(A) if (A); else
+
+
+void test_macros() {
+  SOME_IF(0);
+  IF_ELSE(0);
+
+  IDENTITY(if (0);) // expected-warning{{if statement has empty body}} expected-note{{separate line}}
+  IDENTITY(if (0); else;) // expected-warning{{else clause has empty body}} expected-note{{separate line}}}
+}
Index: lib/Sema/SemaStmt.cpp
===
--- lib/Sema/SemaStmt.cpp
+++ lib/Sema/SemaStmt.cpp
@@ -530,8 +530,7 @@
   if (elseStmt)
 DiagnoseEmptyStmtBody(ElseLoc, elseStmt, diag::warn_empty_else_body);
   else
-DiagnoseEmptyStmtBody(CondExpr->getLocEnd(), thenStmt,
-  diag::warn_empty_if_body);
+DiagnoseEmptyStmtBody(Cond.RParenLoc, thenStmt, diag::warn_empty_if_body);
 
   return BuildIfStmt(IfLoc, IsConstexpr, InitStmt, Cond, thenStmt, ElseLoc,
  elseStmt);
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11815,7 +11815,7 @@
 
   // Get line numbers of statement and body.
   bool StmtLineInvalid;
-  unsigned StmtLine = SourceMgr.getPresumedLineNumber(StmtLoc,
+  unsigned StmtLine = SourceMgr.getSpellingLineNumber(StmtLoc,
   );
   if (StmtLineInvalid)
 return false;
Index: lib/Parse/ParseStmt.cpp
===
--- lib/Parse/ParseStmt.cpp
+++ 

r318538 - [AST] Partially revert r318341 to fix two broken tests on llvm-clang-x86_64-expensive-checks-win (NFC).

2017-11-17 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Fri Nov 17 10:09:48 2017
New Revision: 318538

URL: http://llvm.org/viewvc/llvm-project?rev=318538=rev
Log:
[AST] Partially revert r318341 to fix two broken tests on 
llvm-clang-x86_64-expensive-checks-win (NFC).

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=318538=318537=318538=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Nov 17 10:09:48 2017
@@ -1,4 +1,4 @@
-//===- Expr.h - Classes for representing expressions *- C++ 
-*-===//
+//===--- Expr.h - Classes for representing expressions --*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -18,56 +18,42 @@
 #include "clang/AST/ASTVector.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclAccessPair.h"
-#include "clang/AST/DeclarationName.h"
-#include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/CharInfo.h"
-#include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
-#include "clang/Basic/OperatorKinds.h"
-#include "clang/Basic/SourceLocation.h"
-#include "clang/Basic/Specifiers.h"
 #include "clang/Basic/SyncScope.h"
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/APInt.h"
 #include "llvm/ADT/APSInt.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/None.h"
-#include "llvm/ADT/PointerIntPair.h"
-#include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/iterator_range.h"
-#include "llvm/Support/Casting.h"
+#include "llvm/Support/AtomicOrdering.h"
 #include "llvm/Support/Compiler.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/TrailingObjects.h"
-#include 
-#include 
-#include 
-#include 
-#include 
 
 namespace clang {
-
-class ASTContext;
-class CastExpr;
-class CXXBaseSpecifier;
-class CXXRecordDecl;
-class Decl;
-class Expr;
-class IdentifierInfo;
-class ObjCPropertyRefExpr;
-class SourceManager;
-class StringLiteral;
-class TargetInfo;
+  class APValue;
+  class ASTContext;
+  class BlockDecl;
+  class CXXBaseSpecifier;
+  class CXXMemberCallExpr;
+  class CXXOperatorCallExpr;
+  class CastExpr;
+  class Decl;
+  class IdentifierInfo;
+  class MaterializeTemporaryExpr;
+  class NamedDecl;
+  class ObjCPropertyRefExpr;
+  class OpaqueValueExpr;
+  class ParmVarDecl;
+  class StringLiteral;
+  class TargetInfo;
+  class ValueDecl;
 
 /// \brief A simple array of base specifiers.
-using CXXCastPath = SmallVector;
+typedef SmallVector CXXCastPath;
 
 /// \brief An adjustment to be made to the temporary created when emitting a
 /// reference binding, which accesses a particular subobject of that temporary.
@@ -96,17 +82,18 @@ struct SubobjectAdjustment {
 
   SubobjectAdjustment(const CastExpr *BasePath,
   const CXXRecordDecl *DerivedClass)
-  : Kind(DerivedToBaseAdjustment) {
+: Kind(DerivedToBaseAdjustment) {
 DerivedToBase.BasePath = BasePath;
 DerivedToBase.DerivedClass = DerivedClass;
   }
 
-  SubobjectAdjustment(FieldDecl *Field) : Kind(FieldAdjustment) {
+  SubobjectAdjustment(FieldDecl *Field)
+: Kind(FieldAdjustment) {
 this->Field = Field;
   }
 
   SubobjectAdjustment(const MemberPointerType *MPT, Expr *RHS)
-  : Kind(MemberPointerAdjustment) {
+: Kind(MemberPointerAdjustment) {
 this->Ptr.MPT = MPT;
 this->Ptr.RHS = RHS;
   }
@@ -122,7 +109,8 @@ class Expr : public Stmt {
 protected:
   Expr(StmtClass SC, QualType T, ExprValueKind VK, ExprObjectKind OK,
bool TD, bool VD, bool ID, bool ContainsUnexpandedParameterPack)
-  : Stmt(SC) {
+: Stmt(SC)
+  {
 ExprBits.TypeDependent = TD;
 ExprBits.ValueDependent = VD;
 ExprBits.InstantiationDependent = ID;
@@ -134,11 +122,10 @@ protected:
   }
 
   /// \brief Construct an empty expression.
-  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) {}
+  explicit Expr(StmtClass SC, EmptyShell) : Stmt(SC) { }
 
 public:
   QualType getType() const { return TR; }
-
   void setType(QualType t) {
 // In C++, the type of an expression is always adjusted so that it
 // will not have reference type (C++ [expr]p6). Use
@@ -200,6 +187,7 @@ public:
   ///   sizeof(sizeof(T() + T());
   /// }
   /// \endcode
+  ///
   bool isInstantiationDependent() const {
 return ExprBits.InstantiationDependent;
   }
@@ -275,7 +263,6 @@ public:
 LV_ClassTemporary,
 LV_ArrayTemporary
   };
-
   /// Reasons why an expression might not be an l-value.
   LValueClassification ClassifyLValue(ASTContext ) const;
 
@@ -298,7 +285,6 @@ public:
 MLV_ClassTemporary,

[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318537: clang-format: remove trailing lines in lamdas and 
arrow functions. (authored by mprobst).

Repository:
  rL LLVM

https://reviews.llvm.org/D40178

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

Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,18 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+// Only strip trailing empty lines for l_braces that have children, i.e.
+// for function expressions (lambdas, arrows, etc).
+!Current.MatchingParen->Children.empty()) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -1117,6 +1117,9 @@
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -70,18 +70,23 @@
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,17 @@
   "});");
 }
 
+TEST_F(FormatTest, EmptyLinesInLambdas) {
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "\n"
+   "  x(); //\n"
+   "\n"
+   "};");
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = true;
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,17 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

r318537 - clang-format: remove trailing lines in lamdas and arrow functions.

2017-11-17 Thread Martin Probst via cfe-commits
Author: mprobst
Date: Fri Nov 17 10:06:33 2017
New Revision: 318537

URL: http://llvm.org/viewvc/llvm-project?rev=318537=rev
Log:
clang-format: remove trailing lines in lamdas and arrow functions.

Summary:
clang-format already removes empty lines at the beginning & end of
blocks:

int x() {

  foo();  // lines before and after will be removed.

}

However because lamdas and arrow functions are parsed as expressions,
the existing logic to remove empty lines in UnwrappedLineFormatter
doesn't handle them.

This change special cases arrow functions in ContinuationIndenter to
remove empty lines:

x = []() {

  foo();  // lines before and after will now be removed.

};

Reviewers: djasper

Subscribers: klimek, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=318537=318536=318537=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 17 10:06:33 2017
@@ -701,8 +701,18 @@ unsigned ContinuationIndenter::addTokenO
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+// Only strip trailing empty lines for l_braces that have children, 
i.e.
+// for function expressions (lambdas, arrows, etc).
+!Current.MatchingParen->Children.empty()) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's 
logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, 
State.Column,

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=318537=318536=318537=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Fri Nov 17 10:06:33 2017
@@ -1117,6 +1117,9 @@ void UnwrappedLineFormatter::formatFirst
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=318537=318536=318537=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Nov 17 10:06:33 2017
@@ -70,18 +70,23 @@ protected:
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,17 @@ TEST_F(FormatTest, FormatsLambdas) {
   "});");
 

[PATCH] D39457: [OPENMP] Current status of OpenMP support.

2017-11-17 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev updated this revision to Diff 123373.
ABataev added a comment.

Updated info about supported constructs.


https://reviews.llvm.org/D39457

Files:
  docs/OpenMPSupport.rst
  docs/index.rst


Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -39,6 +39,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenMPSupport
ThinLTO
CommandGuide/index
FAQ
Index: docs/OpenMPSupport.rst
===
--- /dev/null
+++ docs/OpenMPSupport.rst
@@ -0,0 +1,73 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+==
+OpenMP Support
+==
+
+Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports 
offloading to X86_64, AArch64, PPC64[LE] and Cuda devices.
+The status of major OpenMP 4.5 features support in Clang.
+
+Standalone directives
+=
+
+* #pragma omp [for] simd: :good:`Complete`.
+
+* #pragma omp declare simd: :partial:`Partial`.  We support parsing/semantic
+  analysis + generation of special attributes for X86 target, but still
+  missing the LLVM pass for vectorization.
+
+* #pragma omp taskloop [simd]: :good:`Complete`.
+
+* #pragma omp target [enter|exit] data: :good:`Mostly complete`.  Some rework 
is
+  required for better stability.
+
+* #pragma omp target update: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams: :good:`Complete`.
+
+* #pragma omp distribute [simd]: :good:`Complete`.
+
+* #pragma omp distribute parallel for [simd]: :partial:`Partial`. No full 
codegen support.
+
+Combined directives
+===
+
+* #pragma omp parallel for simd: :good:`Complete`.
+
+* #pragma omp target parallel: :partial:`Partial`.  No support for the 
`reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target parallel for [simd]: :partial:`Partial`.  No support for 
the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target simd: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp target teams: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams distribute [simd]: :partial:`Partial`.  No full codegen 
support.
+
+* #pragma omp target teams distribute [simd]: :partial:`Partial`.  No full 
codegen support.
+
+* #pragma omp teams distribute parallel for [simd]: :partial:`Partial`.  No 
full codegen support.
+
+* #pragma omp target teams distribute parallel for [simd]: :partial:`Partial`. 
 No full codegen support.
+
+Clang does not support any constructs/updates from upcoming OpenMP 5.0 except 
for `reduction`-based clauses in the `task`-based directives.
+


Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -39,6 +39,7 @@
SourceBasedCodeCoverage
Modules
MSVCCompatibility
+   OpenMPSupport
ThinLTO
CommandGuide/index
FAQ
Index: docs/OpenMPSupport.rst
===
--- /dev/null
+++ docs/OpenMPSupport.rst
@@ -0,0 +1,73 @@
+.. raw:: html
+
+  
+.none { background-color: #FF }
+.partial { background-color: #99 }
+.good { background-color: #CCFF99 }
+  
+
+.. role:: none
+.. role:: partial
+.. role:: good
+
+==
+OpenMP Support
+==
+
+Clang fully supports OpenMP 3.1 + some elements of OpenMP 4.5. Clang supports offloading to X86_64, AArch64, PPC64[LE] and Cuda devices.
+The status of major OpenMP 4.5 features support in Clang.
+
+Standalone directives
+=
+
+* #pragma omp [for] simd: :good:`Complete`.
+
+* #pragma omp declare simd: :partial:`Partial`.  We support parsing/semantic
+  analysis + generation of special attributes for X86 target, but still
+  missing the LLVM pass for vectorization.
+
+* #pragma omp taskloop [simd]: :good:`Complete`.
+
+* #pragma omp target [enter|exit] data: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target update: :good:`Mostly complete`.  Some rework is
+  required for better stability.
+
+* #pragma omp target: :partial:`Partial`.  No support for the `reduction`,
+  `nowait` and `depend` clauses.
+
+* #pragma omp declare target: :partial:`Partial`.  No full codegen support.
+
+* #pragma omp teams: :good:`Complete`.
+
+* #pragma omp distribute [simd]: :good:`Complete`.
+
+* #pragma omp distribute parallel for [simd]: :partial:`Partial`. No full codegen support.
+
+Combined directives

[PATCH] D35894: [clangd] Code hover for Clangd

2017-11-17 Thread William Enright via Phabricator via cfe-commits
Nebiroth marked 25 inline comments as done.
Nebiroth added inline comments.



Comment at: clangd/ClangdServer.cpp:360
+
+  auto FileContents = DraftMgr.getDraft(File);
+  assert(FileContents.Draft &&

malaperle wrote:
> Why are you adding this? Is this coming from another commit?
> It looks like it makes tests fail:
> <-- 
> {"jsonrpc":"2.0","id":2,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///doesnotexist.cpp"},"position":{"line":4,"character":7}}}
> clangd: ../tools/clang/tools/extra/clangd/ClangdServer.cpp:362: 
> llvm::Expected  const clang::Decl*> > > > 
> clang::clangd::ClangdServer::findDefinitions(clang::clangd::PathRef, 
> clang::clangd::Position): Assertion `FileContents.Draft && "findDefinitions 
> is called for non-added document"' failed.
> /home/emalape/git/llvm/tools/clang/tools/extra/test/clangd/definitions.test:169:10:
>  error: expected string not found in input
> 
Accidental addition.



Comment at: clangd/ClangdServer.h:281
   /// Get definition of symbol at a specified \p Line and \p Column in \p File.
-  llvm::Expected> findDefinitions(PathRef File,
+  llvm::Expected malaperle wrote:
> > Location can be deduced from Decl*. I don't think this should be a pair. I 
> > also think we need a more general finder that just gets either the Decl* or 
> > MacroDef* at the "cursor". I think CXCursor does something similar in that 
> > it stores either Decl* or MacroDef*. I'm not sure it would be worth moving 
> > CXCursor from libclang but perhaps something stripped down for Clangd would 
> > be OK. This new finder will be able to be reused by findDefinition, 
> > highlights, hover, references and more.
> > We can make one patch that refactors the existing code so that 
> > findDefinitions uses this new finder class.
> We should not return `Decl*` from `ClangdServer::findDefinitions`, it's an 
> internal clang object (there are many other reasons why it's bad). 
> 
> It's ok the change the `findDefinitions` helper function inside 
> `ClangdUnit.cpp`, though. Please change it instead.
> 
> As for the `CXCursor`, I think the simplest approach would be to return two 
> vectors (`vector` and `vector`). I think clangd would 
> eventually get its own `CXCursor`-like things, possible reusing code or 
> wrapping CXCursor. But for now let's keep things simple.
We would have to handle MacroDef occurrences for this to work first. In other 
words, we would have to implement handleMacroDefOccurence in a similar way to 
handleDeclOccurence in DeclarationLocationsFinder. The document highlights 
feature suffers from the exact same problem. I'm planning on working on this 
feature in the near future.



Comment at: clangd/ClangdUnit.cpp:941
+
+// Keep default value.
+SourceRange SR = D->getSourceRange();

malaperle wrote:
> This code doesn't belong here. The hover feature and "find definition" do not 
> need the same range. The hover basically wants everything up to the first 
> left brace but "find definitions" wants everything up to the closing brace. 
> So having this code here will make "find definition" less correct.
Agreed, I'll revert the code to normal here and move this patch's code to 
getHover().


https://reviews.llvm.org/D35894



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


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 123371.
mprobst added a comment.

- prefer !x.empty() over .size() > 0.


https://reviews.llvm.org/D40178

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,17 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -70,18 +70,23 @@
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,17 @@
   "});");
 }
 
+TEST_F(FormatTest, EmptyLinesInLambdas) {
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "\n"
+   "  x(); //\n"
+   "\n"
+   "};");
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = true;
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -1117,6 +1117,9 @@
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,18 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+// Only strip trailing empty lines for l_braces that have children, i.e.
+// for function expressions (lambdas, arrows, etc).
+!Current.MatchingParen->Children.empty()) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 123370.
mprobst added a comment.

- document the meaning if Children.size() == 0 in this context.


https://reviews.llvm.org/D40178

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,17 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -70,18 +70,23 @@
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,17 @@
   "});");
 }
 
+TEST_F(FormatTest, EmptyLinesInLambdas) {
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "\n"
+   "  x(); //\n"
+   "\n"
+   "};");
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = true;
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -1117,6 +1117,9 @@
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,18 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+// Only strip trailing empty lines for l_braces that have children, i.e.
+// for function expressions (lambdas, arrows, etc).
+Current.MatchingParen->Children.size() > 0) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r318536 - [OPENMP] Codegen for `target simd` construct.

2017-11-17 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Fri Nov 17 09:57:25 2017
New Revision: 318536

URL: http://llvm.org/viewvc/llvm-project?rev=318536=rev
Log:
[OPENMP] Codegen for `target simd` construct.

Added codegen support for `target simd` directive.

Added:
cfe/trunk/test/OpenMP/target_simd_codegen.cpp
cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_simd_codegen_registration_naming.cpp
Modified:
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Basic/OpenMPKinds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/OpenMPKinds.cpp?rev=318536=318535=318536=diff
==
--- cfe/trunk/lib/Basic/OpenMPKinds.cpp (original)
+++ cfe/trunk/lib/Basic/OpenMPKinds.cpp Fri Nov 17 09:57:25 2017
@@ -894,6 +894,9 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_teams_distribute:
 CaptureRegions.push_back(OMPD_teams);
 break;
+  case OMPD_target_simd:
+CaptureRegions.push_back(OMPD_target);
+break;
   case OMPD_teams:
   case OMPD_simd:
   case OMPD_for:
@@ -909,7 +912,6 @@ void clang::getOpenMPCaptureRegions(
   case OMPD_atomic:
   case OMPD_target_data:
   case OMPD_target:
-  case OMPD_target_simd:
   case OMPD_task:
   case OMPD_taskloop:
   case OMPD_taskloop_simd:

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=318536=318535=318536=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Fri Nov 17 09:57:25 2017
@@ -7131,6 +7131,10 @@ void CGOpenMPRuntime::scanForTargetRegio
   CodeGenFunction::EmitOMPTargetParallelForSimdDeviceFunction(
   CGM, ParentName, cast(*S));
   break;
+case Stmt::OMPTargetSimdDirectiveClass:
+  CodeGenFunction::EmitOMPTargetSimdDeviceFunction(
+  CGM, ParentName, cast(*S));
+  break;
 default:
   llvm_unreachable("Unknown target directive for OpenMP device codegen.");
 }

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=318536=318535=318536=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Fri Nov 17 09:57:25 2017
@@ -138,6 +138,10 @@ public:
 
 } // namespace
 
+static void emitCommonOMPTargetDirective(CodeGenFunction ,
+ const OMPExecutableDirective ,
+ const RegionCodeGenTy );
+
 LValue CodeGenFunction::EmitOMPSharedLValue(const Expr *E) {
   if (auto *OrigDRE = dyn_cast(E)) {
 if (auto *OrigVD = dyn_cast(OrigDRE->getDecl())) {
@@ -1536,83 +1540,90 @@ static void emitOMPLoopBodyWithStopPoint
   CGF.EmitStopPoint();
 }
 
-void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective ) {
-  auto & = [](CodeGenFunction , PrePostActionTy &) {
-OMPLoopScope PreInitScope(CGF, S);
-// if (PreCond) {
-//   for (IV in 0..LastIteration) BODY;
-//   ;
-// }
-//
-
-// Emit: if (PreCond) - begin.
-// If the condition constant folds and can be elided, avoid emitting the
-// whole loop.
-bool CondConstant;
-llvm::BasicBlock *ContBlock = nullptr;
-if (CGF.ConstantFoldsToSimpleInteger(S.getPreCond(), CondConstant)) {
-  if (!CondConstant)
-return;
-} else {
-  auto *ThenBlock = CGF.createBasicBlock("simd.if.then");
-  ContBlock = CGF.createBasicBlock("simd.if.end");
-  emitPreCond(CGF, S, S.getPreCond(), ThenBlock, ContBlock,
-  CGF.getProfileCount());
-  CGF.EmitBlock(ThenBlock);
-  CGF.incrementProfileCounter();
-}
-
-// Emit the loop iteration variable.
-const Expr *IVExpr = S.getIterationVariable();
-const VarDecl *IVDecl = 
cast(cast(IVExpr)->getDecl());
-CGF.EmitVarDecl(*IVDecl);
-CGF.EmitIgnoredExpr(S.getInit());
-
-// Emit the iterations count variable.
-// If it is not a variable, Sema decided to calculate iterations count on
-// each iteration (e.g., it is foldable into a constant).
-if (auto LIExpr = dyn_cast(S.getLastIteration())) {
-  CGF.EmitVarDecl(*cast(LIExpr->getDecl()));
-  // Emit calculation of the iterations count.
-  CGF.EmitIgnoredExpr(S.getCalcLastIteration());
-}
-
-CGF.EmitOMPSimdInit(S);
-
-emitAlignedClause(CGF, S);
-(void)CGF.EmitOMPLinearClauseInit(S);
-{
-  OMPPrivateScope LoopScope(CGF);
-  CGF.EmitOMPPrivateLoopCounters(S, LoopScope);
-  CGF.EmitOMPLinearClause(S, LoopScope);
-  CGF.EmitOMPPrivateClause(S, 

[PATCH] D33989: [OpenCL] Allow targets to select address space per type

2017-11-17 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

Perhaps, I don't understand the concept of layered design in this particular 
case. But I just find it annoying that we need to re-implement the entire 
OpenCL AST Type structure in Basic. And even if we don't have dependencies on 
the files physically we still logically  bound to the AST representation in 
Basics and just entirely mirror it there.


Repository:
  rL LLVM

https://reviews.llvm.org/D33989



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


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

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

Looks good. There is a chance that some people do not want this in their coding 
style. But if so, we can add an option later.


https://reviews.llvm.org/D40178



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


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 123368.
mprobst added a comment.

- reduce test cases a bit, no need to separate before/after cases


https://reviews.llvm.org/D40178

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,17 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -70,18 +70,23 @@
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,17 @@
   "});");
 }
 
+TEST_F(FormatTest, EmptyLinesInLambdas) {
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "\n"
+   "  x(); //\n"
+   "\n"
+   "};");
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = true;
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -1117,6 +1117,9 @@
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,16 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+Current.MatchingParen->Children.size() > 0) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
mprobst added a comment.

In https://reviews.llvm.org/D40178#928645, @djasper wrote:

> Is this different for C++ lambdas? I would think that we never should add an 
> empty line before the "}" of a child block.


Actually indeed turns out to be identical for C++ lambdas. Fixed as we 
discussed offline.


https://reviews.llvm.org/D40178



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


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Martin Probst via Phabricator via cfe-commits
mprobst updated this revision to Diff 123367.
mprobst added a comment.

- handle C++ lambdas
- handle preceding empty lines


https://reviews.llvm.org/D40178

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

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,23 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesInArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "\n"
+   "  foo();\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -70,18 +70,23 @@
 return getStyleWithColumns(getGoogleStyle(), ColumnLimit);
   }
 
-  void verifyFormat(llvm::StringRef Code,
+  void verifyFormat(llvm::StringRef Expected, llvm::StringRef Code,
 const FormatStyle  = getLLVMStyle()) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+EXPECT_EQ(Expected.str(), format(Code, Style));
 if (Style.Language == FormatStyle::LK_Cpp) {
   // Objective-C++ is a superset of C++, so everything checked for C++
   // needs to be checked for Objective-C++ as well.
   FormatStyle ObjCStyle = Style;
   ObjCStyle.Language = FormatStyle::LK_ObjC;
-  EXPECT_EQ(Code.str(), format(test::messUp(Code), ObjCStyle));
+  EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
 }
   }
 
+  void verifyFormat(llvm::StringRef Code,
+const FormatStyle  = getLLVMStyle()) {
+verifyFormat(Code, test::messUp(Code), Style);
+  }
+
   void verifyIncompleteFormat(llvm::StringRef Code,
   const FormatStyle  = getLLVMStyle()) {
 EXPECT_EQ(Code.str(),
@@ -11089,6 +11094,23 @@
   "});");
 }
 
+TEST_F(FormatTest, EmptyLinesInLambdas) {
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "\n"
+   "  x(); //\n"
+   "};");
+  verifyFormat("auto lambda = []() {\n"
+   "  x(); //\n"
+   "};",
+   "auto lambda = []() {\n"
+   "  x(); //\n"
+   "\n"
+   "};");
+}
+
 TEST_F(FormatTest, FormatsBlocks) {
   FormatStyle ShortBlocks = getLLVMStyle();
   ShortBlocks.AllowShortBlocksOnASingleLine = true;
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -1117,6 +1117,9 @@
   (!RootToken.Next ||
(RootToken.Next->is(tok::semi) && !RootToken.Next->Next)))
 Newlines = std::min(Newlines, 1u);
+  // Remove empty lines at the start of nested blocks (lambdas/arrow functions)
+  if (PreviousLine == nullptr && Line.Level > 0)
+Newlines = std::min(Newlines, 1u);
   if (Newlines == 0 && !RootToken.IsFirst)
 Newlines = 1;
   if (RootToken.IsFirst && !RootToken.HasUnescapedNewline)
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,16 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Current.is(tok::r_brace) && Current.MatchingParen &&
+Current.MatchingParen->Children.size() > 0) {
+  // lambdas and arrow functions are expressions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case them here.
+  MaxEmptyLinesToKeep = 1;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D39505: [OpenMP] Show error if VLAs are not supported

2017-11-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld marked an inline comment as done.
Hahnfeld added inline comments.



Comment at: include/clang/Basic/TargetInfo.h:944
+  /// \brief Whether target supports variable-length arrays.
+  bool isVLASupported() const { return VLASupported; }
+

rjmccall wrote:
> Hahnfeld wrote:
> > rjmccall wrote:
> > > ABataev wrote:
> > > > Hahnfeld wrote:
> > > > > rjmccall wrote:
> > > > > > Hahnfeld wrote:
> > > > > > > rjmccall wrote:
> > > > > > > > Hahnfeld wrote:
> > > > > > > > > rjmccall wrote:
> > > > > > > > > > ABataev wrote:
> > > > > > > > > > > ABataev wrote:
> > > > > > > > > > > > Hahnfeld wrote:
> > > > > > > > > > > > > rjmccall wrote:
> > > > > > > > > > > > > > Hahnfeld wrote:
> > > > > > > > > > > > > > > rjmccall wrote:
> > > > > > > > > > > > > > > > Hahnfeld wrote:
> > > > > > > > > > > > > > > > > rjmccall wrote:
> > > > > > > > > > > > > > > > > > The way you've written this makes it sound 
> > > > > > > > > > > > > > > > > > like "does the target support VLAs?", but 
> > > > > > > > > > > > > > > > > > the actual semantic checks treat it as "do 
> > > > > > > > > > > > > > > > > > OpenMP devices on this target support 
> > > > > > > > > > > > > > > > > > VLAs?"  Maybe there should be a more 
> > > > > > > > > > > > > > > > > > specific way to query things about OpenMP 
> > > > > > > > > > > > > > > > > > devices instead of setting a global flag 
> > > > > > > > > > > > > > > > > > for the target?
> > > > > > > > > > > > > > > > > Actually, the NVPTX and SPIR targets never 
> > > > > > > > > > > > > > > > > support VLAs. So I felt like it would be more 
> > > > > > > > > > > > > > > > > correct to make this a global property of the 
> > > > > > > > > > > > > > > > > target.
> > > > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > > > The difference is that the other programming 
> > > > > > > > > > > > > > > > > models (OpenCL and CUDA) error out 
> > > > > > > > > > > > > > > > > immediatelyand regardless of the target 
> > > > > > > > > > > > > > > > > because this limitation is reflected in the 
> > > > > > > > > > > > > > > > > standards that disallow VLAs (see 
> > > > > > > > > > > > > > > > > SemaType.cpp). For OpenMP we might have 
> > > > > > > > > > > > > > > > > target devices that support VLA so we 
> > > > > > > > > > > > > > > > > shouldn't error out for those.
> > > > > > > > > > > > > > > > If you want to make it a global property of the 
> > > > > > > > > > > > > > > > target, that's fine, but then I don't 
> > > > > > > > > > > > > > > > understand why your diagnostic only fires when 
> > > > > > > > > > > > > > > > (S.isInOpenMPDeclareTargetContext() || 
> > > > > > > > > > > > > > > > S.isInOpenMPTargetExecutionDirective()).
> > > > > > > > > > > > > > > That is because of how OpenMP offloading works 
> > > > > > > > > > > > > > > and how it is implemented in Clang. Consider the 
> > > > > > > > > > > > > > > following snippet from the added test case:
> > > > > > > > > > > > > > > ```lang=c
> > > > > > > > > > > > > > > int vla[arg];
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > #pragma omp target map(vla[0:arg])
> > > > > > > > > > > > > > > {
> > > > > > > > > > > > > > >// more code here...
> > > > > > > > > > > > > > > }
> > > > > > > > > > > > > > > ```
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > Clang will take the following steps to compile 
> > > > > > > > > > > > > > > this into a working binary for a GPU:
> > > > > > > > > > > > > > > 1. Parse and (semantically) analyze the code 
> > > > > > > > > > > > > > > as-is for the host and produce LLVM Bitcode.
> > > > > > > > > > > > > > > 2. Parse and analyze again the code as-is and 
> > > > > > > > > > > > > > > generate code for the offloading target, the GPU 
> > > > > > > > > > > > > > > in this case.
> > > > > > > > > > > > > > > 3. Take LLVM Bitcode from 1., generate host 
> > > > > > > > > > > > > > > binary and embed target binary from 3.
> > > > > > > > > > > > > > > 
> > > > > > > > > > > > > > > `OpenMPIsDevice` will be true for 2., but the 
> > > > > > > > > > > > > > > complete source code is analyzed. So to not throw 
> > > > > > > > > > > > > > > errors for the host code, we have to make sure 
> > > > > > > > > > > > > > > that we are actually generating code for the 
> > > > > > > > > > > > > > > target device. This is either in a `target` 
> > > > > > > > > > > > > > > directive or in a `declare target` region.
> > > > > > > > > > > > > > > Note that this is quite similar to what CUDA 
> > > > > > > > > > > > > > > does, only they have `CUDADiagIfDeviceCode` for 
> > > > > > > > > > > > > > > this logic. If you want me to add something of 
> > > > > > > > > > > > > > > that kind for OpenMP target devices, I'm fine 
> > > > > > > > > > > > > > > with that. However for the given case, it's a bit 
> > > > > > > > > > > > > > > different because this error should only be 
> > > > > > > > > > > > > > > thrown for target devices 

[PATCH] D39505: [OpenMP] Show error if VLAs are not supported

2017-11-17 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld updated this revision to Diff 123364.
Hahnfeld added a comment.

Update changes to be generic.


https://reviews.llvm.org/D39505

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TargetInfo.h
  include/clang/Sema/Sema.h
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/NVPTX.cpp
  lib/Basic/Targets/SPIR.h
  lib/Sema/SemaOpenMP.cpp
  lib/Sema/SemaType.cpp
  test/OpenMP/target_vla_messages.cpp

Index: test/OpenMP/target_vla_messages.cpp
===
--- /dev/null
+++ test/OpenMP/target_vla_messages.cpp
@@ -0,0 +1,201 @@
+// PowerPC supports VLAs.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-unknown-unknown -emit-llvm-bc %s -o %t-ppc-host-ppc.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-unknown-unknown -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-ppc.bc -o %t-ppc-device.ll
+
+// Nvidia GPUs don't support VLAs.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host-nvptx.bc
+// RUN: %clang_cc1 -verify -DNO_VLA -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host-nvptx.bc -o %t-nvptx-device.ll
+
+#ifndef NO_VLA
+// expected-no-diagnostics
+#endif
+
+#pragma omp declare target
+void declare(int arg) {
+  int a[2];
+#ifdef NO_VLA
+  // expected-error@+2 {{variable length arrays are not supported for the current target}}
+#endif
+  int vla[arg];
+}
+
+void declare_parallel_reduction(int arg) {
+  int a[2];
+
+#pragma omp parallel reduction(+: a)
+  { }
+
+#pragma omp parallel reduction(+: a[0:2])
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+3 {{cannot generate code for reduction on array section, which requires a variable length array}}
+  // expected-note@+2 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp parallel reduction(+: a[0:arg])
+  { }
+}
+#pragma omp end declare target
+
+template 
+void target_template(int arg) {  
+#pragma omp target
+  {
+#ifdef NO_VLA
+// expected-error@+2 {{variable length arrays are not supported for the current target}}
+#endif
+T vla[arg];
+  }
+}
+
+void target(int arg) {
+#pragma omp target
+  {
+#ifdef NO_VLA
+// expected-error@+2 {{variable length arrays are not supported for the current target}}
+#endif
+int vla[arg];
+  }
+
+#pragma omp target
+  {
+#pragma omp parallel
+{
+#ifdef NO_VLA
+// expected-error@+2 {{variable length arrays are not supported for the current target}}
+#endif
+  int vla[arg];
+}
+  }
+
+  target_template(arg);
+}
+
+void teams_reduction(int arg) {
+  int a[2];
+  int vla[arg];
+
+#pragma omp target map(a)
+#pragma omp teams reduction(+: a)
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+4 {{cannot generate code for reduction on variable length array}}
+  // expected-note@+3 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp target map(vla)
+#pragma omp teams reduction(+: vla)
+  { }
+  
+#pragma omp target map(a[0:2])
+#pragma omp teams reduction(+: a[0:2])
+  { }
+
+#pragma omp target map(vla[0:2])
+#pragma omp teams reduction(+: vla[0:2])
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+4 {{cannot generate code for reduction on array section, which requires a variable length array}}
+  // expected-note@+3 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp target map(a[0:arg])
+#pragma omp teams reduction(+: a[0:arg])
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+4 {{cannot generate code for reduction on array section, which requires a variable length array}}
+  // expected-note@+3 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp target map(vla[0:arg])
+#pragma omp teams reduction(+: vla[0:arg])
+  { }
+}
+
+void parallel_reduction(int arg) {
+  int a[2];
+  int vla[arg];
+
+#pragma omp target map(a)
+#pragma omp parallel reduction(+: a)
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+4 {{cannot generate code for reduction on variable length array}}
+  // expected-note@+3 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp target map(vla)
+#pragma omp parallel reduction(+: vla)
+  { }
+
+#pragma omp target map(a[0:2])
+#pragma omp parallel reduction(+: a[0:2])
+  { }
+
+#pragma omp target map(vla[0:2])
+#pragma omp parallel reduction(+: vla[0:2])
+  { }
+
+#ifdef NO_VLA
+  // expected-error@+4 {{cannot generate code for reduction on array section, which requires a variable length array}}
+  // expected-note@+3 {{variable length arrays are not supported for the current target}}
+#endif
+#pragma omp target map(a[0:arg])
+#pragma omp parallel reduction(+: a[0:arg])
+  { }
+
+#ifdef NO_VLA
+  // 

[PATCH] D40182: [clangd] Add parsing and value inspection to JSONExpr.

2017-11-17 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added a subscriber: ilya-biryukov.

This will replace the places where we're using YAMLParser to parse JSON now:

- the new marshalling code (T::parse()) should handle fewer cases and require 
fewer explicit casts
- we'll early-reject invalid JSON that YAMLParser accepts
- we'll be able to fix protocol-parsing bugs caused by the fact that YAML can 
only parse forward

I plan to do the conversion as soon as this lands, but I don't want it in one
patch as the protocol.cpp changes are conflict-prone.


https://reviews.llvm.org/D40182

Files:
  clangd/JSONExpr.cpp
  clangd/JSONExpr.h
  unittests/clangd/JSONExprTests.cpp

Index: unittests/clangd/JSONExprTests.cpp
===
--- unittests/clangd/JSONExprTests.cpp
+++ unittests/clangd/JSONExprTests.cpp
@@ -15,6 +15,9 @@
 namespace clang {
 namespace clangd {
 namespace json {
+void PrintTo(const Expr , std::ostream *OS) {
+  llvm::raw_os_ostream(*OS) << llvm::formatv("{0:2}", E);
+}
 namespace {
 
 std::string s(const Expr ) { return llvm::formatv("{0}", E).str(); }
@@ -108,6 +111,77 @@
  }));
 }
 
+TEST(JSONTest, Parse) {
+  auto Compare = [](llvm::StringRef S, Expr Expected) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  EXPECT_EQ(*E, Expected);
+  EXPECT_EQ(sp(*E), sp(Expected));
+} else {
+  handleAllErrors(E.takeError(), [S](const llvm::ErrorInfoBase ) {
+FAIL() << "Failed to parse JSON >>> " << S << " <<<: " << E.message();
+  });
+}
+  };
+
+  Compare(R"(true)", true);
+  Compare(R"(false)", false);
+  Compare(R"(null)", nullptr);
+
+  Compare(R"(42)", 42);
+  Compare(R"(2.5)", 2.5);
+  Compare(R"(2e50)", 2e50);
+  Compare(R"(1.2e3456789)", 1.0 / 0.0);
+
+  Compare(R"("foo")", "foo");
+  Compare(R"("\"\\\b\f\n\r\t")", "\"\\\b\f\n\r\t");
+  Compare(R"("\u")", llvm::StringRef("\0", 1));
+  Compare("\"\x7f\"", "\x7f");
+  Compare(R"("\ud801\udc37")", "\U00010437"); // UTF16 surrogate pair escape.
+  Compare("\"\xE2\x82\xAC\xF0\x9D\x84\x9E\"", "\u20ac\U0001d11e"); // UTF8
+  Compare(R"("\ud801")", "\ufffd"); // Invalid codepoint.
+
+  Compare(R"({"":0,"":0})", obj{{"", 0}});
+  Compare(R"({"obj":{},"arr":[]})", obj{{"obj", obj{}}, {"arr", {}}});
+  Compare(R"({"\n":{"\u":}})",
+  obj{{"\n", obj{
+ {llvm::StringRef("\0", 1), },
+ }}});
+  Compare("\r[\n\t] ", {});
+}
+
+TEST(JSONTest, ParseErrors) {
+  auto ExpectErr = [](llvm::StringRef Msg, llvm::StringRef S) {
+if (auto E = parse(S)) {
+  // Compare both string forms and with operator==, in case we have bugs.
+  FAIL() << "Parsed JSON >>> " << S << " <<< but wanted error: " << Msg;
+} else {
+  handleAllErrors(E.takeError(), [S, Msg](const llvm::ErrorInfoBase ) {
+EXPECT_THAT(E.message(), testing::HasSubstr(Msg)) << S;
+  });
+}
+  };
+  ExpectErr("Unexpected EOF", "");
+  ExpectErr("Unexpected EOF", "[");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Text after end of document", "[][]");
+  ExpectErr("Invalid bareword", "fuzzy");
+  ExpectErr("Expected , or ]", "[2?]");
+  ExpectErr("Expected object key", "{a:2}");
+  ExpectErr("Expected : after object key", R"({"a",2})");
+  ExpectErr("Expected , or } after object property", R"({"a":2 "b":3})");
+  ExpectErr("Expected JSON value", R"([&%!])");
+  ExpectErr("Invalid number", "1e1.0");
+  ExpectErr("Unterminated string", R"("abc\"def)");
+  ExpectErr("Control character in string", "\"abc\ndef\"");
+  ExpectErr("Invalid escape sequence", R"("\030")");
+  ExpectErr("Invalid \\u escape sequence", R"("\usuck")");
+  ExpectErr("[3:3, byte=19]", R"({
+  "valid": 1,
+  invalid: 2
+})");
+}
+
 } // namespace
 } // namespace json
 } // namespace clangd
Index: clangd/JSONExpr.h
===
--- clangd/JSONExpr.h
+++ clangd/JSONExpr.h
@@ -1,30 +1,35 @@
-//===--- JSONExpr.h - composable JSON expressions ---*- C++ -*-===//
+//===--- JSONExpr.h - JSON expressions, parsing and serialization - C++ -*-===//
 //
 // The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===-===//
 
+// FIXME: rename to JSON.h now that the scope is wider?
+
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_JSON_H
 
 #include 
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 
 namespace clang {
 namespace clangd {
 namespace json {
 
-// An Expr is an opaque temporary JSON structure used to compose documents.
+// An Expr is an JSON 

[PATCH] D40181: [libcxx] Allow to set locale on Windows.

2017-11-17 Thread Andrey Khalyavin via Phabricator via cfe-commits
halyavin created this revision.

Fix the problem PR31516  with 
setting locale on Windows by wrapping _locale_t with a pointer-like class.

Reduces 74 test failures in std/localization test suite to 47 test failures (on 
llvm clang, Visual Studio 2015). Number of test failures doesn't depend on the 
platform (x86 or x64).


https://reviews.llvm.org/D40181

Files:
  include/__locale
  include/support/win32/locale_win32.h
  src/support/win32/locale_win32.cpp

Index: src/support/win32/locale_win32.cpp
===
--- src/support/win32/locale_win32.cpp
+++ src/support/win32/locale_win32.cpp
@@ -18,23 +18,9 @@
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
 {
-return _create_locale( mask, locale );
+return {_create_locale( LC_ALL, locale ), locale};
 }
 
-locale_t uselocale( locale_t newloc )
-{
-locale_t old_locale = _get_current_locale();
-if ( newloc == NULL )
-return old_locale;
-// uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
-_configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
-// uselocale sets all categories
-// disable setting locale on Windows temporarily because the structure is opaque (PR31516)
-//setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
-// uselocale returns the old locale_t
-return old_locale;
-}
-
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
 #if defined(_LIBCPP_MSVCRT)
Index: include/support/win32/locale_win32.h
===
--- include/support/win32/locale_win32.h
+++ include/support/win32/locale_win32.h
@@ -14,6 +14,7 @@
 #include <__config>
 #include 
 #include  // _locale_t
+#include <__nullptr>
 
 #define LC_COLLATE_MASK _M_COLLATE
 #define LC_CTYPE_MASK _M_CTYPE
@@ -28,13 +29,77 @@
  | LC_NUMERIC_MASK \
  | LC_TIME_MASK )
 
-#define locale_t _locale_t
+class locale_t {
+public:
+locale_t()
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(std::nullptr_t)
+: __locale(nullptr), __locale_str(nullptr) {}
+locale_t(_locale_t __locale, const char* __locale_str)
+: __locale(__locale), __locale_str(__locale_str) {}
 
+friend bool operator==(const locale_t& __left, const locale_t& __right) {
+return __left.__locale == __right.__locale;
+}
+
+friend bool operator==(const locale_t& __left, int __right) {
+return __left.__locale == nullptr && __right == 0;
+}
+
+friend bool operator==(const locale_t& __left, nullptr_t) {
+return __left.__locale == nullptr;
+}
+
+friend bool operator==(int __left, const locale_t& __right) {
+return __left == 0 && nullptr == __right.__locale;
+}
+
+friend bool operator==(nullptr_t, const locale_t& __right) {
+return nullptr == __right.__locale;
+}
+
+friend bool operator!=(const locale_t& __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, int __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(const locale_t& __left, nullptr_t __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(int __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+friend bool operator!=(nullptr_t __left, const locale_t& __right) {
+return !(__left == __right);
+}
+
+operator bool() const {
+return __locale != nullptr;
+}
+
+const char* __get_locale() const { return __locale_str; }
+
+operator _locale_t() const {
+return __locale;
+}
+private:
+_locale_t __locale;
+const char* __locale_str;
+};
+
 // Locale management functions
 #define freelocale _free_locale
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t base );
-locale_t uselocale( locale_t newloc );
+// uselocale can't be implemented on Windows because Windows allows partial modification
+// of thread-local locale and so _get_current_locale() returns a copy while uselocale does
+// not create any copies.
+// We can still implement raii even without uselocale though.
 
 
 lconv *localeconv_l( locale_t loc );
Index: include/__locale
===
--- include/__locale
+++ include/__locale
@@ -49,7 +49,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS) || defined(_LIBCPP_MSVCRT)
+#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
 struct __libcpp_locale_guard {
   _LIBCPP_INLINE_VISIBILITY
   __libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}

[PATCH] D38921: [analyzer] LoopUnrolling: update the matched assignment operators

2017-11-17 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.
This revision is now accepted and ready to land.

A nit, otherwise LG!




Comment at: lib/StaticAnalyzer/Core/PathDiagnostic.cpp:693
 SMng);
+  } else if (Optional BE = P.getAs()) {
+S = BE->getBlock()->getTerminatorCondition();

Is this change related? Maybe you forgot to add a dependency to this revision?


https://reviews.llvm.org/D38921



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


[PATCH] D39438: [analyzer] Diagnose stack leaks via block captures

2017-11-17 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:192
+  this, "Address of stack-allocated memory is captured");
+SmallString<512> Buf;
+llvm::raw_svector_ostream Out(Buf);

xazax.hun wrote:
> How long usually these error messages are? Maybe 512 is a bit large buffer 
> for this? Note that in case the error message is longer this is still not a 
> hard error, it just will hit the slow path (allocating the buffer on the 
> heap).
>Note that in case the error message is longer this is still not a hard error, 
>it just will hit the slow path

thanks, i'm aware of that. 
512 was used in this file before my invasion,
the size obviously depends on what genName would generate (and inherently 
depends on the code style of the codebase)


Repository:
  rL LLVM

https://reviews.llvm.org/D39438



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


[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 123359.
klimek added a comment.

Just exporting


https://reviews.llvm.org/D40068

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -2102,6 +2102,21 @@
   EXPECT_EQ("///", format(" ///  ", getLLVMStyleWithColumns(20)));
 }
 
+TEST_F(FormatTestComments, ReflowTODO) {
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// re flows\n",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("// some text\n"
+"// that re flows\n",
+format("// some text that\n"
+   "// reflows\n",
+   getLLVMStyleWithColumns(16)));
+// some text that
+// that reflows
+}
+
 TEST_F(FormatTestComments, IgnoresIf0Contents) {
   EXPECT_EQ("#if 0\n"
 "}{)(&*(^%%#%@! fsadj f;ldjs ,:;| <<<>>>][)(][\n"
@@ -2484,6 +2499,7 @@
   " long */\n"
   "  b);",
   format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(16)));
+
   EXPECT_EQ(
   "a = f(\n"
   "a,\n"
@@ -2888,16 +2904,15 @@
getLLVMStyleWithColumns(20)));
 }
 
-TEST_F(FormatTestComments, NoCrush_Bug34236) {
+TEST_F(FormatTestComments, NoCrash_Bug34236) {
   // This is a test case from a crasher reported in:
   // https://bugs.llvm.org/show_bug.cgi?id=34236
   // Temporarily disable formatting for readability.
   // clang-format off
   EXPECT_EQ(
 "/**/ /*\n"
 "  *   a\n"
-"  * b c\n"
-"  * d*/",
+"  * b c d*/",
   format(
 "/**/ /*\n"
 " *   a b\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -9922,16 +9922,9 @@
 
   Style.PenaltyExcessCharacter = 90;
   verifyFormat("int a; // the comment", Style);
-  EXPECT_EQ("int a; // the\n"
-"   // comment aa",
+  EXPECT_EQ("int a; // the comment\n"
+"   // aa",
 format("int a; // the comment aa", Style));
-  EXPECT_EQ("int a; // first line\n"
-"   // second line\n"
-"   // third line",
-format("int a; // first line\n"
-   "   // second line\n"
-   "   // third line",
-   Style));
   EXPECT_EQ("int a; /* first line\n"
 "* second line\n"
 "* third line\n"
@@ -9941,12 +9934,18 @@
"* third line\n"
"*/",
Style));
+  EXPECT_EQ("int a; // first line\n"
+"   // second line\n"
+"   // third line",
+format("int a; // first line\n"
+   "   // second line\n"
+   "   // third line",
+   Style));
   // FIXME: Investigate why this is not getting the same layout as the test
   // above.
   EXPECT_EQ("int a; /* first line\n"
-"* second\n"
-"* line third\n"
-"* line\n"
+"* second line\n"
+"* third line\n"
 "*/",
 format("int a; /* first line second line third line"
"\n*/",
@@ -9965,31 +9964,23 @@
 
   // FIXME: Optimally, we'd keep bazfoo on the first line and reflow bar to the
   // next one.
-  EXPECT_EQ("// foo bar baz\n"
-"// bazfoo bar foo\n"
-"// bar\n",
+  EXPECT_EQ("// foo bar baz bazfoo\n"
+"// bar foo bar\n",
 format("// foo bar baz  bazfoo bar\n"
"// foobar\n",
Style));
 
   EXPECT_EQ("// foo bar baz bazfoo\n"
-"// foo bar baz\n"
-"// bazfoo bar foo\n"
-"// bar\n",
+"// foo bar baz bazfoo\n"
+"// bar foo bar\n",
 format("// foo bar baz  bazfoo\n"
"// foo bar baz  bazfoo bar\n"
"// foo bar\n",
Style));
 
-  // FIXME: Optimally, we'd keep 'bar' in the last line at the end of the line,
-  // as it does not actually protrude far enough to make breaking pay off.
-  // Unfortunately, 

[PATCH] D40180: [clang-tools-extra] Fix small typo in docs/ReleaseNotes.rst

2017-11-17 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.

This is mainly a test diff to check the new Herald rule I
added in LLVM Phabricator to automatically Cc: cfe-commits on all
clang-tools-extra diffs.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40180

Files:
  docs/ReleaseNotes.rst


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,7 +57,7 @@
 Improvements to clang-tidy
 --
 
-- New `google-avoid-throwing-objc-exception
+- New `google-objc-avoid-throwing-exception
   
`_
 check
 
   Add new check to detect throwing exceptions in Objective-C code, which 
should be avoided.


Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,7 +57,7 @@
 Improvements to clang-tidy
 --
 
-- New `google-avoid-throwing-objc-exception
+- New `google-objc-avoid-throwing-exception
   `_ check
 
   Add new check to detect throwing exceptions in Objective-C code, which should be avoided.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r318530 - Indent code blocks so they are actually treated as such

2017-11-17 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Fri Nov 17 08:34:36 2017
New Revision: 318530

URL: http://llvm.org/viewvc/llvm-project?rev=318530=rev
Log:
Indent code blocks so they are actually treated as such

Modified:
cfe/trunk/docs/ClangFormatStyleOptions.rst

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=318530=318529=318530=diff
==
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Fri Nov 17 08:34:36 2017
@@ -994,9 +994,9 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-Constructor()
-: initializer1(),
-  initializer2()
+  Constructor()
+  : initializer1(),
+initializer2()
 
   * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
 Break constructor initializers before the colon and commas, and align
@@ -1004,18 +1004,18 @@ the configuration (without a prefix: ``A
 
 .. code-block:: c++
 
-Constructor()
-: initializer1()
-, initializer2()
+  Constructor()
+  : initializer1()
+  , initializer2()
 
   * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
 Break constructor initializers after the colon and commas.
 
 .. code-block:: c++
 
-Constructor() :
-initializer1(),
-initializer2()
+  Constructor() :
+  initializer1(),
+  initializer2()
 
 
 


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


[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

2017-11-17 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

Is this different for C++ lambdas? I would think that we never should add an 
empty line before the "}" of a child block.


https://reviews.llvm.org/D40178



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


[PATCH] D40024: Fix skipping of flags in getClangStripDependencyFileAdjuster

2017-11-17 Thread Dave Lee via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318529: Fix skipping of flags in 
getClangStripDependencyFileAdjuster (authored by kastiglione).

Repository:
  rL LLVM

https://reviews.llvm.org/D40024

Files:
  cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
  cfe/trunk/unittests/Tooling/ToolingTest.cpp


Index: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
===
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
@@ -58,14 +58,14 @@
   StringRef Arg = Args[i];
   // All dependency-file options begin with -M. These include -MM,
   // -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
-  if (!Arg.startswith("-M"))
+  if (!Arg.startswith("-M")) {
 AdjustedArgs.push_back(Args[i]);
+continue;
+  }
 
-  if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
-  (Arg == "-MD") || (Arg == "-MMD")) {
-// Output is specified as -MX foo. Skip the next argument also.
+  if (Arg == "-MF" || Arg == "-MT" || Arg == "-MQ")
+// These flags take an argument: -MX foo. Skip the next argument also.
 ++i;
-  }
 }
 return AdjustedArgs;
   };
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -402,6 +402,37 @@
   EXPECT_FALSE(Found);
 }
 
+// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
+TEST(ClangToolTest, StripDependencyFileAdjuster) {
+  FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
+
+  ClangTool Tool(Compilations, std::vector(1, "/a.cc"));
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+
+  CommandLineArguments FinalArgs;
+  ArgumentsAdjuster CheckFlagsAdjuster =
+[](const CommandLineArguments , StringRef /*unused*/) {
+  FinalArgs = Args;
+  return Args;
+};
+  Tool.clearArgumentsAdjusters();
+  Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
+  Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
+  Tool.run(Action.get());
+
+  auto HasFlag = [](const std::string ) {
+return std::find(FinalArgs.begin(), FinalArgs.end(), Flag) !=
+   FinalArgs.end();
+  };
+  EXPECT_FALSE(HasFlag("-MD"));
+  EXPECT_FALSE(HasFlag("-MMD"));
+  EXPECT_TRUE(HasFlag("-c"));
+  EXPECT_TRUE(HasFlag("-w"));
+}
+
 namespace {
 /// Find a target name such that looking for it in TargetRegistry by that name
 /// returns the same target. We expect that there is at least one target


Index: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
===
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
@@ -58,14 +58,14 @@
   StringRef Arg = Args[i];
   // All dependency-file options begin with -M. These include -MM,
   // -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
-  if (!Arg.startswith("-M"))
+  if (!Arg.startswith("-M")) {
 AdjustedArgs.push_back(Args[i]);
+continue;
+  }
 
-  if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
-  (Arg == "-MD") || (Arg == "-MMD")) {
-// Output is specified as -MX foo. Skip the next argument also.
+  if (Arg == "-MF" || Arg == "-MT" || Arg == "-MQ")
+// These flags take an argument: -MX foo. Skip the next argument also.
 ++i;
-  }
 }
 return AdjustedArgs;
   };
Index: cfe/trunk/unittests/Tooling/ToolingTest.cpp
===
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp
@@ -402,6 +402,37 @@
   EXPECT_FALSE(Found);
 }
 
+// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
+TEST(ClangToolTest, StripDependencyFileAdjuster) {
+  FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
+
+  ClangTool Tool(Compilations, std::vector(1, "/a.cc"));
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+
+  CommandLineArguments FinalArgs;
+  ArgumentsAdjuster CheckFlagsAdjuster =
+[](const CommandLineArguments , StringRef /*unused*/) {
+  FinalArgs = Args;
+  return Args;
+};
+  Tool.clearArgumentsAdjusters();
+  Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
+  Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
+  Tool.run(Action.get());
+
+  auto HasFlag = [](const std::string ) {
+return std::find(FinalArgs.begin(), FinalArgs.end(), Flag) !=
+   FinalArgs.end();
+  };
+  EXPECT_FALSE(HasFlag("-MD"));
+  EXPECT_FALSE(HasFlag("-MMD"));
+  EXPECT_TRUE(HasFlag("-c"));
+  EXPECT_TRUE(HasFlag("-w"));
+}
+
 namespace {
 /// Find a 

r318529 - Fix skipping of flags in getClangStripDependencyFileAdjuster

2017-11-17 Thread Dave Lee via cfe-commits
Author: kastiglione
Date: Fri Nov 17 08:27:21 2017
New Revision: 318529

URL: http://llvm.org/viewvc/llvm-project?rev=318529=rev
Log:
Fix skipping of flags in getClangStripDependencyFileAdjuster

Summary:
The ArgumentsAdjuster returned from `getClangStripDependencyFileAdjuster` will
skip dependency flags, and also their associated values for those flags that
take an argument. This change corrects the handling of the `-MD` and `-MMD`
flags, which do not take an argument.

Reviewers: saugustine, klimek, alexshap

Reviewed By: alexshap

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
cfe/trunk/unittests/Tooling/ToolingTest.cpp

Modified: cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp?rev=318529=318528=318529=diff
==
--- cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp (original)
+++ cfe/trunk/lib/Tooling/ArgumentsAdjusters.cpp Fri Nov 17 08:27:21 2017
@@ -58,14 +58,14 @@ ArgumentsAdjuster getClangStripDependenc
   StringRef Arg = Args[i];
   // All dependency-file options begin with -M. These include -MM,
   // -MF, -MG, -MP, -MT, -MQ, -MD, and -MMD.
-  if (!Arg.startswith("-M"))
+  if (!Arg.startswith("-M")) {
 AdjustedArgs.push_back(Args[i]);
+continue;
+  }
 
-  if ((Arg == "-MF") || (Arg == "-MT") || (Arg == "-MQ") ||
-  (Arg == "-MD") || (Arg == "-MMD")) {
-// Output is specified as -MX foo. Skip the next argument also.
+  if (Arg == "-MF" || Arg == "-MT" || Arg == "-MQ")
+// These flags take an argument: -MX foo. Skip the next argument also.
 ++i;
-  }
 }
 return AdjustedArgs;
   };

Modified: cfe/trunk/unittests/Tooling/ToolingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/ToolingTest.cpp?rev=318529=318528=318529=diff
==
--- cfe/trunk/unittests/Tooling/ToolingTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/ToolingTest.cpp Fri Nov 17 08:27:21 2017
@@ -402,6 +402,37 @@ TEST(ClangToolTest, ArgumentAdjusters) {
   EXPECT_FALSE(Found);
 }
 
+// Check getClangStripDependencyFileAdjuster doesn't strip args after -MD/-MMD.
+TEST(ClangToolTest, StripDependencyFileAdjuster) {
+  FixedCompilationDatabase Compilations("/", {"-MD", "-c", "-MMD", "-w"});
+
+  ClangTool Tool(Compilations, std::vector(1, "/a.cc"));
+  Tool.mapVirtualFile("/a.cc", "void a() {}");
+
+  std::unique_ptr Action(
+  newFrontendActionFactory());
+
+  CommandLineArguments FinalArgs;
+  ArgumentsAdjuster CheckFlagsAdjuster =
+[](const CommandLineArguments , StringRef /*unused*/) {
+  FinalArgs = Args;
+  return Args;
+};
+  Tool.clearArgumentsAdjusters();
+  Tool.appendArgumentsAdjuster(getClangStripDependencyFileAdjuster());
+  Tool.appendArgumentsAdjuster(CheckFlagsAdjuster);
+  Tool.run(Action.get());
+
+  auto HasFlag = [](const std::string ) {
+return std::find(FinalArgs.begin(), FinalArgs.end(), Flag) !=
+   FinalArgs.end();
+  };
+  EXPECT_FALSE(HasFlag("-MD"));
+  EXPECT_FALSE(HasFlag("-MMD"));
+  EXPECT_TRUE(HasFlag("-c"));
+  EXPECT_TRUE(HasFlag("-w"));
+}
+
 namespace {
 /// Find a target name such that looking for it in TargetRegistry by that name
 /// returns the same target. We expect that there is at least one target


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


[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-11-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 123349.
JonasToth added a comment.

- - fix ReleaseNotes


https://reviews.llvm.org/D37808

Files:
  clang-tidy/hicpp/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
  test/clang-tidy/hicpp-multiway-paths-covered.cpp

Index: test/clang-tidy/hicpp-multiway-paths-covered.cpp
===
--- /dev/null
+++ test/clang-tidy/hicpp-multiway-paths-covered.cpp
@@ -0,0 +1,467 @@
+// RUN: %check_clang_tidy %s hicpp-multiway-paths-covered %t
+
+enum OS { Mac,
+  Windows,
+  Linux };
+
+struct Bitfields {
+  unsigned UInt : 3;
+  int SInt : 1;
+};
+
+int return_integer() { return 42; }
+
+void bad_switch(int i) {
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // No default in this switch
+  switch (i) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+break;
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  // degenerate, maybe even warning
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch without labels
+  }
+
+  switch (int j = return_integer()) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+  case 2:
+break;
+  }
+
+  // Degenerated, only default case.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // Degenerated, only one case label and default case -> Better as if-stmt.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch could be better written as an if/else statement
+  case 0:
+break;
+  default:
+break;
+  }
+
+  unsigned long long BigNumber = 0;
+  switch (BigNumber) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  const int  = i;
+  switch (IntRef) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  char C = 'A';
+  switch (C) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 'A':
+break;
+  case 'B':
+break;
+  }
+
+  Bitfields Bf;
+  // UInt has 3 bits size.
+  switch (Bf.UInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.UInt) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+break;
+  }
+  // SInt has 1 bit size, so this is somewhat degenerated.
+  switch (Bf.SInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.SInt) {
+  case 0:
+  case 1:
+break;
+  }
+
+  bool Flag = false;
+  switch (Flag) {
+// CHECK-MESSAGES:[[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case true:
+break;
+  }
+
+  switch (Flag) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // This `switch` will create a frontend warning from '-Wswitch-bool' but is
+  // ok for this check.
+  switch (Flag) {
+  case true:
+break;
+  case false:
+break;
+  }
+}
+
+void unproblematic_switch(unsigned char c) {
+  switch (c) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+  case 11:
+  case 12:
+  case 13:
+  case 14:
+  case 15:
+  case 16:
+  case 17:
+  case 18:
+  case 19:
+  case 20:
+  case 21:
+  case 22:
+  case 23:
+  case 24:
+  case 25:
+  case 26:
+  case 27:
+  case 28:
+  case 29:
+  case 30:
+  case 31:
+  case 32:
+  case 33:
+  case 34:
+  case 35:
+  case 36:
+  case 37:
+  case 38:
+  case 39:
+  case 40:
+  case 41:
+  case 42:
+  case 43:
+  case 44:
+  case 45:
+  case 46:
+  case 47:
+  case 48:
+  case 49:
+  case 50:
+  case 51:
+  case 52:
+  case 53:
+  case 54:
+  case 55:
+  case 56:
+  case 57:
+  case 58:
+  case 59:
+  case 60:
+  case 61:
+  case 62:
+  case 63:
+  case 64:
+  case 65:
+  case 66:
+  case 67:
+  case 68:
+  case 69:
+  case 70:
+  case 71:
+  case 72:
+  case 73:
+  case 74:
+  case 75:
+  case 76:
+  case 77:
+  case 78:
+  case 79:
+  case 80:
+  case 81:
+  case 82:
+  case 83:
+  case 84:
+  case 85:
+  case 86:
+  case 87:
+  case 88:
+  case 89:
+  case 90:
+  case 91:
+ 

[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-11-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 123347.
JonasToth marked 12 inline comments as done.
JonasToth added a comment.

- address more comments, especially doc


https://reviews.llvm.org/D37808

Files:
  clang-tidy/hicpp/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
  test/clang-tidy/hicpp-multiway-paths-covered.cpp

Index: test/clang-tidy/hicpp-multiway-paths-covered.cpp
===
--- /dev/null
+++ test/clang-tidy/hicpp-multiway-paths-covered.cpp
@@ -0,0 +1,467 @@
+// RUN: %check_clang_tidy %s hicpp-multiway-paths-covered %t
+
+enum OS { Mac,
+  Windows,
+  Linux };
+
+struct Bitfields {
+  unsigned UInt : 3;
+  int SInt : 1;
+};
+
+int return_integer() { return 42; }
+
+void bad_switch(int i) {
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // No default in this switch
+  switch (i) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+break;
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  // degenerate, maybe even warning
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch without labels
+  }
+
+  switch (int j = return_integer()) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+  case 2:
+break;
+  }
+
+  // Degenerated, only default case.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // Degenerated, only one case label and default case -> Better as if-stmt.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch could be better written as an if/else statement
+  case 0:
+break;
+  default:
+break;
+  }
+
+  unsigned long long BigNumber = 0;
+  switch (BigNumber) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  const int  = i;
+  switch (IntRef) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  char C = 'A';
+  switch (C) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 'A':
+break;
+  case 'B':
+break;
+  }
+
+  Bitfields Bf;
+  // UInt has 3 bits size.
+  switch (Bf.UInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.UInt) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+break;
+  }
+  // SInt has 1 bit size, so this is somewhat degenerated.
+  switch (Bf.SInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.SInt) {
+  case 0:
+  case 1:
+break;
+  }
+
+  bool Flag = false;
+  switch (Flag) {
+// CHECK-MESSAGES:[[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case true:
+break;
+  }
+
+  switch (Flag) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // This `switch` will create a frontend warning from '-Wswitch-bool' but is
+  // ok for this check.
+  switch (Flag) {
+  case true:
+break;
+  case false:
+break;
+  }
+}
+
+void unproblematic_switch(unsigned char c) {
+  switch (c) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+  case 11:
+  case 12:
+  case 13:
+  case 14:
+  case 15:
+  case 16:
+  case 17:
+  case 18:
+  case 19:
+  case 20:
+  case 21:
+  case 22:
+  case 23:
+  case 24:
+  case 25:
+  case 26:
+  case 27:
+  case 28:
+  case 29:
+  case 30:
+  case 31:
+  case 32:
+  case 33:
+  case 34:
+  case 35:
+  case 36:
+  case 37:
+  case 38:
+  case 39:
+  case 40:
+  case 41:
+  case 42:
+  case 43:
+  case 44:
+  case 45:
+  case 46:
+  case 47:
+  case 48:
+  case 49:
+  case 50:
+  case 51:
+  case 52:
+  case 53:
+  case 54:
+  case 55:
+  case 56:
+  case 57:
+  case 58:
+  case 59:
+  case 60:
+  case 61:
+  case 62:
+  case 63:
+  case 64:
+  case 65:
+  case 66:
+  case 67:
+  case 68:
+  case 69:
+  case 70:
+  case 71:
+  case 72:
+  case 73:
+  case 74:
+  case 75:
+  case 76:
+  case 77:
+  case 78:
+  case 79:
+  case 80:
+  case 81:
+  case 82:
+  case 83:
+  case 84:
+  case 85:
+  case 

[PATCH] D39611: [CodeGen] change const-ness of complex calls

2017-11-17 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added a comment.

Ping.


https://reviews.llvm.org/D39611



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


[PATCH] D39049: [analyzer] Fix wrong calculation of offset in ArrayBoundsV2

2017-11-17 Thread Daniel Marjamäki via Phabricator via cfe-commits
danielmarjamaki added a comment.

> So what are the arguments that are passed to getSimplifiedOffset() in that 
> case? 0? That does not seem to be correct.

yes.

so the conclusion is:

- this code does not work
- this code is untested
- this code is not even used in the use cases it was intended for because of 
bugs elsewhere

therefore it should be removed.


Repository:
  rL LLVM

https://reviews.llvm.org/D39049



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


[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-11-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:13
+
+#include 
+#include 

aaron.ballman wrote:
> Including  is forbidden by our coding standard. However, it doesn't 
> appear to be used in the source file, either.
Yes, forgot it from debugging.



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:91-92
+  // Context.getTypeSize(T) returns the number of bits T uses.
+  // Calculates the number of discrete values that are representable by this
+  // type.
+  return T->isIntegralType(Context) ? twoPow(Context.getTypeSize(T))

aaron.ballman wrote:
> I don't think this comment adds value.
i dropped all of it. The function doc should be clear enough, is it?



Comment at: clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp:94
+  return T->isIntegralType(Context) ? twoPow(Context.getTypeSize(T))
+: twoPow(0ul);
+}

aaron.ballman wrote:
> aaron.ballman wrote:
> > No need for the `ul` suffix -- the type will undergo implicit conversion 
> > with or without the suffix.
> Why call toPow instead of just returning the value `1` directly?
True!



Comment at: test/clang-tidy/hicpp-multiway-paths-covered.cpp:445
+  }
+}

aaron.ballman wrote:
> For fun, can you add a switch over a value of type `bool`?
> ```
> void f(bool b) {
>   switch (b) {
>   case true:
>   }
> 
>   switch (b) {
>   default:
>   }
> 
>   switch (b) {
>   case true:
>   case false:
>   }
> }
> ```
There is already a warning in the frontend (-Wswitch-bool) that will complain 
about boolean conditions in `switch`.

I will implement the logic anyway. I think its more userfriendly to get this 
warning. One might have code style that allows switch for bools.


https://reviews.llvm.org/D37808



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


[PATCH] D37808: [clang-tidy] Add new hicpp-multiway-paths-covered check for missing branches

2017-11-17 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 123345.
JonasToth marked 18 inline comments as done.
JonasToth added a comment.

- rebase to master
- address review comments from aaron
- handle bools correctly


https://reviews.llvm.org/D37808

Files:
  clang-tidy/hicpp/CMakeLists.txt
  clang-tidy/hicpp/HICPPTidyModule.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp
  clang-tidy/hicpp/MultiwayPathsCoveredCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/hicpp-multiway-paths-covered.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/hicpp-multiway-paths-covered-else.cpp
  test/clang-tidy/hicpp-multiway-paths-covered.cpp

Index: test/clang-tidy/hicpp-multiway-paths-covered.cpp
===
--- /dev/null
+++ test/clang-tidy/hicpp-multiway-paths-covered.cpp
@@ -0,0 +1,467 @@
+// RUN: %check_clang_tidy %s hicpp-multiway-paths-covered %t
+
+enum OS { Mac,
+  Windows,
+  Linux };
+
+struct Bitfields {
+  unsigned UInt : 3;
+  int SInt : 1;
+};
+
+int return_integer() { return 42; }
+
+void bad_switch(int i) {
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // No default in this switch
+  switch (i) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+break;
+  case 1:
+break;
+  case 2:
+break;
+  }
+
+  // degenerate, maybe even warning
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch without labels
+  }
+
+  switch (int j = return_integer()) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+  case 2:
+break;
+  }
+
+  // Degenerated, only default case.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // Degenerated, only one case label and default case -> Better as if-stmt.
+  switch (i) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch could be better written as an if/else statement
+  case 0:
+break;
+  default:
+break;
+  }
+
+  unsigned long long BigNumber = 0;
+  switch (BigNumber) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  const int  = i;
+  switch (IntRef) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+
+  char C = 'A';
+  switch (C) {
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 'A':
+break;
+  case 'B':
+break;
+  }
+
+  Bitfields Bf;
+  // UInt has 3 bits size.
+  switch (Bf.UInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: potential uncovered code path; add a default label
+  case 0:
+  case 1:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.UInt) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+break;
+  }
+  // SInt has 1 bit size, so this is somewhat degenerated.
+  switch (Bf.SInt) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case 0:
+break;
+  }
+  // All paths explicitly covered.
+  switch (Bf.SInt) {
+  case 0:
+  case 1:
+break;
+  }
+
+  bool Flag = false;
+  switch (Flag) {
+// CHECK-MESSAGES:[[@LINE-1]]:3: warning: switch with only one case; use an if statement
+  case true:
+break;
+  }
+
+  switch (Flag) {
+// CHECK-MESSAGES: [[@LINE-1]]:3: warning: degenerated switch with default label only
+  default:
+break;
+  }
+
+  // This `switch` will create a frontend warning from '-Wswitch-bool' but is
+  // ok for this check.
+  switch (Flag) {
+  case true:
+break;
+  case false:
+break;
+  }
+}
+
+void unproblematic_switch(unsigned char c) {
+  switch (c) {
+  case 0:
+  case 1:
+  case 2:
+  case 3:
+  case 4:
+  case 5:
+  case 6:
+  case 7:
+  case 8:
+  case 9:
+  case 10:
+  case 11:
+  case 12:
+  case 13:
+  case 14:
+  case 15:
+  case 16:
+  case 17:
+  case 18:
+  case 19:
+  case 20:
+  case 21:
+  case 22:
+  case 23:
+  case 24:
+  case 25:
+  case 26:
+  case 27:
+  case 28:
+  case 29:
+  case 30:
+  case 31:
+  case 32:
+  case 33:
+  case 34:
+  case 35:
+  case 36:
+  case 37:
+  case 38:
+  case 39:
+  case 40:
+  case 41:
+  case 42:
+  case 43:
+  case 44:
+  case 45:
+  case 46:
+  case 47:
+  case 48:
+  case 49:
+  case 50:
+  case 51:
+  case 52:
+  case 53:
+  case 54:
+  case 55:
+  case 56:
+  case 57:
+  case 58:
+  case 59:
+  case 60:
+  case 61:
+  case 62:
+  case 63:
+  case 64:
+  case 65:
+  case 66:
+  case 67:
+  case 68:
+  case 69:
+  case 70:
+  case 71:
+  case 72:
+  case 73:
+  case 74:
+  case 75:
+  case 76:
+  case 77:
+  case 78:
+  case 79:
+  case 80:
+  case 81:
+  case 82:
+  

[PATCH] D40178: clang-format: [JS] remove trailing lines in arrow functions.

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

clang-format already removes lines trailing at the end of blocks:

  function x() {
foo();  // next line will be removed.
  
  }

However because JS arrow functions are parsed as expressions, the existing logic
to remove empty lines in UnwrappedLineFormatter doesn't handle them. This code
special cases arrow functions in ContinuationIndenter to remove any trailing
spaces:

  x = () => {
foo();  // next line will (now) be removed.
  
  };


https://reviews.llvm.org/D40178

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


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,16 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesTrailingArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,18 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Style.Language == FormatStyle::LK_JavaScript &&
+Current.is(tok::r_brace) && Current.MatchingParen &&
+Current.MatchingParen->Previous &&
+Current.MatchingParen->Previous->is(TT_JsFatArrow)) {
+  // JavaScript arrow functions are experssions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's 
logic
+  // about removing empty lines on closing blocks. Special case it here.
+  MaxEmptyLinesToKeep = 0;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, 
State.Column,


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1606,6 +1606,16 @@
   Style);
 }
 
+TEST_F(FormatTestJS, RemoveEmptyLinesTrailingArrowFunctions) {
+  verifyFormat("x = () => {\n"
+   "  foo();\n"
+   "};\n",
+   "x = () => {\n"
+   "  foo();\n"
+   "\n"
+   "};\n");
+}
+
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -701,8 +701,18 @@
 State.Stack.back().BreakBeforeParameter = false;
 
   if (!DryRun) {
+unsigned MaxEmptyLinesToKeep = Style.MaxEmptyLinesToKeep + 1;
+if (Style.Language == FormatStyle::LK_JavaScript &&
+Current.is(tok::r_brace) && Current.MatchingParen &&
+Current.MatchingParen->Previous &&
+Current.MatchingParen->Previous->is(TT_JsFatArrow)) {
+  // JavaScript arrow functions are experssions, thus their r_brace is not
+  // on its own line, and thus not covered by UnwrappedLineFormatter's logic
+  // about removing empty lines on closing blocks. Special case it here.
+  MaxEmptyLinesToKeep = 0;
+}
 unsigned Newlines = std::max(
-1u, std::min(Current.NewlinesBefore, Style.MaxEmptyLinesToKeep + 1));
+1u, std::min(Current.NewlinesBefore, MaxEmptyLinesToKeep));
 bool ContinuePPDirective =
 State.Line->InPPDirective && State.Line->Type != LT_ImportStatement;
 Whitespaces.replaceWhitespace(Current, Newlines, State.Column, State.Column,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40089: [clangd] Make completion scores use 0-1 floats internally.

2017-11-17 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

A few comments based on our discussion.




Comment at: clangd/ClangdUnit.cpp:387
 
   std::string sortText() const {
 std::string S, NameStorage;

example



Comment at: clangd/ClangdUnit.cpp:416
+
+  // Produces an integer that sorts in the same order as F.
+  static uint32_t encodeFloat(float F) {

nit: mention that if a < b, encodeFloat(a) < encodeFloat(b)



Comment at: clangd/ClangdUnit.cpp:417
+  // Produces an integer that sorts in the same order as F.
+  static uint32_t encodeFloat(float F) {
+// IEEE 754 floats compare like 2s complement integers.

I think we'd better have unittest for this function.



Comment at: clangd/ClangdUnit.cpp:423
+memcpy(, , sizeof(float));
+// Convert U from 2s complement to unsigned, preserving order.
+const uint32_t SignBit = ~(~uint32_t{0} >> 1);

Would be nice to explain more what we do here: we are trying to remap from the 
signed range [INT_MIN, INT_MAX] to the unsigned range [0, UINT_MAX], so that we 
can compare them via string literal comparison.



Comment at: clangd/ClangdUnit.cpp:425
+const uint32_t SignBit = ~(~uint32_t{0} >> 1);
+return U & SignBit ? 0 - U : U + SignBit;
+  }

U ^ SignBit



Comment at: test/clangd/completion-items-kinds.test:1
 # RUN: clangd -enable-snippets -run-synchronously < %s | FileCheck %s
 # It is absolutely vital that this file has CRLF line endings.

an off-topic comment: why not using `-pretty` in this test?


https://reviews.llvm.org/D40089



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


[PATCH] D40176: [CodeGen] Collect information about sizes of accesses and access types for TBAA

2017-11-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev created this revision.
kosarev added a project: clang.

The information about access and type sizes is necessary for producing TBAA 
metadata in the new size-aware format. With this patch, 
https://reviews.llvm.org/D39955 and https://reviews.llvm.org/D39956 in place we 
should be able to change CodeGenTBAA::createScalarTypeNode() and 
CodeGenTBAA::getBaseTypeInfo() to generate metadata in the new format under the 
-new-struct-path-tbaa command-line option. For now, this new information 
remains unused.


Repository:
  rL LLVM

https://reviews.llvm.org/D40176

Files:
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/CodeGen/CodeGenTBAA.cpp
  lib/CodeGen/CodeGenTBAA.h

Index: lib/CodeGen/CodeGenTBAA.h
===
--- lib/CodeGen/CodeGenTBAA.h
+++ lib/CodeGen/CodeGenTBAA.h
@@ -36,40 +36,53 @@
 enum class TBAAAccessKind : unsigned {
   Ordinary,
   MayAlias,
+  Incomplete,
 };
 
 // TBAAAccessInfo - Describes a memory access in terms of TBAA.
 struct TBAAAccessInfo {
   TBAAAccessInfo(TBAAAccessKind Kind, llvm::MDNode *BaseType,
- llvm::MDNode *AccessType, uint64_t Offset)
-: Kind(Kind), BaseType(BaseType), AccessType(AccessType), Offset(Offset)
+ llvm::MDNode *AccessType, uint64_t Offset, uint64_t Size)
+: Kind(Kind), BaseType(BaseType), AccessType(AccessType),
+  Offset(Offset), Size(Size)
   {}
 
   TBAAAccessInfo(llvm::MDNode *BaseType, llvm::MDNode *AccessType,
- uint64_t Offset)
-: TBAAAccessInfo(TBAAAccessKind::Ordinary, BaseType, AccessType, Offset)
+ uint64_t Offset, uint64_t Size)
+: TBAAAccessInfo(TBAAAccessKind::Ordinary, BaseType, AccessType,
+ Offset, Size)
   {}
 
-  explicit TBAAAccessInfo(llvm::MDNode *AccessType)
-: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0)
+  explicit TBAAAccessInfo(llvm::MDNode *AccessType, uint64_t Size)
+: TBAAAccessInfo(/* BaseType= */ nullptr, AccessType, /* Offset= */ 0, Size)
   {}
 
   TBAAAccessInfo()
-: TBAAAccessInfo(/* AccessType= */ nullptr)
+: TBAAAccessInfo(/* AccessType= */ nullptr, /* Size= */ 0)
   {}
 
   static TBAAAccessInfo getMayAliasInfo() {
-return TBAAAccessInfo(TBAAAccessKind::MayAlias, /* BaseType= */ nullptr,
-  /* AccessType= */ nullptr, /* Offset= */ 0);
+return TBAAAccessInfo(TBAAAccessKind::MayAlias,
+  /* BaseType= */ nullptr, /* AccessType= */ nullptr,
+  /* Offset= */ 0, /* Size= */ 0);
   }
 
   bool isMayAlias() const { return Kind == TBAAAccessKind::MayAlias; }
 
+  static TBAAAccessInfo getIncompleteInfo() {
+return TBAAAccessInfo(TBAAAccessKind::Incomplete,
+  /* BaseType= */ nullptr, /* AccessType= */ nullptr,
+  /* Offset= */ 0, /* Size= */ 0);
+  }
+
+  bool isIncomplete() const { return Kind == TBAAAccessKind::Incomplete; }
+
   bool operator==(const TBAAAccessInfo ) const {
 return Kind == Other.Kind &&
BaseType == Other.BaseType &&
AccessType == Other.AccessType &&
-   Offset == Other.Offset;
+   Offset == Other.Offset &&
+   Size == Other.Size;
   }
 
   bool operator!=(const TBAAAccessInfo ) const {
@@ -95,12 +108,16 @@
   /// Offset - The byte offset of the final access within the base one. Must be
   /// zero if the base access type is not specified.
   uint64_t Offset;
+
+  /// Size - The size of access, in bytes.
+  uint64_t Size;
 };
 
 /// CodeGenTBAA - This class organizes the cross-module state that is used
 /// while lowering AST types to LLVM types.
 class CodeGenTBAA {
   ASTContext 
+  llvm::Module 
   const CodeGenOptions 
   const LangOptions 
   MangleContext 
@@ -138,25 +155,23 @@
  SmallVectorImpl ,
  bool MayAlias);
 
-  /// A wrapper function to create a scalar type. For struct-path aware TBAA,
-  /// the scalar type has the same format as the struct type: name, offset,
-  /// pointer to another node in the type DAG.
-  llvm::MDNode *createTBAAScalarType(StringRef Name, llvm::MDNode *Parent);
+  /// createScalarTypeNode - A wrapper function to create metadata nodes
+  /// describing scalar types.
+  llvm::MDNode *createScalarTypeNode(StringRef Name, llvm::MDNode *Parent,
+ uint64_t Size);
 
 public:
-  CodeGenTBAA(ASTContext , llvm::LLVMContext ,
-  const CodeGenOptions ,
-  const LangOptions ,
-  MangleContext );
+  CodeGenTBAA(ASTContext , llvm::Module , const CodeGenOptions ,
+  const LangOptions , MangleContext );
   ~CodeGenTBAA();
 
   /// getTypeInfo - Get metadata used to describe accesses to objects of the
   /// given type.
   llvm::MDNode *getTypeInfo(QualType QTy);
 
   /// getVTablePtrAccessInfo - Get the TBAA information that describes an
   

[PATCH] D40120: [clang-format] Add text proto filename detection

2017-11-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318525: [clang-format] Add text proto filename detection 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D40120

Files:
  cfe/trunk/lib/Format/Format.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2084,6 +2084,11 @@
   if (FileName.endswith_lower(".proto") ||
   FileName.endswith_lower(".protodevel"))
 return FormatStyle::LK_Proto;
+  if (FileName.endswith_lower(".textpb") ||
+  FileName.endswith_lower(".pb.txt") ||
+  FileName.endswith_lower(".textproto") ||
+  FileName.endswith_lower(".asciipb"))
+return FormatStyle::LK_TextProto;
   if (FileName.endswith_lower(".td"))
 return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -2084,6 +2084,11 @@
   if (FileName.endswith_lower(".proto") ||
   FileName.endswith_lower(".protodevel"))
 return FormatStyle::LK_Proto;
+  if (FileName.endswith_lower(".textpb") ||
+  FileName.endswith_lower(".pb.txt") ||
+  FileName.endswith_lower(".textproto") ||
+  FileName.endswith_lower(".asciipb"))
+return FormatStyle::LK_TextProto;
   if (FileName.endswith_lower(".td"))
 return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D20124: [PCH] Serialize skipped preprocessor ranges

2017-11-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D20124#927967, @cameron314 wrote:

> Well, it seems like preamble PCH source location translation is fundamentally 
> broken. The entry file has a single, positive file ID. The preamble PCH is 
> treated as an imported module, so it has a negative file ID for the part that 
> overlaps the preamble of the entry file. That means locations in the preamble 
> part of the entry file can have two different file IDs depending on how they 
> are arrived at.
>
> I really don't know how to fix this. Any ideas?


Why do we store raw source locations in `PPSkippedRange`? Would storing 
`SourceLocation` and using  `ASTWriter::AddSourceLocation` and `ASTReader:: 
ReadSourceLocation` do the trick?


https://reviews.llvm.org/D20124



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


r318525 - [clang-format] Add text proto filename detection

2017-11-17 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Fri Nov 17 07:10:49 2017
New Revision: 318525

URL: http://llvm.org/viewvc/llvm-project?rev=318525=rev
Log:
[clang-format] Add text proto filename detection

Summary: Adds text proto filename detection.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=318525=318524=318525=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Nov 17 07:10:49 2017
@@ -2084,6 +2084,11 @@ static FormatStyle::LanguageKind getLang
   if (FileName.endswith_lower(".proto") ||
   FileName.endswith_lower(".protodevel"))
 return FormatStyle::LK_Proto;
+  if (FileName.endswith_lower(".textpb") ||
+  FileName.endswith_lower(".pb.txt") ||
+  FileName.endswith_lower(".textproto") ||
+  FileName.endswith_lower(".asciipb"))
+return FormatStyle::LK_TextProto;
   if (FileName.endswith_lower(".td"))
 return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;


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


[PATCH] D39438: [analyzer] Diagnose stack leaks via block captures

2017-11-17 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I found some nits, but overall I think this is getting close.




Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:76
 range = CL->getSourceRange();
-  }
-  else if (const AllocaRegion* AR = dyn_cast(R)) {
+  } else if (const AllocaRegion *AR = dyn_cast(R)) {
 const Expr *ARE = AR->getExpr();

In case you already change these lines you could replace the type name on the 
left side with `auto` to avoid repeating types. 



Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:123
+  for (const auto  : B.captures()) {
+const TypedefType *T = C.getVariable()->getType()->getAs();
+if (T && T->getDecl()->getIdentifier() == dispatch_semaphore_tII)

You can also use auto here to avoid mentioning the type twice. 



Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:192
+  this, "Address of stack-allocated memory is captured");
+SmallString<512> Buf;
+llvm::raw_svector_ostream Out(Buf);

How long usually these error messages are? Maybe 512 is a bit large buffer for 
this? Note that in case the error message is longer this is still not a hard 
error, it just will hit the slow path (allocating the buffer on the heap).



Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:214
+  BT_capturedstackret = llvm::make_unique(
+  this, "Address of stack-allocated memory");
+SmallString<512> Buf;

Maybe you wanted to mention "captured" here as well?



Comment at: lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:215
+  this, "Address of stack-allocated memory");
+SmallString<512> Buf;
+llvm::raw_svector_ostream Out(Buf);

Maybe the error reporting part could be abstracted out to avoid code 
duplication with the function above?


Repository:
  rL LLVM

https://reviews.llvm.org/D39438



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


[PATCH] D40120: [clang-format] Add text proto filename detection

2017-11-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D40120



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


[PATCH] D39913: [ObjC] warn about availability attributes missing from a method's declaration when they're specified for a method's definition

2017-11-17 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington accepted this revision.
erik.pilkington added a comment.
This revision is now accepted and ready to land.

> It's harder as we don't know the distinction between declaration/definition 
> at merge time. Right now the C++ implementation of this warning actually 
> checks the attributes too late, after they're merged. I'll take out the C++/C 
> support completely and keep to ObjC in this patch for simplicity. The rest 
> can be supported later.

That sounds fine for now! LGTM


Repository:
  rL LLVM

https://reviews.llvm.org/D39913



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


[PATCH] D39955: [Driver] Add a cc1 flag for the new TBAA metadata format

2017-11-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev updated this revision to Diff 123320.
kosarev retitled this revision from "[Driver] Add command-line flags for the 
new TBAA metadata format" to "[Driver] Add a cc1 flag for the new TBAA metadata 
format".
kosarev added a comment.

Removed the clang command-line flag for the new format.


https://reviews.llvm.org/D39955

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/Frontend/CompilerInvocation.cpp


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -546,6 +546,8 @@
 OPT_fuse_register_sized_bitfield_access);
   Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
   Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa);
+  Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) &&
+   Args.hasArg(OPT_new_struct_path_tbaa);
   Opts.FineGrainedBitfieldAccesses =
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -144,6 +144,7 @@
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is 
enabled.
 CODEGENOPT(StructPathTBAA, 1, 0) ///< Whether or not to use struct-path 
TBAA.
+CODEGENOPT(NewStructPathTBAA , 1, 0) ///< Whether or not to use enhanced 
struct-path TBAA.
 CODEGENOPT(SaveTempLabels, 1, 0) ///< Save temporary labels.
 CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0) ///< Enable use-after-scope 
detection
 ///< in AddressSanitizer
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -244,6 +244,8 @@
   HelpText<"Turn off Type Based Alias Analysis">;
 def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">,
   HelpText<"Turn off struct-path aware Type Based Alias Analysis">;
+def new_struct_path_tbaa : Flag<["-"], "new-struct-path-tbaa">,
+  HelpText<"Enable enhanced struct-path aware Type Based Alias Analysis">;
 def masm_verbose : Flag<["-"], "masm-verbose">,
   HelpText<"Generate verbose assembly output">;
 def mcode_model : Separate<["-"], "mcode-model">,


Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -546,6 +546,8 @@
 OPT_fuse_register_sized_bitfield_access);
   Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
   Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa);
+  Opts.NewStructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa) &&
+   Args.hasArg(OPT_new_struct_path_tbaa);
   Opts.FineGrainedBitfieldAccesses =
   Args.hasFlag(OPT_ffine_grained_bitfield_accesses,
OPT_fno_fine_grained_bitfield_accesses, false);
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -144,6 +144,7 @@
 CODEGENOPT(RelaxAll  , 1, 0) ///< Relax all machine code instructions.
 CODEGENOPT(RelaxedAliasing   , 1, 0) ///< Set when -fno-strict-aliasing is enabled.
 CODEGENOPT(StructPathTBAA, 1, 0) ///< Whether or not to use struct-path TBAA.
+CODEGENOPT(NewStructPathTBAA , 1, 0) ///< Whether or not to use enhanced struct-path TBAA.
 CODEGENOPT(SaveTempLabels, 1, 0) ///< Save temporary labels.
 CODEGENOPT(SanitizeAddressUseAfterScope , 1, 0) ///< Enable use-after-scope detection
 ///< in AddressSanitizer
Index: include/clang/Driver/CC1Options.td
===
--- include/clang/Driver/CC1Options.td
+++ include/clang/Driver/CC1Options.td
@@ -244,6 +244,8 @@
   HelpText<"Turn off Type Based Alias Analysis">;
 def no_struct_path_tbaa : Flag<["-"], "no-struct-path-tbaa">,
   HelpText<"Turn off struct-path aware Type Based Alias Analysis">;
+def new_struct_path_tbaa : Flag<["-"], "new-struct-path-tbaa">,
+  HelpText<"Enable enhanced struct-path aware Type Based Alias Analysis">;
 def masm_verbose : Flag<["-"], "masm-verbose">,
   HelpText<"Generate verbose assembly output">;
 def mcode_model : Separate<["-"], "mcode-model">,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39953: [CodeGen] Do not lookup for cached TBAA metadata nodes twice

2017-11-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Indeed, DenseMap invalidates iterators on insertion. But then even the 
"technically correct" part of these changes make things more fragile while my 
original concern was reliability and not performance. I particularly don't like 
the repeating cache assignments.

What if we add a set of helper functions whose only purpose is to produce new 
nodes so we can handle cache-related things in a single place? Something like 
this:

  llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(llvm::Type *Type) {
... Whatever we currently do in getTypeInfo(), except accesses to 
MetadataCache ...
  }
  
  llvm::MDNode *CodeGenTBAA::getTypeInfo(QualType QTy) {
...
const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
if (llvm::MDNode *N = MetadataCache[Ty])
  return N;
  
return MetadataCache[Ty] = getTypeInfoHelper(Ty);
  }

If for any reasons it is undesirable, then I think I better abandon this diff. 
Maybe just add a comment explaining that we lookup twice for the same key 
intentionally.


Repository:
  rL LLVM

https://reviews.llvm.org/D39953



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


[PATCH] D39455: [CodeGen] Add initial support for union members in TBAA

2017-11-17 Thread Ivan Kosarev via Phabricator via cfe-commits
kosarev added a comment.

Thanks John.

Hal, do you see any problems with this patch?


Repository:
  rL LLVM

https://reviews.llvm.org/D39455



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


[clang-tools-extra] r318523 - [clang-tidy] Fix an oversight after renaming a check

2017-11-17 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Nov 17 04:28:58 2017
New Revision: 318523

URL: http://llvm.org/viewvc/llvm-project?rev=318523=rev
Log:
[clang-tidy] Fix an oversight after renaming a check

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318523=318522=318523=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Nov 
17 04:28:58 2017
@@ -23,7 +23,7 @@ class BugproneModule : public ClangTidyM
 public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
 CheckFactories.registerCheck(
-"misc-copy-constructor-init");
+"bugprone-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-integer-division");
 CheckFactories.registerCheck(

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp?rev=318523=318522=318523=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp 
Fri Nov 17 04:28:58 2017
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-copy-constructor-init %t
+// RUN: %check_clang_tidy %s bugprone-copy-constructor-init %t
 
 class NonCopyable {
 public:
@@ -79,7 +79,7 @@ class X : public Copyable, public EmptyC
 
 class X2 : public Copyable2 {
   X2(const X2 ) {}
-  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling a base constructor other 
than the copy constructor [misc-copy-constructor-init]
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: calling a base constructor other 
than the copy constructor [bugprone-copy-constructor-init]
   // CHECK-FIXES: X2(const X2 )  : Copyable2(other) {}
 };
 


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


[clang-tools-extra] r318522 - [clang-tidy] Add a check for undelegated copy of base classes

2017-11-17 Thread Gabor Horvath via cfe-commits
Author: xazax
Date: Fri Nov 17 04:23:30 2017
New Revision: 318522

URL: http://llvm.org/viewvc/llvm-project?rev=318522=rev
Log:
[clang-tidy] Add a check for undelegated copy of base classes

Finds copy constructors where the constructor don't call
the copy constructor of the base class.

```
class X : public Copyable {
X(const X ) {} // Copyable(other) is missing
};
```

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

Added:
clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-copy-constructor-init.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp?rev=318522=318521=318522=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp Fri Nov 
17 04:23:30 2017
@@ -10,6 +10,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
+#include "CopyConstructorInitCheck.h"
 #include "IntegerDivisionCheck.h"
 #include "SuspiciousMemsetUsageCheck.h"
 #include "UndefinedMemoryManipulationCheck.h"
@@ -21,6 +22,8 @@ namespace bugprone {
 class BugproneModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories ) override {
+CheckFactories.registerCheck(
+"misc-copy-constructor-init");
 CheckFactories.registerCheck(
 "bugprone-integer-division");
 CheckFactories.registerCheck(

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt?rev=318522=318521=318522=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt Fri Nov 17 
04:23:30 2017
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support)
 
 add_clang_library(clangTidyBugproneModule
   BugproneTidyModule.cpp
+  CopyConstructorInitCheck.cpp
   IntegerDivisionCheck.cpp
   SuspiciousMemsetUsageCheck.cpp
   UndefinedMemoryManipulationCheck.cpp

Added: clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp?rev=318522=auto
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp 
Fri Nov 17 04:23:30 2017
@@ -0,0 +1,121 @@
+//===--- CopyConstructorInitCheck.cpp - 
clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CopyConstructorInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // In the future this might be extended to move constructors?
+  Finder->addMatcher(
+  cxxConstructorDecl(
+  isCopyConstructor(),
+  hasAnyConstructorInitializer(cxxCtorInitializer(
+  isBaseInitializer(),
+  withInitializer(cxxConstructExpr(hasDeclaration(
+  cxxConstructorDecl(isDefaultConstructor())),
+  unless(isInstantiated()))
+  .bind("ctor"),
+  this);
+}
+
+void CopyConstructorInitCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Ctor = Result.Nodes.getNodeAs("ctor");
+  std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
+
+  // We want only one warning (and FixIt) for each ctor.
+  std::string FixItInitList;
+  bool HasRelevantBaseInit = false;
+  bool ShouldNotDoFixit = false;
+  bool HasWrittenInitializer = false;
+  SmallVector SafeFixIts;
+  for (const auto *Init : Ctor->inits()) {
+bool 

[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-11-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL318522: [clang-tidy] Add a check for undelegated copy of 
base classes (authored by xazax).

Changed prior to commit:
  https://reviews.llvm.org/D33722?vs=121886=123319#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33722

Files:
  clang-tools-extra/trunk/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
  clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-copy-constructor-init.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/bugprone-copy-constructor-init.cpp

Index: clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
@@ -0,0 +1,121 @@
+//===--- CopyConstructorInitCheck.cpp - clang-tidy-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "CopyConstructorInitCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace bugprone {
+
+void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  // In the future this might be extended to move constructors?
+  Finder->addMatcher(
+  cxxConstructorDecl(
+  isCopyConstructor(),
+  hasAnyConstructorInitializer(cxxCtorInitializer(
+  isBaseInitializer(),
+  withInitializer(cxxConstructExpr(hasDeclaration(
+  cxxConstructorDecl(isDefaultConstructor())),
+  unless(isInstantiated()))
+  .bind("ctor"),
+  this);
+}
+
+void CopyConstructorInitCheck::check(const MatchFinder::MatchResult ) {
+  const auto *Ctor = Result.Nodes.getNodeAs("ctor");
+  std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
+
+  // We want only one warning (and FixIt) for each ctor.
+  std::string FixItInitList;
+  bool HasRelevantBaseInit = false;
+  bool ShouldNotDoFixit = false;
+  bool HasWrittenInitializer = false;
+  SmallVector SafeFixIts;
+  for (const auto *Init : Ctor->inits()) {
+bool CtorInitIsWritten = Init->isWritten();
+HasWrittenInitializer = HasWrittenInitializer || CtorInitIsWritten;
+if (!Init->isBaseInitializer())
+  continue;
+const Type *BaseType = Init->getBaseClass();
+// Do not do fixits if there is a type alias involved or one of the bases
+// are explicitly initialized. In the latter case we not do fixits to avoid
+// -Wreorder warnings.
+if (const auto *TempSpecTy = dyn_cast(BaseType))
+  ShouldNotDoFixit = ShouldNotDoFixit || TempSpecTy->isTypeAlias();
+ShouldNotDoFixit = ShouldNotDoFixit || isa(BaseType);
+ShouldNotDoFixit = ShouldNotDoFixit || CtorInitIsWritten;
+const CXXRecordDecl *BaseClass =
+BaseType->getAsCXXRecordDecl()->getDefinition();
+if (BaseClass->field_empty() &&
+BaseClass->forallBases(
+[](const CXXRecordDecl *Class) { return Class->field_empty(); }))
+  continue;
+bool NonCopyableBase = false;
+for (const auto *Ctor : BaseClass->ctors()) {
+  if (Ctor->isCopyConstructor() &&
+  (Ctor->getAccess() == AS_private || Ctor->isDeleted())) {
+NonCopyableBase = true;
+break;
+  }
+}
+if (NonCopyableBase)
+  continue;
+const auto *CExpr = dyn_cast(Init->getInit());
+if (!CExpr || !CExpr->getConstructor()->isDefaultConstructor())
+  continue;
+HasRelevantBaseInit = true;
+if (CtorInitIsWritten) {
+  if (!ParamName.empty())
+SafeFixIts.push_back(
+FixItHint::CreateInsertion(CExpr->getLocEnd(), ParamName));
+} else {
+  if (Init->getSourceLocation().isMacroID() ||
+  Ctor->getLocation().isMacroID() || ShouldNotDoFixit)
+break;
+  FixItInitList += BaseClass->getNameAsString();
+  FixItInitList += "(" + ParamName + "), ";
+}
+  }
+  if (!HasRelevantBaseInit)
+return;
+
+  auto Diag = diag(Ctor->getLocation(),
+   "calling a base constructor other than the copy constructor")
+  << SafeFixIts;
+
+  if (FixItInitList.empty() || ParamName.empty() || ShouldNotDoFixit)
+return;
+
+  std::string 

[PATCH] D37299: [Modules] Add ability to specify module name to module file mapping in a file

2017-11-17 Thread Boris Kolpackov via Phabricator via cfe-commits
boris added a comment.

Ping.

Also, to add to my previous comment, even if for a moment we ignore the header 
dependencies and when they are extracted, a modern build system normally tracks 
other kinds of what can be called "auxiliary dependency information": some form 
of compiler signature, hash of options that were used to compile the file, 
etc., so that when any of those change, the object file gets recompiled 
automatically. For example, in build2, we store all these signatures/hashes 
plus the header and module dependency information in a single .d file (which we 
call auxiliary dependency database). What I am trying to show by this is that 
it is well established that for C/C++ compilation there has to be an extra file 
for each .o where such information is stored. And it seems natural to want to 
reuse this file for supplying the "module map" to the compiler instead of 
creating yet another per-.o file.


https://reviews.llvm.org/D37299



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


r318515 - Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Manuel Klimek via cfe-commits
Author: klimek
Date: Fri Nov 17 03:17:15 2017
New Revision: 318515

URL: http://llvm.org/viewvc/llvm-project?rev=318515=rev
Log:
Implement more accurate penalty & trade-offs while breaking protruding tokens.

For each line that we break in a protruding token, compute whether the
penalty of breaking is actually larger than the penalty of the excess
characters. Only break if that is the case.

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

Modified: cfe/trunk/lib/Format/BreakableToken.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.cpp?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/BreakableToken.cpp (original)
+++ cfe/trunk/lib/Format/BreakableToken.cpp Fri Nov 17 03:17:15 2017
@@ -605,9 +605,9 @@ unsigned BreakableBlockComment::getLineL
   }
 }
 
-bool BreakableBlockComment::introducesBreakBefore(unsigned LineIndex) const {
+bool BreakableBlockComment::introducesBreakBeforeToken() const {
   // A break is introduced when we want delimiters on newline.
-  return LineIndex == 0 && DelimitersOnNewline &&
+  return DelimitersOnNewline &&
  Lines[0].substr(1).find_first_not_of(Blanks) != StringRef::npos;
 }
 

Modified: cfe/trunk/lib/Format/BreakableToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/BreakableToken.h?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/BreakableToken.h (original)
+++ cfe/trunk/lib/Format/BreakableToken.h Fri Nov 17 03:17:15 2017
@@ -137,9 +137,9 @@ public:
 return Split(StringRef::npos, 0);
   }
 
-  /// \brief Returns if a break before the content at \p LineIndex will be
-  /// inserted after the whitespace preceding the content has been reformatted.
-  virtual bool introducesBreakBefore(unsigned LineIndex) const {
+  /// \brief Returns whether there will be a line break at the start of the
+  /// token.
+  virtual bool introducesBreakBeforeToken() const {
 return false;
   }
 
@@ -347,7 +347,7 @@ public:
   Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit,
llvm::Regex ) const override;
-  bool introducesBreakBefore(unsigned LineIndex) const override;
+  bool introducesBreakBeforeToken() const override;
   unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
  unsigned TailOffset,
  unsigned PreviousEndColumn,

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=318515=318514=318515=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Nov 17 03:17:15 2017
@@ -1487,8 +1487,14 @@ unsigned ContinuationIndenter::breakProt
   if (Current.UnbreakableTailLength >= ColumnLimit)
 return 0;
 
+  unsigned NewBreakPenalty = Current.isStringLiteral()
+ ? Style.PenaltyBreakString
+ : Style.PenaltyBreakComment;
   unsigned RemainingSpace = ColumnLimit - Current.UnbreakableTailLength;
-  bool BreakInserted = false;
+  bool BreakInserted = Token->introducesBreakBeforeToken();
+  // Store whether we inserted a new line break at the end of the previous
+  // logical line.
+  bool NewBreakBefore = false;
   // We use a conservative reflowing strategy. Reflow starts after a line is
   // broken or the corresponding whitespace compressed. Reflow ends as soon as 
a
   // line that doesn't get reflown with the previous line is reached.
@@ -1496,23 +1502,50 @@ unsigned ContinuationIndenter::breakProt
   unsigned Penalty = 0;
   unsigned RemainingTokenColumns = 0;
   unsigned TailOffset = 0;
+  DEBUG(llvm::dbgs() << "Breaking protruding token at column " << StartColumn
+ << ".\n");
   for (unsigned LineIndex = 0, EndIndex = Token->getLineCount();
LineIndex != EndIndex; ++LineIndex) {
+DEBUG(llvm::dbgs() << "  Line: " << LineIndex
+   << " (Reflow: " << ReflowInProgress << ")\n");
 BreakableToken::Split SplitBefore(StringRef::npos, 0);
 if (ReflowInProgress) {
   SplitBefore = Token->getSplitBefore(LineIndex, RemainingTokenColumns,
   RemainingSpace, CommentPragmasRegex);
 }
 ReflowInProgress = SplitBefore.first != StringRef::npos;
+DEBUG({
+  if (ReflowInProgress)
+llvm::dbgs() << "  Reflowing.\n";
+});
 TailOffset =
 ReflowInProgress ? (SplitBefore.first 

[PATCH] D40127: [Driver][ARM] For assembler files recognize -Xassembler or -Wa, -mthumb

2017-11-17 Thread Peter Smith via Phabricator via cfe-commits
peter.smith updated this revision to Diff 123310.
peter.smith added a comment.

Updated diff with an attempt to simplify the check for filetype and mthumb. 
I've left the existing Args.filtered in expression for now as I couldn't make a 
better alternative with std::for_any.


https://reviews.llvm.org/D40127

Files:
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains/Clang.cpp
  test/Driver/arm-target-as-mthumb.s


Index: test/Driver/arm-target-as-mthumb.s
===
--- /dev/null
+++ test/Driver/arm-target-as-mthumb.s
@@ -0,0 +1,17 @@
+// Make sure -mthumb does not affect assembler triple, but -Wa,-mthumb or
+// -Xassembler -mthumb does. Also check that -Wa,-mthumb or -Xassembler -mthumb
+// does not affect non assembler files.
+
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -mthumb %s 2>&1 | \
+// RUN: FileCheck -check-prefix=TRIPLE-ARM %s
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Wa,-mthumb \
+// RUN: %S/Inputs/wildcard1.c  2>&1 | FileCheck -check-prefix=TRIPLE-ARM %s
+
+// TRIPLE-ARM: "-triple" "armv7--linux-gnueabi"
+
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Wa,-mthumb %s 2>&1 | \
+// RUN: FileCheck -check-prefix=TRIPLE-THUMB %s
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Xassembler -mthumb %s \
+// RUN: 2>&1 | FileCheck -check-prefix=TRIPLE-THUMB %s
+
+// TRIPLE-THUMB: "-triple" "thumbv7--linux-gnueabi"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -1889,6 +1889,15 @@
   switch (C.getDefaultToolChain().getArch()) {
   default:
 break;
+  case llvm::Triple::thumb:
+  case llvm::Triple::thumbeb:
+  case llvm::Triple::arm:
+  case llvm::Triple::armeb:
+if (Value == "-mthumb")
+  // -mthumb has already been processed in ComputeLLVMTriple()
+  // recognize but skip over here.
+  continue;
+
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
   case llvm::Triple::mips64:
Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -541,11 +541,30 @@
   << tools::arm::getARMArch(MArch, getTriple()) << "ARM";
 }
 
-// Assembly files should start in ARM mode, unless arch is M-profile.
-// Windows is always thumb.
-if ((InputType != types::TY_PP_Asm && Args.hasFlag(options::OPT_mthumb,
- options::OPT_mno_thumb, ThumbDefault)) || IsMProfile ||
- getTriple().isOSWindows()) {
+// Check to see if an explicit choice to use thumb has been made via
+// -mthumb. For assembler files we must check for -mthumb in the options
+// passed to the assember via -Wa or -Xassembler.
+bool IsMThumb = false;
+if (InputType != types::TY_PP_Asm)
+  IsMThumb = Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb,
+  ThumbDefault);
+else {
+  // Ideally we would check for these flags in
+  // CollectArgsForIntegratedAssembler but we can't change the ArchName at
+  // that point. There is no assembler equivalent of -mno-thumb, -marm, or
+  // -mno-arm.
+  for (const Arg *A :
+   Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
+for (StringRef Value : A->getValues()) {
+  if (Value == "-mthumb")
+IsMThumb = true;
+}
+  }
+}
+// Assembly files should start in ARM mode, unless arch is M-profile, or
+// -mthumb has been passed explicitly to the assembler. Windows is always
+// thumb.
+if (IsMThumb || IsMProfile || getTriple().isOSWindows()) {
   if (IsBigEndian)
 ArchName = "thumbeb";
   else


Index: test/Driver/arm-target-as-mthumb.s
===
--- /dev/null
+++ test/Driver/arm-target-as-mthumb.s
@@ -0,0 +1,17 @@
+// Make sure -mthumb does not affect assembler triple, but -Wa,-mthumb or
+// -Xassembler -mthumb does. Also check that -Wa,-mthumb or -Xassembler -mthumb
+// does not affect non assembler files.
+
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -mthumb %s 2>&1 | \
+// RUN: FileCheck -check-prefix=TRIPLE-ARM %s
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Wa,-mthumb \
+// RUN: %S/Inputs/wildcard1.c  2>&1 | FileCheck -check-prefix=TRIPLE-ARM %s
+
+// TRIPLE-ARM: "-triple" "armv7--linux-gnueabi"
+
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Wa,-mthumb %s 2>&1 | \
+// RUN: FileCheck -check-prefix=TRIPLE-THUMB %s
+// RUN: %clang -target armv7a-linux-gnueabi -### -c -Xassembler -mthumb %s \
+// RUN: 2>&1 | FileCheck -check-prefix=TRIPLE-THUMB %s
+
+// TRIPLE-THUMB: "-triple" "thumbv7--linux-gnueabi"
Index: lib/Driver/ToolChains/Clang.cpp
===
--- 

[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek updated this revision to Diff 123309.
klimek marked an inline comment as done.
klimek added a comment.

Address review comments.


https://reviews.llvm.org/D40068

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -2078,6 +2078,22 @@
"   // longsec\n",
getLLVMStyleWithColumns(20)));
 
+  // Simple case that correctly handles reflow in parameter lists.
+  EXPECT_EQ("a = f(/* long\n"
+"   * long long\n"
+"   */\n"
+"  a);",
+format("a = f(/* long long\n* long\n*/ a);",
+   getLLVMStyleWithColumns(22)));
+  // Tricky case that has fewer lines if we reflow the comment, ending up with
+  // fewer lines.
+  EXPECT_EQ("a = f(/* loong\n"
+"   * long long\n"
+"   */\n"
+"  a);",
+format("a = f(/* loong long\n* long\n*/ a);",
+   getLLVMStyleWithColumns(22)));
+
   // Keep empty comment lines.
   EXPECT_EQ("/**/", format(" /**/", getLLVMStyleWithColumns(20)));
   EXPECT_EQ("/* */", format(" /* */", getLLVMStyleWithColumns(20)));
@@ -2426,9 +2442,13 @@
 
 TEST_F(FormatTestComments, BreaksAfterMultilineBlockCommentsInParamLists) {
   EXPECT_EQ("a = f(/* long\n"
-" long\n"
-"   */\n"
+" long */\n"
 "  a);",
+format("a = f(/* long long */ a);", getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("a = f(\n"
+"/* long\n"
+"   long */\n"
+"a);",
 format("a = f(/* long long */ a);", getLLVMStyleWithColumns(15)));
 
   EXPECT_EQ("a = f(/* long\n"
@@ -2438,41 +2458,53 @@
 format("a = f(/* long\n"
" long\n"
"   */a);",
-   getLLVMStyleWithColumns(15)));
+   getLLVMStyleWithColumns(16)));
 
   EXPECT_EQ("a = f(/* long\n"
 " long\n"
 "   */\n"
 "  a);",
 format("a = f(/* long\n"
" long\n"
"   */ a);",
-   getLLVMStyleWithColumns(15)));
+   getLLVMStyleWithColumns(16)));
 
   EXPECT_EQ("a = f(/* long\n"
 " long\n"
 "   */\n"
 "  (1 + 1));",
 format("a = f(/* long\n"
" long\n"
"   */ (1 + 1));",
-   getLLVMStyleWithColumns(15)));
+   getLLVMStyleWithColumns(16)));
 
   EXPECT_EQ(
   "a = f(a,\n"
   "  /* long\n"
-  " long\n"
-  "   */\n"
+  " long */\n"
   "  b);",
+  format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(16)));
+  EXPECT_EQ(
+  "a = f(\n"
+  "a,\n"
+  "/* long\n"
+  "   long */\n"
+  "b);",
   format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(15)));
 
-  EXPECT_EQ(
-  "a = f(a,\n"
-  "  /* long\n"
-  " long\n"
-  "   */\n"
-  "  (1 + 1));",
-  format("a = f(a, /* long long */ (1 + 1));", getLLVMStyleWithColumns(15)));
+  EXPECT_EQ("a = f(a,\n"
+"  /* long\n"
+" long */\n"
+"  (1 + 1));",
+format("a = f(a, /* long long */ (1 + 1));",
+   getLLVMStyleWithColumns(16)));
+  EXPECT_EQ("a = f(\n"
+"a,\n"
+"/* long\n"
+"   long */\n"
+"(1 + 1));",
+format("a = f(a, /* long long */ (1 + 1));",
+   getLLVMStyleWithColumns(15)));
 }
 
 TEST_F(FormatTestComments, IndentLineCommentsInStartOfBlockAtEndOfFile) {
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -8002,9 +8002,9 @@
 "\"f\");",
 format("someFunction1234567890(\"aaabbbcccdddeeefff\");",
getLLVMStyleWithColumns(24)));
-  EXPECT_EQ("someFunction(\"aaabbbcc \"\n"
-" \"ddde \"\n"
-" \"efff\");",
+  EXPECT_EQ("someFunction(\n"
+"\"aaabbbcc ddde \"\n"
+"\"efff\");",
 format("someFunction(\"aaabbbcc ddde efff\");",
getLLVMStyleWithColumns(25)));
   EXPECT_EQ("someFunction(\"aaabbbccc \"\n"
@@ -8023,10 +8023,9 @@
 "  int i;",
 format("#define A string s = 

[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: unittests/Format/FormatTest.cpp:9951
+   "\n*/",
+   Style));
+

krasimir wrote:
> Why didn't this get reformatted as:
> ```
>   EXPECT_EQ("int a; /* first line\n"
> "* second line\n"
> "* third line\n"
> "*/",
> ```
Added FIXME.


https://reviews.llvm.org/D40068



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


[PATCH] D40127: [Driver][ARM] For assembler files recognize -Xassembler or -Wa, -mthumb

2017-11-17 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added inline comments.



Comment at: lib/Driver/ToolChain.cpp:549-556
+bool IsIntegratedAssemblerThumb = false;
+for (const Arg *A :
+ Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler)) {
+  for (StringRef Value : A->getValues()) {
+if (Value == "-mthumb")
+  IsIntegratedAssemblerThumb = true;
+  }

compnerd wrote:
> Why not write this as:
> 
> const auto  = Args.filtered(options::OPT_Wa_COMMA, 
> options::OPT_Xassembler);
> bool IsIntegratedAssemblerThumb =
> std::any_of(std::begin(A->getValues()),
> std::end(A->getValues()),
> [](StringRef Arg) { return Arg == "-mthumb"});
I gave it a try and I don't think it can be done simply as there are two loops 
and not one. There could be two Args, one for Wa_COMMA and one for X_Assembler. 
Unless there is a way of combining the iterator ranges into one I don't think 
this can be done without nested loops. I checked the other uses of 
Args.filtered and I couldn't find any of use outside of the range for. Please 
do let me know if I'm missing something though as I'm happy to change it if 
there is something better. 



Comment at: lib/Driver/ToolChain.cpp:560-564
+if ((InputType != types::TY_PP_Asm &&
+ Args.hasFlag(options::OPT_mthumb, options::OPT_mno_thumb,
+  ThumbDefault)) ||
+(InputType == types::TY_PP_Asm && IsIntegratedAssemblerThumb) ||
+IsMProfile || getTriple().isOSWindows()) {

compnerd wrote:
> This is horribly complicated to read.  Can we just split this out of the 
> condition and create a variable?
Agreed. I'll post an alternative that attempts to evaluate -mthumb before the 
boolean expression. 


https://reviews.llvm.org/D40127



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


[PATCH] D40068: Implement more accurate penalty & trade-offs while breaking protruding tokens.

2017-11-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/ContinuationIndenter.cpp:1616
+
+
   if (!DryRun)

nit: remove an empty line



Comment at: unittests/Format/FormatTest.cpp:9951
+   "\n*/",
+   Style));
+

Why didn't this get reformatted as:
```
  EXPECT_EQ("int a; /* first line\n"
"* second line\n"
"* third line\n"
"*/",
```


https://reviews.llvm.org/D40068



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


[PATCH] D40120: [clang-format] Add text proto filename detection

2017-11-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 123308.
krasimir added a comment.

- Remove METADATA


https://reviews.llvm.org/D40120

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2084,6 +2084,11 @@
   if (FileName.endswith_lower(".proto") ||
   FileName.endswith_lower(".protodevel"))
 return FormatStyle::LK_Proto;
+  if (FileName.endswith_lower(".textpb") ||
+  FileName.endswith_lower(".pb.txt") ||
+  FileName.endswith_lower(".textproto") ||
+  FileName.endswith_lower(".asciipb"))
+return FormatStyle::LK_TextProto;
   if (FileName.endswith_lower(".td"))
 return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -2084,6 +2084,11 @@
   if (FileName.endswith_lower(".proto") ||
   FileName.endswith_lower(".protodevel"))
 return FormatStyle::LK_Proto;
+  if (FileName.endswith_lower(".textpb") ||
+  FileName.endswith_lower(".pb.txt") ||
+  FileName.endswith_lower(".textproto") ||
+  FileName.endswith_lower(".asciipb"))
+return FormatStyle::LK_TextProto;
   if (FileName.endswith_lower(".td"))
 return FormatStyle::LK_TableGen;
   return FormatStyle::LK_Cpp;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39842: Allow to store precompiled preambles in memory.

2017-11-17 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D39842#927578, @mgorny wrote:

> Please revert this commit. You've just broken all the stand-alone builds of 
> clang.


Sorry about that. Should be fixed in https://reviews.llvm.org/rL318514


Repository:
  rL LLVM

https://reviews.llvm.org/D39842



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


r318514 - Use llvm-config.h instead of config.h

2017-11-17 Thread Ilya Biryukov via cfe-commits
Author: ibiryukov
Date: Fri Nov 17 02:09:02 2017
New Revision: 318514

URL: http://llvm.org/viewvc/llvm-project?rev=318514=rev
Log:
Use llvm-config.h instead of config.h

To fix standalone builds broken by r318411 (config.h is private to llvm).

Modified:
cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp

Modified: cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp?rev=318514=318513=318514=diff
==
--- cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp (original)
+++ cfe/trunk/lib/Frontend/PrecompiledPreamble.cpp Fri Nov 17 02:09:02 2017
@@ -24,7 +24,7 @@
 #include "clang/Serialization/ASTWriter.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSet.h"
-#include "llvm/Config/config.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Mutex.h"


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


[PATCH] D39673: Toolchain: Normalize dwarf, sjlj and seh eh

2017-11-17 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

https://reviews.llvm.org/D39533 was committed now, so before committing, make 
sure that the `__ARM_DWARF_EH__` (that was added in that commit) only gets set 
while dwarf is enabled (which now is the default for mingw/arm but not 
msvc/arm).


Repository:
  rL LLVM

https://reviews.llvm.org/D39673



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


  1   2   >