Re: r305860 - Special-case handling of destructors in override lists when dumping ASTs.

2017-07-12 Thread Akira Hatanaka via cfe-commits
Hi Lang,

clang crashes when I compile the following code with "-Xclang -ast-dump”:

class Base {
public:
  virtual void operator()() {}
};

class Derived : public Base {
public:
  void operator()() override {}
};

If I change “OS << D->getName()” to “OS << D->getNameAsString()”, the crash 
disappears.

Can you take a look please?

> On Jun 20, 2017, at 2:30 PM, Lang Hames via cfe-commits 
>  wrote:
> 
> Author: lhames
> Date: Tue Jun 20 16:30:43 2017
> New Revision: 305860
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=305860=rev
> Log:
> Special-case handling of destructors in override lists when dumping ASTs.
> 
> Fixes a bug in r305850: CXXDestructors don't have names, so we need to handle
> printing of them separately.
> 
> 
> Modified:
>cfe/trunk/lib/AST/ASTDumper.cpp
> 
> Modified: cfe/trunk/lib/AST/ASTDumper.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTDumper.cpp?rev=305860=305859=305860=diff
> ==
> --- cfe/trunk/lib/AST/ASTDumper.cpp (original)
> +++ cfe/trunk/lib/AST/ASTDumper.cpp Tue Jun 20 16:30:43 2017
> @@ -1189,9 +1189,12 @@ void ASTDumper::VisitFunctionDecl(const
>   auto dumpOverride =
> [=](const CXXMethodDecl *D) {
>   SplitQualType T_split = D->getType().split();
> -  OS << D << " " << D->getParent()->getName() << "::"
> - << D->getName() << " '"
> - << QualType::getAsString(T_split) << "'";
> +  OS << D << " " << D->getParent()->getName() << "::";
> +  if (isa(D))
> +OS << "~" << D->getParent()->getName();
> +  else
> +OS << D->getName();
> +  OS << " '" << QualType::getAsString(T_split) << "'";
> };
> 
>   dumpChild([=] {
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


[PATCH] D34955: [Basic] Detect Git submodule version in CMake

2017-07-12 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 106367.
modocache added a comment.

Use CMAKE_MATCH_0 instead of using REGEX REPLACE. Thanks for the suggestion!


https://reviews.llvm.org/D34955

Files:
  lib/Basic/CMakeLists.txt


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,23 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+if("${file_contents}" MATCHES "^gitdir: ([^\n]+)")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  set(git_path "${path}/${CMAKE_MATCH_1}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )


Index: lib/Basic/CMakeLists.txt
===
--- lib/Basic/CMakeLists.txt
+++ lib/Basic/CMakeLists.txt
@@ -15,8 +15,23 @@
 endfunction()
 
 macro(find_first_existing_vc_file out_var path)
+  set(git_path "${path}/.git")
+
+  # Normally '.git' is a directory that contains a 'logs/HEAD' file that
+  # is updated as modifications are made to the repository. In case the
+  # repository is a Git submodule, '.git' is a file that contains text that
+  # indicates where the repository's Git directory exists.
+  if (EXISTS "${git_path}" AND NOT IS_DIRECTORY "${git_path}")
+FILE(READ "${git_path}" file_contents)
+if("${file_contents}" MATCHES "^gitdir: ([^\n]+)")
+  # '.git' is indeed a link to the submodule's Git directory.
+  # Use the path to that Git directory.
+  set(git_path "${path}/${CMAKE_MATCH_1}")
+endif()
+  endif()
+
   find_first_existing_file(${out_var}
-"${path}/.git/logs/HEAD" # Git
+"${git_path}/logs/HEAD"  # Git or Git submodule
 "${path}/.svn/wc.db" # SVN 1.7
 "${path}/.svn/entries"   # SVN 1.6
 )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] r307876 - clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param-header.cpp: Resolve flakiness in the test.

2017-07-12 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Wed Jul 12 19:06:30 2017
New Revision: 307876

URL: http://llvm.org/viewvc/llvm-project?rev=307876=rev
Log:
clang-tools-extra/test/clang-tidy/performance-unnecessary-value-param-header.cpp:
 Resolve flakiness in the test.

Tests would go flaky if;
1. Using %T (not %t)
2. Put a file with common name like header.h into %T
3. Other tests (eg. misc-unused-parameters.cpp) are doing as well

We should avoid using %T unless it really makes sense.

Modified:

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp?rev=307876=307875=307876=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
 Wed Jul 12 19:06:30 2017
@@ -1,6 +1,8 @@
-// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
-// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- 
-std=c++11 -I %T
-// RUN: diff %T/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
+// RUN: rm -rf %t
+// RUN: mkdir %t
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %t/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t/temp -- -- 
-std=c++11 -I %t
+// RUN: diff %t/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
 
 #include "header.h"
 


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


[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-12 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In https://reviews.llvm.org/D35081#807172, @fhahn wrote:

> It's @yunlian, so if the issue you described above covers his failure, than 
> that's great. @tejohnson do you have time to work on a fix soon? Otherwise I 
> could give it a try, I would probably need a few pointers though, as I am not 
> really familiar with ThinLTO.


A good starting point is `static const GlobalValueSummary *selectCallee()` in 
llvm/lib/Transforms/IPO/FunctionImport.cpp ; but it is likely not trivial to 
solve.


https://reviews.llvm.org/D35081



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


[PATCH] D35338: Add the -fdestroy-globals flag

2017-07-12 Thread Ian Tessier via Phabricator via cfe-commits
itessier created this revision.

The -fdestroy-globals flag can be used to disable global variable destructor
registration. It is intended to be used with embedded code that never exits.
Disabling registration allows the linker to garbage collect unused destructors
and vtables.


https://reviews.llvm.org/D35338

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGDeclCXX.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/fdestroy-globals.cpp

Index: test/Driver/fdestroy-globals.cpp
===
--- /dev/null
+++ test/Driver/fdestroy-globals.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang -fno-destroy-globals -### %s 2>&1 | FileCheck %s --check-prefix=CHECK-FLAG-DISABLE
+// RUN: %clang -fdestroy-globals -### %s 2>&1| FileCheck %s --check-prefix=CHECK-FLAG-ENABLE1
+// RUN: %clang -### %s 2>&1  | FileCheck %s --check-prefix=CHECK-FLAG-ENABLE2
+
+// RUN: %clang_cc1 -fno-destroy-globals -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-CODE-DISABLE
+// RUN: %clang_cc1 -fdestroy-globals -emit-llvm -o - %s| FileCheck %s --check-prefix=CHECK-CODE-ENABLE
+
+// CHECK-FLAG-DISABLE: "-cc1"
+// CHECK-FLAG-DISABLE: "-fno-destroy-globals"
+
+// CHECK-FLAG-ENABLE1: "-cc1"
+// CHECK-FLAG-ENABLE1-NOT: "-fno-destroy-globals"
+
+// CHECK-FLAG-ENABLE2: "-cc1"
+// CHECK-FLAG-ENABLE2-NOT: "-fno-destroy-globals"
+
+// CHECK-CODE-DISABLE-LABEL: define {{.*}} @__cxx_global_var_init
+// CHECK-CODE-DISABLE: call void @_ZN1AC1Ev{{.*}}
+// CHECK-CODE-DISABLE: ret void
+
+// CHECK-CODE-ENABLE-LABEL: define {{.*}} @__cxx_global_var_init
+// CHECK-CODE-ENABLE: call void @_ZN1AC1Ev{{.*}}
+// CHECK-CODE-ENABLE: %{{.*}} = call i32 @__cxa_atexit{{.*}}_ZN1AD1Ev
+// CHECK-CODE-ENABLE: ret void
+
+struct A {
+  virtual ~A() {}
+};
+
+A a;
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -582,6 +582,7 @@
   Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
   Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
   Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
+  Opts.DestroyGlobals = !Args.hasArg(OPT_fno_destroy_globals);
   Opts.CodeModel = getCodeModel(Args, Diags);
   Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
   Opts.DisableFPElim =
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3697,6 +3697,11 @@
   KernelOrKext)
 CmdArgs.push_back("-fno-use-cxa-atexit");
 
+  // -fdestroy-globals=1 is default.
+  if (!Args.hasFlag(options::OPT_fdestroy_globals,
+options::OPT_fno_destroy_globals, true))
+  CmdArgs.push_back("-fno-destroy-globals");
+
   // -fms-extensions=0 is default.
   if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
IsWindowsMSVC))
Index: lib/CodeGen/CGDeclCXX.cpp
===
--- lib/CodeGen/CGDeclCXX.cpp
+++ lib/CodeGen/CGDeclCXX.cpp
@@ -180,7 +180,7 @@
   EmitDeclInit(*this, D, DeclAddr);
 if (CGM.isTypeConstant(D.getType(), true))
   EmitDeclInvariant(*this, D, DeclPtr);
-else
+else if (CGM.getCodeGenOpts().DestroyGlobals)
   EmitDeclDestroy(*this, D, DeclAddr);
 return;
   }
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -44,6 +44,7 @@
 CODEGENOPT(CXAAtExit , 1, 1) ///< Use __cxa_atexit for calling destructors.
 CODEGENOPT(CXXCtorDtorAliases, 1, 0) ///< Emit complete ctors/dtors as linker
  ///< aliases to base ctors when possible.
+CODEGENOPT(DestroyGlobals, 1, 1) ///< -fdestroy-globals
 CODEGENOPT(DataSections  , 1, 0) ///< Set when -fdata-sections is enabled.
 CODEGENOPT(UniqueSectionNames, 1, 1) ///< Set for -funique-section-names.
 CODEGENOPT(DisableFPElim , 1, 0) ///< Set when -fomit-frame-pointer is enabled.
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1235,6 +1235,7 @@
   HelpText<"Don't use __cxa_atexit for calling destructors">;
 def fno_use_init_array : Flag<["-"], "fno-use-init-array">, Group, Flags<[CC1Option]>,
   HelpText<"Don't use .init_array instead of .ctors">;
+def fno_destroy_globals : Flag<["-"], "fno-destroy-globals">, Group, Flags<[CC1Option]>;
 def fno_unit_at_a_time : Flag<["-"], "fno-unit-at-a-time">, Group;
 def fno_unwind_tables : Flag<["-"], "fno-unwind-tables">, Group;
 def fno_verbose_asm : 

[PATCH] D28954: [analyzer] Add support for symbolic float expressions

2017-07-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

Thanks for the patch, and apologies for the delay reviewing!

Here are some initial comments -- there are more coming.




Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:159
+llvm::APFloat To(S, llvm::APFloat::uninitialized);
+assert(Convert(To, From) && "Failed to convert integer to 
floating-point!");
+return getValue(To);

The called overload of Convert() initializes 'To', right? Should it be in an 
assert()? I'm worried about losing the side effect in non-assert builds.



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h:173
+#endif
+assert(!(Status & (llvm::APFloat::opOverflow | 
llvm::APFloat::opInvalidOp)));
+return getValue(To);

There are multiple checks for overflow or invalid in this file. Can the checks 
be factored out into a static member function?



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:137
   /// value for a symbol, even if it is perfectly constrained.
   virtual const llvm::APSInt* getSymVal(ProgramStateRef state,
 SymbolRef sym) const {

What do you think about renaming this to "getSymIntVal" now that we have 
getSymFloatVal()?



Comment at: 
include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:175
+  ///  query whether it is supported, use this to ask directly.
+  virtual bool canReasonAboutFloat() const = 0;
+

The name seems slightly weird. How about "canReasonAboutFloats" or 
"canReasonAboutFloatingPoint"?



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h:118
+  /// that value is returned. Otherwise, returns NULL.
+  virtual const llvm::APFloat *getKnownFloatValue(ProgramStateRef state, SVal 
val) = 0;
+

Note the 80-column violation here.



Comment at: include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h:575
+
+  const SymFloatExpr *getSymFloatExpr(const SymExpr ,
+  BinaryOperator::Opcode op,

I don't think we need the 'const SymExpr ' entry point. It seems 
superfluous and as far as I can tell the analog for getSymIntExpr() is never 
called and should probably be removed.



Comment at: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp:80
+DefinedOrUnknownSVal isPInf = SVB.evalEQ(state, V, SPInf);
+if (isPInf.isConstant(1)) {
+  C.addTransition(state->BindExpr(CE, LCtx, isPInf));

Is there a reason you're not using assumeDual() here?



Comment at: lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp:95
+// TODO: FIXME
+// This should be BO_LOr for (V == -\inf) || (V == \inf), but logical
+// operations are handled much earlier during ExplodedGraph generation.

Logical || has control flow implications, which is why it is handled at a 
higher level. We don't have a good way of representing generalized lazy 
disjunctive constraints. We can eagerly case split at the top level for 
disjunction, but this is bad for performance and is usually not needed.

Your trick of using bitwise OR as an ad hoc lazy disjunct seems reasonable here.



Comment at: lib/StaticAnalyzer/Core/BasicValueFactory.cpp:118
+const llvm::APFloat ::getValue(const llvm::APFloat& X) {
+  llvm::FoldingSetNodeID ID;
+  void *InsertPos;

This logic is nearly identical to that in getValue(const llvm::APSInt& X). Can 
the logic be factored out in some sort of zero-costish abstraction? (Perhaps 
templatized over the value type?)



Comment at: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp:1242
+BinaryOperator::isComparisonOp(BSE->getOpcode())) {
+  const llvm::APFloat *LHS, *RHS;
+  if (const FloatSymExpr *FSE = dyn_cast(BSE)) {

My compiler is complaining about these being uninitialized at line 1251 when 
both the if and else if guard conditions are false.


https://reviews.llvm.org/D28954



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


[PATCH] D35337: [Solaris] gcc runtime dropped support for .ctors, switch to .init_array

2017-07-12 Thread Fedor Sergeev via Phabricator via cfe-commits
fedor.sergeev added a comment.

Note, that LLVM has already been changed to honor use-init-array on Solaris:

  https://reviews.llvm.org/rL305948

(before that change setting Options.UseInitArray in clang would not matter).


https://reviews.llvm.org/D35337



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


[PATCH] D32817: [CMake] Build runtimes for Fuchsia targets

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 106349.

Repository:
  rL LLVM

https://reviews.llvm.org/D32817

Files:
  cmake/caches/Fuchsia-stage2.cmake
  cmake/caches/Fuchsia.cmake


Index: cmake/caches/Fuchsia.cmake
===
--- cmake/caches/Fuchsia.cmake
+++ cmake/caches/Fuchsia.cmake
@@ -38,9 +38,11 @@
   install-distribution
   clang CACHE STRING "")
 
-if(FUCHSIA_SYSROOT)
-  set(EXTRA_ARGS -DFUCHSIA_SYSROOT=${FUCHSIA_SYSROOT})
-endif()
+foreach(target x86_64;aarch64)
+  if(FUCHSIA_${target}_SYSROOT)
+list(APPEND EXTRA_ARGS 
-DFUCHSIA_${target}_SYSROOT=${FUCHSIA_${target}_SYSROOT})
+  endif()
+endforeach()
 
 # Setup the bootstrap build.
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -7,7 +7,6 @@
 
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
-set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
@@ -27,11 +26,23 @@
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 
-set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia-none;aarch64-fuchsia-none" CACHE 
STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING 
"")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE 
STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+set(LLVM_BUILTIN_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia" CACHE STRING 
"")
+foreach(target x86_64;aarch64)
+  set(BUILTINS_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
+  set(BUILTINS_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+endforeach()
+
+set(LLVM_RUNTIME_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia" CACHE STRING 
"")
+foreach(target x86_64;aarch64)
+  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_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+endforeach()
 
 # Setup toolchain.
 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
@@ -61,8 +72,9 @@
   LTO
   clang-format
   clang-headers
-  builtins-x86_64-fuchsia-none
-  builtins-aarch64-fuchsia-none
+  clang-tidy
+  clangd
+  builtins
   runtimes
   ${LLVM_TOOLCHAIN_TOOLS}
   CACHE STRING "")


Index: cmake/caches/Fuchsia.cmake
===
--- cmake/caches/Fuchsia.cmake
+++ cmake/caches/Fuchsia.cmake
@@ -38,9 +38,11 @@
   install-distribution
   clang CACHE STRING "")
 
-if(FUCHSIA_SYSROOT)
-  set(EXTRA_ARGS -DFUCHSIA_SYSROOT=${FUCHSIA_SYSROOT})
-endif()
+foreach(target x86_64;aarch64)
+  if(FUCHSIA_${target}_SYSROOT)
+list(APPEND EXTRA_ARGS -DFUCHSIA_${target}_SYSROOT=${FUCHSIA_${target}_SYSROOT})
+  endif()
+endforeach()
 
 # Setup the bootstrap build.
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -7,7 +7,6 @@
 
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
-set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
@@ -27,11 +26,23 @@
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
 
-set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia-none;aarch64-fuchsia-none" CACHE STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+set(LLVM_BUILTIN_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia" CACHE STRING "")
+foreach(target x86_64;aarch64)
+  

[PATCH] D34301: [Sema] Make sure the definition of a referenced virtual function is emitted when it is final

2017-07-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk accepted this revision.
vsk added a comment.
This revision is now accepted and ready to land.

Thanks, this looks great.


https://reviews.llvm.org/D34301



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


[PATCH] D35337: [Solaris] gcc runtime dropped support for .ctors, switch to .init_array

2017-07-12 Thread Fedor Sergeev via Phabricator via cfe-commits
fedor.sergeev created this revision.

crtbegin.o from gcc toolchain as configured on latest Solaris
(with --enable-initfini-array) does not have support for .ctors.

Clang needs to switch to .init_array. Doing it unconditionally
is fine since older Solaris configurations do support .init_array.


https://reviews.llvm.org/D35337

Files:
  lib/Driver/ToolChains/Gnu.cpp
  lib/Driver/ToolChains/Solaris.cpp
  lib/Driver/ToolChains/Solaris.h


Index: lib/Driver/ToolChains/Solaris.h
===
--- lib/Driver/ToolChains/Solaris.h
+++ lib/Driver/ToolChains/Solaris.h
@@ -50,7 +50,7 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
+class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
 public:
   Solaris(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -126,7 +126,7 @@
 
 Solaris::Solaris(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_GCC(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args) {
 
   GCCInstallation.init(Triple, Args);
 
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2471,7 +2471,8 @@
(!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) ||
   getTriple().getOS() == llvm::Triple::NaCl ||
   (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
-   !getTriple().hasEnvironment());
+   !getTriple().hasEnvironment()) ||
+  getTriple().getOS() == llvm::Triple::Solaris;
 
   if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
  options::OPT_fno_use_init_array, UseInitArrayDefault))


Index: lib/Driver/ToolChains/Solaris.h
===
--- lib/Driver/ToolChains/Solaris.h
+++ lib/Driver/ToolChains/Solaris.h
@@ -50,7 +50,7 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_GCC {
+class LLVM_LIBRARY_VISIBILITY Solaris : public Generic_ELF {
 public:
   Solaris(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
Index: lib/Driver/ToolChains/Solaris.cpp
===
--- lib/Driver/ToolChains/Solaris.cpp
+++ lib/Driver/ToolChains/Solaris.cpp
@@ -126,7 +126,7 @@
 
 Solaris::Solaris(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_GCC(D, Triple, Args) {
+: Generic_ELF(D, Triple, Args) {
 
   GCCInstallation.init(Triple, Args);
 
Index: lib/Driver/ToolChains/Gnu.cpp
===
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -2471,7 +2471,8 @@
(!V.isOlderThan(4, 7, 0) || getTriple().isAndroid())) ||
   getTriple().getOS() == llvm::Triple::NaCl ||
   (getTriple().getVendor() == llvm::Triple::MipsTechnologies &&
-   !getTriple().hasEnvironment());
+   !getTriple().hasEnvironment()) ||
+  getTriple().getOS() == llvm::Triple::Solaris;
 
   if (DriverArgs.hasFlag(options::OPT_fuse_init_array,
  options::OPT_fno_use_init_array, UseInitArrayDefault))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34301: [Sema] Make sure the definition of a referenced virtual function is emitted when it is final

2017-07-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 106347.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Define and use CXXMethodDecl::getDevirtualizedMethod, which returns the 
function that is called when a call is devirtualized.


https://reviews.llvm.org/D34301

Files:
  include/clang/AST/DeclCXX.h
  include/clang/Sema/Sema.h
  lib/AST/DeclCXX.cpp
  lib/CodeGen/CGClass.cpp
  lib/CodeGen/CGExprCXX.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGen/no-devirt.cpp
  test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
  test/CodeGenCXX/vtable-available-externally.cpp

Index: test/CodeGenCXX/vtable-available-externally.cpp
===
--- test/CodeGenCXX/vtable-available-externally.cpp
+++ test/CodeGenCXX/vtable-available-externally.cpp
@@ -275,9 +275,8 @@
   virtual D& operator=(const D&);
 };
 
-// Cannot emit D's vtable available_externally, because we cannot create
-// a reference to the inline virtual D::operator= function.
-// CHECK-TEST11: @_ZTVN6Test111DE = external unnamed_addr constant
+// Can emit D's vtable available_externally.
+// CHECK-TEST11: @_ZTVN6Test111DE = available_externally unnamed_addr constant
 struct D : C {
   virtual void key();
 };
Index: test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
===
--- test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
+++ test/CodeGenCXX/devirtualize-virtual-function-calls-final.cpp
@@ -241,3 +241,53 @@
 return static_cast(b)->f();
   }
 }
+
+namespace Test11 {
+  // Check that the definitions of Derived's operators are emitted.
+
+  // CHECK-LABEL: define linkonce_odr void @_ZN6Test111SIiE4foo1Ev(
+  // CHECK: call void @_ZN6Test111SIiE7DerivedclEv(
+  // CHECK: call zeroext i1 @_ZN6Test111SIiE7DerivedeqERKNS_4BaseE(
+  // CHECK: call zeroext i1 @_ZN6Test111SIiE7DerivedntEv(
+  // CHECK: call dereferenceable(4) %"class.Test11::Base"* @_ZN6Test111SIiE7DerivedixEi(
+  // CHECK: define linkonce_odr void @_ZN6Test111SIiE7DerivedclEv(
+  // CHECK: define linkonce_odr zeroext i1 @_ZN6Test111SIiE7DerivedeqERKNS_4BaseE(
+  // CHECK: define linkonce_odr zeroext i1 @_ZN6Test111SIiE7DerivedntEv(
+  // CHECK: define linkonce_odr dereferenceable(4) %"class.Test11::Base"* @_ZN6Test111SIiE7DerivedixEi(
+  class Base {
+  public:
+virtual void operator()() {}
+virtual bool operator==(const Base ) { return false; }
+virtual bool operator!() { return false; }
+virtual Base [](int i) { return *this; }
+  };
+
+  template
+  struct S {
+class Derived final : public Base {
+public:
+  void operator()() override {}
+  bool operator==(const Base ) override { return true; }
+  bool operator!() override { return true; }
+  Base [](int i) override { return *this; }
+};
+
+Derived *ptr = nullptr, *ptr2 = nullptr;
+
+void foo1() {
+  if (ptr && ptr2) {
+// These calls get devirtualized. Linkage fails if the definitions of
+// the called functions are not emitted.
+(*ptr)();
+(void)(*ptr == *ptr2);
+(void)(!(*ptr));
+(void)((*ptr)[1]);
+  }
+}
+  };
+
+  void foo2() {
+S *s = new S;
+s->foo1();
+  }
+}
Index: test/CodeGen/no-devirt.cpp
===
--- test/CodeGen/no-devirt.cpp
+++ test/CodeGen/no-devirt.cpp
@@ -21,7 +21,7 @@
 struct Wrapper {
   TmplWithArray data;
   bool indexIt(int a) {
-if (a > 6) return data[a] ;  // Should not devirtualize
+if (a > 6) return data[a] ;  // Should devirtualize
 if (a > 4) return data.func1(a); // Should devirtualize
 return data.func2(a);// Should devirtualize
   }
@@ -53,7 +53,7 @@
 }
 #endif
 
-// CHECK-NOT: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi
+// CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EEixEi
 // CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func1Ei
 // CHECK-DAG: call {{.*}} @_ZN13TmplWithArrayIbLi10EE5func2Ei
 
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -48,7 +48,7 @@
 /// A convenience routine for creating a decayed reference to a function.
 static ExprResult
 CreateFunctionRefExpr(Sema , FunctionDecl *Fn, NamedDecl *FoundDecl,
-  bool HadMultipleCandidates,
+  const Expr *Base, bool HadMultipleCandidates,
   SourceLocation Loc = SourceLocation(),
   const DeclarationNameLoc  = DeclarationNameLoc()){
   if (S.DiagnoseUseOfDecl(FoundDecl, Loc))
@@ -68,7 +68,7 @@
   if (HadMultipleCandidates)
 DRE->setHadMultipleCandidates(true);
 
-  S.MarkDeclRefReferenced(DRE);
+  S.MarkDeclRefReferenced(DRE, Base);
   return S.ImpCastExprToType(DRE, S.Context.getPointerType(DRE->getType()),
  

[PATCH] D35190: __builtin_constant_p should consider the parameter of a constexpr function as constant

2017-07-12 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

See https://bugs.llvm.org/show_bug.cgi?id=4898 for more discussion of 
__builtin_constant_p in LLVM vs. gcc.


https://reviews.llvm.org/D35190



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


r307856 - Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Wed Jul 12 15:14:41 2017
New Revision: 307856

URL: http://llvm.org/viewvc/llvm-project?rev=307856=rev
Log:
Reland "[Driver] Update Fuchsia driver path handling"

Several improvements to the Fuchsia driver:

* Search for C++ library headers and libraries in directories that
are part of the toolchain distribution rather than sysroot.

* Use LLVM support utlities to construct paths to make sure the driver
is also usable on Windows for cross-compiling.

* Change the driver to inherit directly from ToolChain rather than
Generic_GCC since we don't need any of the GCC related multilib logic.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fuchsia.c
cfe/trunk/test/Driver/fuchsia.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=307856=307855=307856=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Wed Jul 12 15:14:41 2017
@@ -131,16 +131,44 @@ void fuchsia::Linker::ConstructJob(Compi
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string normalizeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", normalizeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
+ types::ID InputType) const {
+  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
+  Triple.setTriple(normalizeTriple(Triple));
+  return Triple.getTriple();
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -208,19 +236,44 @@ void Fuchsia::AddClangSystemIncludeArgs(
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "include");
+addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+  }
 }
 
-std::string Fuchsia::findLibCxxIncludePath() const {
-  return getDriver().SysRoot + "/include/c++/v1";
+void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList ,
+   ArgStringList ) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> P(getTargetDir(getDriver(), getTriple()));
+llvm::sys::path::append(P, "include", "c++", "v1");
+addSystemInclude(DriverArgs, CC1Args, P.str());
+break;
+  }
+
+  default:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 void Fuchsia::AddCXXStdlibLibArgs(const ArgList ,
   ArgStringList ) const {
-  (void) GetCXXStdlibType(Args);
-  CmdArgs.push_back("-lc++");
-  CmdArgs.push_back("-lc++abi");
-  CmdArgs.push_back("-lunwind");
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+CmdArgs.push_back("-lc++");
+CmdArgs.push_back("-lc++abi");
+CmdArgs.push_back("-lunwind");
+break;
+
+  case ToolChain::CST_Libstdcxx:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=307856=307855=307856=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Wed Jul 12 15:14:41 2017
@@ -35,18 +35,29 @@ public:
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia 

[PATCH] D35328: Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307856: Reland "[Driver] Update Fuchsia driver path 
handling" (authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D35328?vs=106323=106327#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35328

Files:
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
  cfe/trunk/test/Driver/fuchsia.c
  cfe/trunk/test/Driver/fuchsia.cpp

Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,44 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string normalizeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", normalizeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
+ types::ID InputType) const {
+  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
+  Triple.setTriple(normalizeTriple(Triple));
+  return Triple.getTriple();
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -208,19 +236,44 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "include");
+addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+  }
 }
 
-std::string Fuchsia::findLibCxxIncludePath() const {
-  return getDriver().SysRoot + "/include/c++/v1";
+void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList ,
+   ArgStringList ) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> P(getTargetDir(getDriver(), getTriple()));
+llvm::sys::path::append(P, "include", "c++", "v1");
+addSystemInclude(DriverArgs, CC1Args, P.str());
+break;
+  }
+
+  default:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 void Fuchsia::AddCXXStdlibLibArgs(const ArgList ,
   ArgStringList ) const {
-  (void) GetCXXStdlibType(Args);
-  CmdArgs.push_back("-lc++");
-  CmdArgs.push_back("-lc++abi");
-  CmdArgs.push_back("-lunwind");
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+CmdArgs.push_back("-lc++");
+CmdArgs.push_back("-lc++abi");
+CmdArgs.push_back("-lunwind");
+break;
+
+  case ToolChain::CST_Libstdcxx:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {
Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
@@ -35,18 +35,29 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind 

r307855 - [index] Don't add relation to a NamedDecl with no name

2017-07-12 Thread Ben Langmuir via cfe-commits
Author: benlangmuir
Date: Wed Jul 12 15:05:30 2017
New Revision: 307855

URL: http://llvm.org/viewvc/llvm-project?rev=307855=rev
Log:
[index] Don't add relation to a NamedDecl with no name

Unless it's one of the special cases (tag, category) that we can handle.
This syncs up the check between handling a decl and handling a relation.

This would cause invalid nameless decls to end up in relations despite
having no name or USR.

rdar://problem/32474406

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

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=307855=307854=307855=diff
==
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Wed Jul 12 15:05:30 2017
@@ -229,6 +229,12 @@ static bool isDeclADefinition(const Decl
   return false;
 }
 
+/// Whether the given NamedDecl should be skipped because it has no name.
+static bool shouldSkipNamelessDecl(const NamedDecl *ND) {
+  return ND->getDeclName().isEmpty() && !isa(ND) &&
+ !isa(ND);
+}
+
 static const Decl *adjustParent(const Decl *Parent) {
   if (!Parent)
 return nullptr;
@@ -243,8 +249,8 @@ static const Decl *adjustParent(const De
 } else if (auto RD = dyn_cast(Parent)) {
   if (RD->isAnonymousStructOrUnion())
 continue;
-} else if (auto FD = dyn_cast(Parent)) {
-  if (FD->getDeclName().isEmpty())
+} else if (auto ND = dyn_cast(Parent)) {
+  if (shouldSkipNamelessDecl(ND))
 continue;
 }
 return Parent;
@@ -315,9 +321,7 @@ bool IndexingContext::handleDeclOccurren
const DeclContext *ContainerDC) {
   if (D->isImplicit() && !isa(D))
 return true;
-  if (!isa(D) ||
-  (cast(D)->getDeclName().isEmpty() &&
-   !isa(D) && !isa(D)))
+  if (!isa(D) || shouldSkipNamelessDecl(cast(D)))
 return true;
 
   SourceManager  = Ctx->getSourceManager();

Added: cfe/trunk/test/Index/Core/index-source-invalid-name.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source-invalid-name.cpp?rev=307855=auto
==
--- cfe/trunk/test/Index/Core/index-source-invalid-name.cpp (added)
+++ cfe/trunk/test/Index/Core/index-source-invalid-name.cpp Wed Jul 12 15:05:30 
2017
@@ -0,0 +1,13 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target 
x86_64-apple-macosx10.7 | FileCheck %s
+
+namespace rdar32474406 {
+// CHECK: [[@LINE+1]]:6 | function/C | foo | c:@N@rdar32474406@F@foo# | 
__ZN12rdar324744063fooEv | Decl,RelChild | rel: 1
+void foo();
+// CHECK: [[@LINE+1]]:16 | type-alias/C | Func_t | 
c:index-source-invalid-name.cpp@N@rdar32474406@T@Func_t |  | 
Def,RelChild | rel: 1
+typedef void (*Func_t)();
+// CHECK: [[@LINE+4]]:1 | type-alias/C | Func_t | 
c:index-source-invalid-name.cpp@N@rdar32474406@T@Func_t |  | 
Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | rdar32474406 | c:@N@rdar32474406
+// CHECK: [[@LINE+2]]:14 | function/C | foo | c:@N@rdar32474406@F@foo# | 
__ZN12rdar324744063fooEv | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | rdar32474406 | c:@N@rdar32474406
+Func_t[] = { foo }; // invalid decomposition
+}


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


[PATCH] D35328: Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 106323.
phosek marked an inline comment as done.

Repository:
  rL LLVM

https://reviews.llvm.org/D35328

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.c
  test/Driver/fuchsia.cpp

Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -1,9 +1,10 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
 // RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
+// CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK: "-internal-isystem" "[[SYSROOT]]{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -13,7 +14,7 @@
 // CHECK: Scrt1.o
 // CHECK-NOT: crti.o
 // CHECK-NOT: crtbegin.o
-// CHECK: "-L[[SYSROOT]]/lib"
+// CHECK: "-L[[SYSROOT]]{{/|}}lib"
 // CHECK: "-lc++" "-lc++abi" "-lunwind" "-lm"
 // CHECK: "{{.*[/\\]}}libclang_rt.builtins-x86_64.a"
 // CHECK: "-lc"
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -12,7 +12,7 @@
 // CHECK: Scrt1.o
 // CHECK-NOT: crti.o
 // CHECK-NOT: crtbegin.o
-// CHECK: "-L[[SYSROOT]]/lib"
+// CHECK: "-L[[SYSROOT]]{{/|}}lib"
 // CHECK: "{{.*[/\\]}}libclang_rt.builtins-x86_64.a"
 // CHECK: "-lc"
 // CHECK-NOT: crtend.o
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -35,18 +35,29 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
 return llvm::DebuggerKind::GDB;
   }
 
+  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList ,
+  types::ID InputType) const override;
+
   SanitizerMask getSupportedSanitizers() const override;
 
   RuntimeLibType
@@ -60,16 +71,17 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
-  std::string findLibCxxIncludePath() const override;
+  void
+  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
 return "lld";
   }
 
 protected:
-  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,44 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string normalizeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", normalizeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  

[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-07-12 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

Reverted in https://reviews.llvm.org/rL307853


Repository:
  rL LLVM

https://reviews.llvm.org/D28953



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-07-12 Thread Dominic Chen via Phabricator via cfe-commits
ddcc added a comment.

Reverted in https://reviews.llvm.org/rL307853


Repository:
  rL LLVM

https://reviews.llvm.org/D28953



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

+1 for moving this file to LLVM's internal style.




Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

dexonsmith wrote:
> mehdi_amini wrote:
> > dexonsmith wrote:
> > > erik.pilkington wrote:
> > > > mehdi_amini wrote:
> > > > > If this is supposed to be *the* ultimate LLVM demangler, can we 
> > > > > follow LLVM coding standard?
> > > > I would like if this followed LLVM conventions too, but this file is 
> > > > already written following this style and leaving it in some middle 
> > > > state would be ugly. All of libcxx[abi] follows this convention too, so 
> > > > this isn't a problem that is isolated to this file.
> > > I agree.  I'd be fine with clang-formatting the entire project, but that 
> > > seems independent from this change.
> > I'm not talking about pure "clang-format" but also naming for instance.
> > 
> > > I would like if this followed LLVM conventions too, but this file is 
> > > already written following this style and leaving it in some middle state 
> > > would be ugly.
> > 
> > Right, but in the meantime you're adding a significant amount of "debt".
> > 
> > > All of libcxx[abi] follows this convention too, so this isn't a problem 
> > > that is isolated to this file.
> > 
> > This file is "special": it is shared (duplicated...) with LLVM.
> > 
> This is a patch for libcxxabi.  Duplicating the file in LLVM is what created 
> technical debt, and that file has already diverged from libcxxabi.  That's 
> where the bug is.
> 
> AFAICT, there is no requirement for LLVM subprojects to use LLVM naming 
> schemes, and since libcxx and libcxxabi are implementing STL facilities, it's 
> reasonable for them to use STL naming conventions (even in private 
> implementations that aren't exposed to users).
> 
> (It would also be reasonable to follow LLVM naming conventions in private 
> implementations, but that's not the current practice, and it would certainly 
> inhibit code readability here to do so just for one type.)
> 
> Perhaps a compromise would be to rename `string_ref` to `string_view`, so 
> that it sounds more like the equivalent STL type than the equivalent LLVM 
> type.
> 
> @mclow.lists, would you like to weigh in as code owner here?  Should the 
> naming scheme for new types in libcxxabi private implementations follow LLVM 
> coding conventions, or libcxxabi coding conventions?
> I'm not talking about pure "clang-format" but also naming for instance.

+1 to that.


https://reviews.llvm.org/D35159



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


r307853 - Revert "[analyzer] Support generating and reasoning over more symbolic constraint types"

2017-07-12 Thread Dominic Chen via cfe-commits
Author: ddcc
Date: Wed Jul 12 14:43:42 2017
New Revision: 307853

URL: http://llvm.org/viewvc/llvm-project?rev=307853=rev
Log:
Revert "[analyzer] Support generating and reasoning over more symbolic 
constraint types"

Assertion `Loc::isLocType(SSE->getLHS()->getType())' failed in Analysis/PR3991.m

This reverts commit e469ff2759275e67f9072b3d67fac90f647c0fe6.

Removed:
cfe/trunk/test/Analysis/plist-macros-z3.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
cfe/trunk/test/Analysis/analyzer_test.py
cfe/trunk/test/Analysis/bitwise-ops.c
cfe/trunk/test/Analysis/bool-assignment.c
cfe/trunk/test/Analysis/conditional-path-notes.c
cfe/trunk/test/Analysis/explain-svals.cpp
cfe/trunk/test/Analysis/plist-macros.cpp
cfe/trunk/test/Analysis/range_casts.c
cfe/trunk/test/Analysis/std-c-library-functions.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h?rev=307853=307852=307853=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h Wed Jul 12 
14:43:42 2017
@@ -125,14 +125,8 @@ public:
 return OS.str();
   }
 
-  std::string VisitIntSymExpr(const IntSymExpr *S) {
-std::string Str;
-llvm::raw_string_ostream OS(Str);
-OS << S->getLHS()
-   << std::string(BinaryOperator::getOpcodeStr(S->getOpcode())) << " "
-   << "(" << Visit(S->getRHS()) << ") ";
-return OS.str();
-  }
+  // TODO: IntSymExpr doesn't appear in practice.
+  // Add the relevant code once it does.
 
   std::string VisitSymSymExpr(const SymSymExpr *S) {
 return "(" + Visit(S->getLHS()) + ") " +
@@ -140,10 +134,8 @@ public:
" (" + Visit(S->getRHS()) + ")";
   }
 
-  std::string VisitSymbolCast(const SymbolCast *S) {
-return "cast of type '" + S->getType().getAsString() + "' of " +
-   Visit(S->getOperand());
-  }
+  // TODO: SymbolCast doesn't appear in practice.
+  // Add the relevant code once it does.
 
   std::string VisitSymbolicRegion(const SymbolicRegion *R) {
 // Explain 'this' object here.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=307853=307852=307853=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Wed Jul 12 14:43:42 2017
@@ -100,7 +100,7 @@ SValBuilder::getRegionValueSymbolVal(con
 
   if (T->isNullPtrType())
 return makeZeroVal(T);
-
+  
   if (!SymbolManager::canSymbolicate(T))
 return UnknownVal();
 
@@ -354,6 +354,9 @@ SVal SValBuilder::makeSymExprValNN(Progr
BinaryOperator::Opcode Op,
NonLoc LHS, NonLoc RHS,
QualType ResultTy) {
+  if (!State->isTainted(RHS) && !State->isTainted(LHS))
+return UnknownVal();
+
   const SymExpr *symLHS = LHS.getAsSymExpr();
   const SymExpr *symRHS = RHS.getAsSymExpr();
   // TODO: When the Max Complexity is reached, we should conjure a symbol
@@ -361,7 +364,7 @@ SVal SValBuilder::makeSymExprValNN(Progr
   const unsigned MaxComp = 1; // 10 28X
 
   if (symLHS && symRHS &&
-  (symLHS->computeComplexity() + symRHS->computeComplexity()) < MaxComp)
+  (symLHS->computeComplexity() + symRHS->computeComplexity()) <  MaxComp)
 return makeNonLoc(symLHS, Op, symRHS, ResultTy);
 
   if (symLHS && symLHS->computeComplexity() < MaxComp)

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=307853=307852=307853=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Wed Jul 12 14:43:42 
2017
@@ -669,12 +669,12 @@ SVal SimpleSValBuilder::evalBinOpLL(Prog
 // If one of the operands is a symbol and the other is a constant,
 // build an expression for use by the constraint manager.
 if (SymbolRef rSym = rhs.getAsLocSymbol()) {
-  const llvm::APSInt  = lhs.castAs().getValue();
-
-  // Prefer expressions with symbols on the left
+  // We can only build expressions with symbols on the left,
+  // so we need a reversible operator.
   if (!BinaryOperator::isComparisonOp(op))
-return makeNonLoc(lVal, op, rSym, resultTy);
+ 

[PATCH] D35268: [ObjC] Ambiguous property synthesis should pick the 'readwrite' property and check for incompatible attributes

2017-07-12 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

This all seems reasonable.  LGTM.


Repository:
  rL LLVM

https://reviews.llvm.org/D35268



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-07-12 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

r307833 is causing the sanitizer-x86_64-linux-fast buildbot 
 to 
fail during clang regression tests with the following error:

  clang: 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/tools/clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp:55:
 virtual clang::ento::ProgramStateRef 
clang::ento::RangedConstraintManager::assumeSym(clang::ento::ProgramStateRef, 
clang::ento::SymbolRef, bool): Assertion 
`Loc::isLocType(SSE->getLHS()->getType())' failed.

Could you please revert and/or fix this revision?


Repository:
  rL LLVM

https://reviews.llvm.org/D28953



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


[PATCH] D35329: [clang-reorder-fields] Enable reordering for plain C structs

2017-07-12 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
alexshap created this revision.

This diff adds support for reordering fields in structs when the code compiles 
as plain C,
in particular we switch to using RecordDecl instead of CXXRecordDecl where it's 
appropriate.

Test plan: make check-all


Repository:
  rL LLVM

https://reviews.llvm.org/D35329

Files:
  clang-reorder-fields/ReorderFieldsAction.cpp
  test/clang-reorder-fields/PlainCStructFieldsOrder.c


Index: test/clang-reorder-fields/PlainCStructFieldsOrder.c
===
--- test/clang-reorder-fields/PlainCStructFieldsOrder.c
+++ test/clang-reorder-fields/PlainCStructFieldsOrder.c
@@ -0,0 +1,14 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order z,w,y,x %s -- | 
FileCheck %s
+
+struct Foo {
+  const int* x; // CHECK:  {{^  double z;}}
+  int y;// CHECK-NEXT: {{^  int w;}}
+  double z; // CHECK-NEXT: {{^  int y;}}
+  int w;// CHECK-NEXT: {{^  const int\* x}}
+};
+
+int main() {
+  const int x = 13;
+  struct Foo foo = { , 0, 1.29, 17 }; // CHECK: {{^  struct Foo foo = { 
1.29, 17, 0,  };}} 
+  return 0;
+}
Index: clang-reorder-fields/ReorderFieldsAction.cpp
===
--- clang-reorder-fields/ReorderFieldsAction.cpp
+++ clang-reorder-fields/ReorderFieldsAction.cpp
@@ -32,10 +32,10 @@
 /// \brief Finds the definition of a record by name.
 ///
 /// \returns nullptr if the name is ambiguous or not found.
-static const CXXRecordDecl *findDefinition(StringRef RecordName,
-   ASTContext ) {
+static const RecordDecl *findDefinition(StringRef RecordName,
+ASTContext ) {
   auto Results = match(
-  recordDecl(hasName(RecordName), isDefinition()).bind("cxxRecordDecl"),
+  recordDecl(hasName(RecordName), isDefinition()).bind("recordDecl"),
   Context);
   if (Results.empty()) {
 llvm::errs() << "Definition of " << RecordName << "  not found\n";
@@ -46,14 +46,14 @@
  << " is ambiguous, several definitions found\n";
 return nullptr;
   }
-  return selectFirst("cxxRecordDecl", Results);
+  return selectFirst("recordDecl", Results);
 }
 
 /// \brief Calculates the new order of fields.
 ///
 /// \returns empty vector if the list of fields doesn't match the definition.
 static SmallVector
-getNewFieldsOrder(const CXXRecordDecl *Definition,
+getNewFieldsOrder(const RecordDecl *Definition,
   ArrayRef DesiredFieldsOrder) {
   assert(Definition && "Definition is null");
 
@@ -97,7 +97,7 @@
 /// different accesses (public/protected/private) is not supported.
 /// \returns true on success.
 static bool reorderFieldsInDefinition(
-const CXXRecordDecl *Definition, ArrayRef NewFieldsOrder,
+const RecordDecl *Definition, ArrayRef NewFieldsOrder,
 const ASTContext ,
 std::map ) {
   assert(Definition && "Definition is null");
@@ -223,25 +223,29 @@
   ReorderingConsumer =(const ReorderingConsumer &) = delete;
 
   void HandleTranslationUnit(ASTContext ) override {
-const CXXRecordDecl *RD = findDefinition(RecordName, Context);
+const RecordDecl *RD = findDefinition(RecordName, Context);
 if (!RD)
   return;
 SmallVector NewFieldsOrder =
 getNewFieldsOrder(RD, DesiredFieldsOrder);
 if (NewFieldsOrder.empty())
   return;
 if (!reorderFieldsInDefinition(RD, NewFieldsOrder, Context, Replacements))
   return;
-for (const auto *C : RD->ctors())
-  if (const auto *D = dyn_cast(C->getDefinition()))
-reorderFieldsInConstructor(cast(D),
-   NewFieldsOrder, Context, Replacements);
+
+// CXXRD will be nullptr if C code (not C++) is being processed 
+const CXXRecordDecl *CXXRD = dyn_cast(RD);
+if (CXXRD)
+  for (const auto *C : CXXRD->ctors())
+if (const auto *D = dyn_cast(C->getDefinition()))
+  reorderFieldsInConstructor(cast(D),
+  NewFieldsOrder, Context, Replacements);
 
 // We only need to reorder init list expressions for aggregate types.
 // For other types the order of constructor parameters is used,
 // which we don't change at the moment.
 // Now (v0) partial initialization is not supported.
-if (RD->isAggregate())
+if (!CXXRD || CXXRD->isAggregate())
   for (auto Result :
match(initListExpr(hasType(equalsNode(RD))).bind("initListExpr"),
  Context))


Index: test/clang-reorder-fields/PlainCStructFieldsOrder.c
===
--- test/clang-reorder-fields/PlainCStructFieldsOrder.c
+++ test/clang-reorder-fields/PlainCStructFieldsOrder.c
@@ -0,0 +1,14 @@
+// RUN: clang-reorder-fields -record-name Foo -fields-order z,w,y,x %s -- | FileCheck %s
+
+struct Foo {
+  const int* x; // CHECK:  {{^  double z;}}
+  int 

[PATCH] D35328: Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Jonathan Roelofs via Phabricator via cfe-commits
jroelofs accepted this revision.
jroelofs added inline comments.
This revision is now accepted and ready to land.



Comment at: lib/Driver/ToolChains/Fuchsia.cpp:134
 
+static std::string computeTriple(llvm::Triple Triple) {
+  SmallString<64> T;

`normalizeTriple` maybe? Since it strips out the vendor string, among other 
things.


Repository:
  rL LLVM

https://reviews.llvm.org/D35328



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


[PATCH] D32817: [CMake] Build runtimes for Fuchsia targets

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 106311.

Repository:
  rL LLVM

https://reviews.llvm.org/D32817

Files:
  cmake/caches/Fuchsia-stage2.cmake
  cmake/caches/Fuchsia.cmake


Index: cmake/caches/Fuchsia.cmake
===
--- cmake/caches/Fuchsia.cmake
+++ cmake/caches/Fuchsia.cmake
@@ -38,9 +38,11 @@
   install-distribution
   clang CACHE STRING "")
 
-if(FUCHSIA_SYSROOT)
-  set(EXTRA_ARGS -DFUCHSIA_SYSROOT=${FUCHSIA_SYSROOT})
-endif()
+foreach(target x86_64;aarch64)
+  if(FUCHSIA_${target}_SYSROOT)
+list(APPEND EXTRA_ARGS 
-DFUCHSIA_${target}_SYSROOT=${FUCHSIA_${target}_SYSROOT})
+  endif()
+endforeach()
 
 # Setup the bootstrap build.
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -7,7 +7,7 @@
 
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
-set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD ON CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
@@ -27,11 +27,23 @@
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE 
STRING "")
 
-set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia-none;aarch64-fuchsia-none" CACHE 
STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING 
"")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE 
STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+set(LLVM_BUILTIN_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia" CACHE STRING 
"")
+foreach(target x86_64;aarch64)
+  set(BUILTINS_${target}-fuchsia_CMAKE_SYSROOT ${FUCHSIA_${target}_SYSROOT} 
CACHE PATH "")
+  set(BUILTINS_${target}-fuchsia_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+endforeach()
+
+set(LLVM_RUNTIME_TARGETS "default;x86_64-fuchsia;aarch64-fuchsia" CACHE STRING 
"")
+foreach(target x86_64;aarch64)
+  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_LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
+  set(RUNTIMES_${target}-fuchsia_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
+endforeach()
 
 # Setup toolchain.
 set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
@@ -61,8 +73,9 @@
   LTO
   clang-format
   clang-headers
-  builtins-x86_64-fuchsia-none
-  builtins-aarch64-fuchsia-none
+  clang-tidy
+  clangd
+  builtins
   runtimes
   ${LLVM_TOOLCHAIN_TOOLS}
   CACHE STRING "")


Index: cmake/caches/Fuchsia.cmake
===
--- cmake/caches/Fuchsia.cmake
+++ cmake/caches/Fuchsia.cmake
@@ -38,9 +38,11 @@
   install-distribution
   clang CACHE STRING "")
 
-if(FUCHSIA_SYSROOT)
-  set(EXTRA_ARGS -DFUCHSIA_SYSROOT=${FUCHSIA_SYSROOT})
-endif()
+foreach(target x86_64;aarch64)
+  if(FUCHSIA_${target}_SYSROOT)
+list(APPEND EXTRA_ARGS -DFUCHSIA_${target}_SYSROOT=${FUCHSIA_${target}_SYSROOT})
+  endif()
+endforeach()
 
 # Setup the bootstrap build.
 set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
Index: cmake/caches/Fuchsia-stage2.cmake
===
--- cmake/caches/Fuchsia-stage2.cmake
+++ cmake/caches/Fuchsia-stage2.cmake
@@ -7,7 +7,7 @@
 
 set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
 set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
-set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD OFF CACHE BOOL "")
+set(LLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD ON CACHE BOOL "")
 set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
 set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
 set(LLVM_EXTERNALIZE_DEBUGINFO ON CACHE BOOL "")
@@ -27,11 +27,23 @@
 set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -gline-tables-only -DNDEBUG" CACHE STRING "")
 
-set(LLVM_BUILTIN_TARGETS "x86_64-fuchsia-none;aarch64-fuchsia-none" CACHE STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
-set(BUILTINS_x86_64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSROOT ${FUCHSIA_SYSROOT} CACHE STRING "")
-set(BUILTINS_aarch64-fuchsia-none_CMAKE_SYSTEM_NAME Fuchsia CACHE STRING "")
+set(LLVM_BUILTIN_TARGETS 

[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-12 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

It's @yunlian, so if the issue you described above covers his failure, than 
that's great. @tejohnson do you have time to work on a fix soon? Otherwise I 
could give it a try, I would probably need a few pointers though, as I am not 
really familiar with ThinLTO.

Passing in the full combined index I generated manually was just a way to 
produce a similar failure to what I was seeing with the index @yunlian sent me.


https://reviews.llvm.org/D35081



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


[PATCH] D35328: Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

I have fixed the test to also handle Windows paths properly which was causing a 
build breakage.


Repository:
  rL LLVM

https://reviews.llvm.org/D35328



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


[PATCH] D35328: Reland "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.

Several improvements to the Fuchsia driver:

- Search for C++ library headers and libraries in directories that

are part of the toolchain distribution rather than sysroot.

- Use LLVM support utlities to construct paths to make sure the driver

is also usable on Windows for cross-compiling.

- Change the driver to inherit directly from ToolChain rather than

Generic_GCC since we don't need any of the GCC related multilib logic.


Repository:
  rL LLVM

https://reviews.llvm.org/D35328

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.c
  test/Driver/fuchsia.cpp

Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -1,9 +1,10 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
 // RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
+// CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK: "-internal-isystem" "[[SYSROOT]]{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
 // CHECK: "--sysroot=[[SYSROOT]]"
@@ -13,7 +14,7 @@
 // CHECK: Scrt1.o
 // CHECK-NOT: crti.o
 // CHECK-NOT: crtbegin.o
-// CHECK: "-L[[SYSROOT]]/lib"
+// CHECK: "-L[[SYSROOT]]{{/|}}lib"
 // CHECK: "-lc++" "-lc++abi" "-lunwind" "-lm"
 // CHECK: "{{.*[/\\]}}libclang_rt.builtins-x86_64.a"
 // CHECK: "-lc"
Index: test/Driver/fuchsia.c
===
--- test/Driver/fuchsia.c
+++ test/Driver/fuchsia.c
@@ -12,7 +12,7 @@
 // CHECK: Scrt1.o
 // CHECK-NOT: crti.o
 // CHECK-NOT: crtbegin.o
-// CHECK: "-L[[SYSROOT]]/lib"
+// CHECK: "-L[[SYSROOT]]{{/|}}lib"
 // CHECK: "{{.*[/\\]}}libclang_rt.builtins-x86_64.a"
 // CHECK: "-lc"
 // CHECK-NOT: crtend.o
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -35,18 +35,29 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
 return llvm::DebuggerKind::GDB;
   }
 
+  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList ,
+  types::ID InputType) const override;
+
   SanitizerMask getSupportedSanitizers() const override;
 
   RuntimeLibType
@@ -60,16 +71,17 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
-  std::string findLibCxxIncludePath() const override;
+  void
+  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
 return "lld";
   }
 
 protected:
-  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,44 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string computeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", computeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  

[PATCH] D35254: [mips][mt][7/7] Add driver option for the MIPS MT ASE.

2017-07-12 Thread Simon Dardis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307847: [mips][mt][7/7] Add driver option for the MIPS MT 
ASE. (authored by sdardis).

Repository:
  rL LLVM

https://reviews.llvm.org/D35254

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
  cfe/trunk/test/Driver/mips-features.c


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2027,6 +2027,10 @@
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
   HelpText<"Disable MSA ASE (MIPS only)">;
+def mmt : Flag<["-"], "mmt">, Group,
+  HelpText<"Enable MT ASE (MIPS only)">;
+def mno_mt : Flag<["-"], "mno-mt">, Group,
+  HelpText<"Disable MT ASE (MIPS only)">;
 def mfp64 : Flag<["-"], "mfp64">, Group,
   HelpText<"Use 64-bit floating point registers (MIPS only)">;
 def mfp32 : Flag<["-"], "mfp32">, Group,
Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -70,6 +70,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NOMMSA %s
 // CHECK-NOMMSA: "-target-feature" "-msa"
 //
+// -mmt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mno-mt -mmt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MMT %s
+// CHECK-MMT: "-target-feature" "+mt"
+//
+// -mno-mt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mmt -mno-mt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOMMT %s
+// CHECK-NOMMT: "-target-feature" "-mt"
+//
 // -modd-spreg
 // RUN: %clang -target mips-linux-gnu -### -c %s -mno-odd-spreg -modd-spreg 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MODDSPREG %s
Index: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -301,6 +301,7 @@
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mlong_calls,
options::OPT_mno_long_calls, "long-calls");
+  AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt,"mt");
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef ) {


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -2027,6 +2027,10 @@
   HelpText<"Enable MSA ASE (MIPS only)">;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
   HelpText<"Disable MSA ASE (MIPS only)">;
+def mmt : Flag<["-"], "mmt">, Group,
+  HelpText<"Enable MT ASE (MIPS only)">;
+def mno_mt : Flag<["-"], "mno-mt">, Group,
+  HelpText<"Disable MT ASE (MIPS only)">;
 def mfp64 : Flag<["-"], "mfp64">, Group,
   HelpText<"Use 64-bit floating point registers (MIPS only)">;
 def mfp32 : Flag<["-"], "mfp32">, Group,
Index: cfe/trunk/test/Driver/mips-features.c
===
--- cfe/trunk/test/Driver/mips-features.c
+++ cfe/trunk/test/Driver/mips-features.c
@@ -70,6 +70,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NOMMSA %s
 // CHECK-NOMMSA: "-target-feature" "-msa"
 //
+// -mmt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mno-mt -mmt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MMT %s
+// CHECK-MMT: "-target-feature" "+mt"
+//
+// -mno-mt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mmt -mno-mt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOMMT %s
+// CHECK-NOMMT: "-target-feature" "-mt"
+//
 // -modd-spreg
 // RUN: %clang -target mips-linux-gnu -### -c %s -mno-odd-spreg -modd-spreg 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MODDSPREG %s
Index: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
@@ -301,6 +301,7 @@
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mlong_calls,
options::OPT_mno_long_calls, "long-calls");
+  AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt,"mt");
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef ) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r307847 - [mips][mt][7/7] Add driver option for the MIPS MT ASE.

2017-07-12 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Wed Jul 12 14:13:05 2017
New Revision: 307847

URL: http://llvm.org/viewvc/llvm-project?rev=307847=rev
Log:
[mips][mt][7/7] Add driver option for the MIPS MT ASE.

Reviewers: atanasyan, slthakur

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
cfe/trunk/test/Driver/mips-features.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=307847=307846=307847=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Jul 12 14:13:05 2017
@@ -2027,6 +2027,10 @@ def mmsa : Flag<["-"], "mmsa">, Group;
 def mno_msa : Flag<["-"], "mno-msa">, Group,
   HelpText<"Disable MSA ASE (MIPS only)">;
+def mmt : Flag<["-"], "mmt">, Group,
+  HelpText<"Enable MT ASE (MIPS only)">;
+def mno_mt : Flag<["-"], "mno-mt">, Group,
+  HelpText<"Disable MT ASE (MIPS only)">;
 def mfp64 : Flag<["-"], "mfp64">, Group,
   HelpText<"Use 64-bit floating point registers (MIPS only)">;
 def mfp32 : Flag<["-"], "mfp32">, Group,

Modified: cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp?rev=307847=307846=307847=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Arch/Mips.cpp Wed Jul 12 14:13:05 2017
@@ -301,6 +301,7 @@ void mips::getMIPSTargetFeatures(const D
"nomadd4");
   AddTargetFeature(Args, Features, options::OPT_mlong_calls,
options::OPT_mno_long_calls, "long-calls");
+  AddTargetFeature(Args, Features, options::OPT_mmt, options::OPT_mno_mt,"mt");
 }
 
 mips::NanEncoding mips::getSupportedNanEncoding(StringRef ) {

Modified: cfe/trunk/test/Driver/mips-features.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/mips-features.c?rev=307847=307846=307847=diff
==
--- cfe/trunk/test/Driver/mips-features.c (original)
+++ cfe/trunk/test/Driver/mips-features.c Wed Jul 12 14:13:05 2017
@@ -70,6 +70,18 @@
 // RUN:   | FileCheck --check-prefix=CHECK-NOMMSA %s
 // CHECK-NOMMSA: "-target-feature" "-msa"
 //
+// -mmt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mno-mt -mmt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MMT %s
+// CHECK-MMT: "-target-feature" "+mt"
+//
+// -mno-mt
+// RUN: %clang -target mips-linux-gnu -### -c %s \
+// RUN: -mmt -mno-mt 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-NOMMT %s
+// CHECK-NOMMT: "-target-feature" "-mt"
+//
 // -modd-spreg
 // RUN: %clang -target mips-linux-gnu -### -c %s -mno-odd-spreg -modd-spreg 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MODDSPREG %s


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


[PATCH] D35081: [ThinLTO] Allow multiple summary entries.

2017-07-12 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson added a comment.

In https://reviews.llvm.org/D35081#805761, @yunlian wrote:

> I've sent a reproduce test case to tejohnson.


FYI I tracked down what is going on here and reproduced with a small test case. 
Essentially, two copies of a linkonce odr function were optimized somewhat 
differently by the compile step and have different instruction counts, with the 
prevailing one being larger. Depending on the order they are encountered during 
the thin link's callgraph traversal, we may initially decide to import the 
smaller non-prevailing copy, and later decide to import the larger prevailing 
copy. This should be fixed in the function importer, which needs to make a 
decision about which copy should be imported (the fix is simple, I just need to 
decide which fix is "right").

This is different than the situation Florian encountered, which is due to 
passing the full combined index to clang when invoking a distributed backend 
process, which we don't want users to do. Florian, I'd still like to understand 
better what the third party you are fixing this for is trying to do, so I can 
advise.


https://reviews.llvm.org/D35081



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


r307845 - Revert "[Driver] Update Fuchsia driver path handling"

2017-07-12 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Wed Jul 12 14:03:54 2017
New Revision: 307845

URL: http://llvm.org/viewvc/llvm-project?rev=307845=rev
Log:
Revert "[Driver] Update Fuchsia driver path handling"

The tests are failing on Windows.

This reverts commit 429fe8229496f639df6b0b4734beedb1d4317aa5.

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fuchsia.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=307845=307844=307845=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Wed Jul 12 14:03:54 2017
@@ -131,44 +131,16 @@ void fuchsia::Linker::ConstructJob(Compi
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
-static std::string computeTriple(llvm::Triple Triple) {
-  SmallString<64> T;
-  T += Triple.getArchName();
-  T += "-";
-  T += Triple.getOSName();
-  return T.str();
-}
-
-static std::string getTargetDir(const Driver ,
-llvm::Triple Triple) {
-  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
-  llvm::sys::path::append(P, "lib", computeTriple(Triple));
-  return P.str();
-}
-
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: ToolChain(D, Triple, Args) {
-  getProgramPaths().push_back(getDriver().getInstalledDir());
-  if (getDriver().getInstalledDir() != D.Dir)
-getProgramPaths().push_back(D.Dir);
-
-  SmallString<128> P(getTargetDir(D, getTriple()));
-  llvm::sys::path::append(P, "lib");
-  getFilePaths().push_back(P.str());
-
-  if (!D.SysRoot.empty()) {
-SmallString<128> P(D.SysRoot);
-llvm::sys::path::append(P, "lib");
-getFilePaths().push_back(P.str());
-  }
+: Generic_ELF(D, Triple, Args) {
+
+  getFilePaths().push_back(D.SysRoot + "/lib");
+  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
 }
 
-std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
- types::ID InputType) const {
-  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
-  Triple.setTriple(computeTriple(Triple));
-  return Triple.getTriple();
+Tool *Fuchsia::buildAssembler() const {
+  return new tools::gnutools::Assembler(*this);
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -236,44 +208,19 @@ void Fuchsia::AddClangSystemIncludeArgs(
 return;
   }
 
-  if (!D.SysRoot.empty()) {
-SmallString<128> P(D.SysRoot);
-llvm::sys::path::append(P, "include");
-addExternCSystemInclude(DriverArgs, CC1Args, P.str());
-  }
+  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
 }
 
-void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList ,
-   ArgStringList ) const {
-  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
-  DriverArgs.hasArg(options::OPT_nostdincxx))
-return;
-
-  switch (GetCXXStdlibType(DriverArgs)) {
-  case ToolChain::CST_Libcxx: {
-SmallString<128> P(getTargetDir(getDriver(), getTriple()));
-llvm::sys::path::append(P, "include", "c++", "v1");
-addSystemInclude(DriverArgs, CC1Args, P.str());
-break;
-  }
-
-  default:
-llvm_unreachable("invalid stdlib name");
-  }
+std::string Fuchsia::findLibCxxIncludePath() const {
+  return getDriver().SysRoot + "/include/c++/v1";
 }
 
 void Fuchsia::AddCXXStdlibLibArgs(const ArgList ,
   ArgStringList ) const {
-  switch (GetCXXStdlibType(Args)) {
-  case ToolChain::CST_Libcxx:
-CmdArgs.push_back("-lc++");
-CmdArgs.push_back("-lc++abi");
-CmdArgs.push_back("-lunwind");
-break;
-
-  case ToolChain::CST_Libstdcxx:
-llvm_unreachable("invalid stdlib name");
-  }
+  (void) GetCXXStdlibType(Args);
+  CmdArgs.push_back("-lc++");
+  CmdArgs.push_back("-lc++abi");
+  CmdArgs.push_back("-lunwind");
 }
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=307845=307844=307845=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Wed Jul 12 14:03:54 2017
@@ -35,29 +35,18 @@ public:
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
+  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
-  RuntimeLibType GetDefaultRuntimeLibType() const override {

[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added a comment.

> Looks like this demangler's design is similar to my demangler for Microsoft 
> name mangling scheme (https://reviews.llvm.org/D34667). Is that a 
> coincidence? Both demanglers create AST, stringize it using 
> print_left/print_right (I named them write_pre/write_post), and use custom 
> memory allocator. Looks like both demangler can share more code once both 
> land.

Yep, that was coincidental. I glanced at your patch and I think we could end up 
sharing some code here, which would be really neat.

> Do you think you can avoid STL containers so that your demangler don't need 
> any destructors? I observed that that makes my demangler faster.

The AST doesn't have destruction now for this reason, I used a bump pointer to 
allocate the AST. Looks like your patch followed this strategy too!


https://reviews.llvm.org/D35159



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a reviewer: mclow.lists.
dexonsmith added a subscriber: mclow.lists.
dexonsmith added a comment.

+mclow.lists




Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

mehdi_amini wrote:
> dexonsmith wrote:
> > erik.pilkington wrote:
> > > mehdi_amini wrote:
> > > > If this is supposed to be *the* ultimate LLVM demangler, can we follow 
> > > > LLVM coding standard?
> > > I would like if this followed LLVM conventions too, but this file is 
> > > already written following this style and leaving it in some middle state 
> > > would be ugly. All of libcxx[abi] follows this convention too, so this 
> > > isn't a problem that is isolated to this file.
> > I agree.  I'd be fine with clang-formatting the entire project, but that 
> > seems independent from this change.
> I'm not talking about pure "clang-format" but also naming for instance.
> 
> > I would like if this followed LLVM conventions too, but this file is 
> > already written following this style and leaving it in some middle state 
> > would be ugly.
> 
> Right, but in the meantime you're adding a significant amount of "debt".
> 
> > All of libcxx[abi] follows this convention too, so this isn't a problem 
> > that is isolated to this file.
> 
> This file is "special": it is shared (duplicated...) with LLVM.
> 
This is a patch for libcxxabi.  Duplicating the file in LLVM is what created 
technical debt, and that file has already diverged from libcxxabi.  That's 
where the bug is.

AFAICT, there is no requirement for LLVM subprojects to use LLVM naming 
schemes, and since libcxx and libcxxabi are implementing STL facilities, it's 
reasonable for them to use STL naming conventions (even in private 
implementations that aren't exposed to users).

(It would also be reasonable to follow LLVM naming conventions in private 
implementations, but that's not the current practice, and it would certainly 
inhibit code readability here to do so just for one type.)

Perhaps a compromise would be to rename `string_ref` to `string_view`, so that 
it sounds more like the equivalent STL type than the equivalent LLVM type.

@mclow.lists, would you like to weigh in as code owner here?  Should the naming 
scheme for new types in libcxxabi private implementations follow LLVM coding 
conventions, or libcxxabi coding conventions?


https://reviews.llvm.org/D35159



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In https://reviews.llvm.org/D35159#807075, @dexonsmith wrote:

> This LGTM.  Mehdi, do you have any other concerns?


No other concern (haven't looked further for any either)


https://reviews.llvm.org/D35159



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added a comment.

Looks like this demangler's design is similar to my demangler for Microsoft 
name mangling scheme (https://reviews.llvm.org/D34667). Is that a coincidence? 
Both demanglers create AST, stringize it using print_left/print_right (I named 
them write_pre/write_post), and use custom memory allocator. Looks like both 
demangler can share more code once both land.

Do you think you can avoid STL containers so that your demangler don't need any 
destructors? I observed that that makes my demangler faster.


https://reviews.llvm.org/D35159



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

dexonsmith wrote:
> erik.pilkington wrote:
> > mehdi_amini wrote:
> > > If this is supposed to be *the* ultimate LLVM demangler, can we follow 
> > > LLVM coding standard?
> > I would like if this followed LLVM conventions too, but this file is 
> > already written following this style and leaving it in some middle state 
> > would be ugly. All of libcxx[abi] follows this convention too, so this 
> > isn't a problem that is isolated to this file.
> I agree.  I'd be fine with clang-formatting the entire project, but that 
> seems independent from this change.
I'm not talking about pure "clang-format" but also naming for instance.

> I would like if this followed LLVM conventions too, but this file is already 
> written following this style and leaving it in some middle state would be 
> ugly.

Right, but in the meantime you're adding a significant amount of "debt".

> All of libcxx[abi] follows this convention too, so this isn't a problem that 
> is isolated to this file.

This file is "special": it is shared (duplicated...) with LLVM.



https://reviews.llvm.org/D35159



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


[PATCH] D35159: [libcxxabi][demangler] Use an AST to represent the demangled name

2017-07-12 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith added a comment.

This LGTM.  Mehdi, do you have any other concerns?




Comment at: src/cxa_demangle.cpp:44
 
+class string_ref
+{

erik.pilkington wrote:
> mehdi_amini wrote:
> > If this is supposed to be *the* ultimate LLVM demangler, can we follow LLVM 
> > coding standard?
> I would like if this followed LLVM conventions too, but this file is already 
> written following this style and leaving it in some middle state would be 
> ugly. All of libcxx[abi] follows this convention too, so this isn't a problem 
> that is isolated to this file.
I agree.  I'd be fine with clang-formatting the entire project, but that seems 
independent from this change.


https://reviews.llvm.org/D35159



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


r307838 - [DOXYGEN] Corrected typos and incorrect parameters description.

2017-07-12 Thread Ekaterina Romanova via cfe-commits
Author: kromanova
Date: Wed Jul 12 13:18:55 2017
New Revision: 307838

URL: http://llvm.org/viewvc/llvm-project?rev=307838=rev
Log:
[DOXYGEN] Corrected typos and incorrect parameters description.

Corrected several typos and incorrect parameters description that Sony
's techinical writer found during review.

I got an OK from Eric Christopher to commit doxygen comments without prior code
review upstream.


Modified:
cfe/trunk/lib/Headers/bmiintrin.h
cfe/trunk/lib/Headers/mmintrin.h

Modified: cfe/trunk/lib/Headers/bmiintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/bmiintrin.h?rev=307838=307837=307838=diff
==
--- cfe/trunk/lib/Headers/bmiintrin.h (original)
+++ cfe/trunk/lib/Headers/bmiintrin.h Wed Jul 12 13:18:55 2017
@@ -318,7 +318,7 @@ __blsi_u64(unsigned long long __X)
 ///
 /// \param __X
 ///An unsigned 64-bit integer used to create the mask.
-/// \returns A unsigned 64-bit integer containing the newly created mask.
+/// \returns An unsigned 64-bit integer containing the newly created mask.
 static __inline__ unsigned long long __DEFAULT_FN_ATTRS
 __blsmsk_u64(unsigned long long __X)
 {

Modified: cfe/trunk/lib/Headers/mmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/mmintrin.h?rev=307838=307837=307838=diff
==
--- cfe/trunk/lib/Headers/mmintrin.h (original)
+++ cfe/trunk/lib/Headers/mmintrin.h Wed Jul 12 13:18:55 2017
@@ -1289,7 +1289,7 @@ _mm_cmpgt_pi32(__m64 __m1, __m64 __m2)
 ///
 /// \headerfile 
 ///
-/// This intrinsic corresponds to the the  VXORPS / XORPS  instruction.
+/// This intrinsic corresponds to the  VXORPS / XORPS  instruction.
 ///
 /// \returns An initialized 64-bit integer vector with all elements set to 
zero.
 static __inline__ __m64 __DEFAULT_FN_ATTRS


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


[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-12 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added a comment.

In https://reviews.llvm.org/D33645#806852, @dcoughlin wrote:

> Do you have commit access, or do you need someone to commit it for you?


Thank you.
I don't have, I'm quite new at this project. :)


https://reviews.llvm.org/D33645



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


[PATCH] D28953: [analyzer] Eliminate analyzer limitations on symbolic constraint generation

2017-07-12 Thread Dominic Chen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307833: [analyzer] Support generating and reasoning over 
more symbolic constraint types (authored by ddcc).

Changed prior to commit:
  https://reviews.llvm.org/D28953?vs=106084=106284#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28953

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
  cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
  cfe/trunk/test/Analysis/analyzer_test.py
  cfe/trunk/test/Analysis/bitwise-ops.c
  cfe/trunk/test/Analysis/bool-assignment.c
  cfe/trunk/test/Analysis/conditional-path-notes.c
  cfe/trunk/test/Analysis/explain-svals.cpp
  cfe/trunk/test/Analysis/plist-macros-z3.cpp
  cfe/trunk/test/Analysis/plist-macros.cpp
  cfe/trunk/test/Analysis/range_casts.c
  cfe/trunk/test/Analysis/std-c-library-functions.c

Index: cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
@@ -1034,31 +1034,39 @@
 ProgramStateRef Z3ConstraintManager::assumeSymInclusiveRange(
 ProgramStateRef State, SymbolRef Sym, const llvm::APSInt ,
 const llvm::APSInt , bool InRange) {
+  ASTContext  = getBasicVals().getContext();
+  // FIXME: This should be a cast from a 1-bit integer type to a boolean type,
+  // but the former is not available in Clang. Instead, extend the APSInt
+  // directly.
+  bool isBoolTy = From.getBitWidth() == 1 && getAPSIntType(From).isNull();
+
   QualType RetTy;
   // The expression may be casted, so we cannot call getZ3DataExpr() directly
   Z3Expr Exp = getZ3Expr(Sym, );
-
-  assert((getAPSIntType(From) == getAPSIntType(To)) &&
- "Range values have different types!");
-  QualType RTy = getAPSIntType(From);
-  bool isSignedTy = RetTy->isSignedIntegerOrEnumerationType();
-  Z3Expr FromExp = Z3Expr::fromAPSInt(From);
-  Z3Expr ToExp = Z3Expr::fromAPSInt(To);
+  QualType RTy = isBoolTy ? Ctx.BoolTy : getAPSIntType(From);
+  Z3Expr FromExp =
+  isBoolTy ? Z3Expr::fromAPSInt(From.extend(Ctx.getTypeSize(Ctx.BoolTy)))
+   : Z3Expr::fromAPSInt(From);
 
   // Construct single (in)equality
   if (From == To)
 return assumeZ3Expr(State, Sym,
 getZ3BinExpr(Exp, RetTy, InRange ? BO_EQ : BO_NE,
  FromExp, RTy, nullptr));
 
+  assert((getAPSIntType(From) == getAPSIntType(To)) &&
+ "Range values have different types!");
+
+  Z3Expr ToExp = Z3Expr::fromAPSInt(To);
   // Construct two (in)equalities, and a logical and/or
   Z3Expr LHS =
   getZ3BinExpr(Exp, RetTy, InRange ? BO_GE : BO_LT, FromExp, RTy, nullptr);
   Z3Expr RHS =
   getZ3BinExpr(Exp, RetTy, InRange ? BO_LE : BO_GT, ToExp, RTy, nullptr);
   return assumeZ3Expr(
   State, Sym,
-  Z3Expr::fromBinOp(LHS, InRange ? BO_LAnd : BO_LOr, RHS, isSignedTy));
+  Z3Expr::fromBinOp(LHS, InRange ? BO_LAnd : BO_LOr, RHS,
+RetTy->isSignedIntegerOrEnumerationType()));
 }
 
 ProgramStateRef Z3ConstraintManager::assumeSymUnsupported(ProgramStateRef State,
@@ -1406,6 +1414,7 @@
QualType , QualType ) const {
   ASTContext  = getBasicVals().getContext();
 
+  assert(!LTy.isNull() && !RTy.isNull() && "Input type is null!");
   // Perform type conversion
   if (LTy->isIntegralOrEnumerationType() &&
   RTy->isIntegralOrEnumerationType()) {
@@ -1468,10 +1477,10 @@
 void Z3ConstraintManager::doIntTypeConversion(T , QualType , T ,
   QualType ) const {
   ASTContext  = getBasicVals().getContext();
-
   uint64_t LBitWidth = Ctx.getTypeSize(LTy);
   uint64_t RBitWidth = Ctx.getTypeSize(RTy);
 
+  assert(!LTy.isNull() && !RTy.isNull() && "Input type is null!");
   // Always perform integer promotion before checking type equality.
   // Otherwise, e.g. (bool) a + (bool) b could trigger a backend assertion
   if (LTy->isPromotableIntegerType()) {
Index: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
@@ -100,7 +100,7 @@
 
   if (T->isNullPtrType())
 return makeZeroVal(T);
-  
+
   if (!SymbolManager::canSymbolicate(T))
 return UnknownVal();
 
@@ -354,17 +354,14 @@
BinaryOperator::Opcode Op,
NonLoc LHS, NonLoc RHS,
QualType ResultTy) {
-  if (!State->isTainted(RHS) && !State->isTainted(LHS))
-return UnknownVal();
-
   const SymExpr *symLHS = LHS.getAsSymExpr();
   const SymExpr *symRHS = RHS.getAsSymExpr();
   // 

r307833 - [analyzer] Support generating and reasoning over more symbolic constraint types

2017-07-12 Thread Dominic Chen via cfe-commits
Author: ddcc
Date: Wed Jul 12 12:37:57 2017
New Revision: 307833

URL: http://llvm.org/viewvc/llvm-project?rev=307833=rev
Log:
[analyzer] Support generating and reasoning over more symbolic constraint types

Summary: Generate more IntSymExpr constraints, perform SVal simplification for 
IntSymExpr and SymbolCast constraints, and create fully symbolic SymExprs

Reviewers: zaks.anna, dcoughlin, NoQ, xazax.hun

Subscribers: mgorny, cfe-commits

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

Added:
cfe/trunk/test/Analysis/plist-macros-z3.cpp
  - copied, changed from r307830, cfe/trunk/test/Analysis/plist-macros.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp
cfe/trunk/test/Analysis/analyzer_test.py
cfe/trunk/test/Analysis/bitwise-ops.c
cfe/trunk/test/Analysis/bool-assignment.c
cfe/trunk/test/Analysis/conditional-path-notes.c
cfe/trunk/test/Analysis/explain-svals.cpp
cfe/trunk/test/Analysis/plist-macros.cpp
cfe/trunk/test/Analysis/range_casts.c
cfe/trunk/test/Analysis/std-c-library-functions.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h?rev=307833=307832=307833=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/SValExplainer.h Wed Jul 12 
12:37:57 2017
@@ -125,8 +125,14 @@ public:
 return OS.str();
   }
 
-  // TODO: IntSymExpr doesn't appear in practice.
-  // Add the relevant code once it does.
+  std::string VisitIntSymExpr(const IntSymExpr *S) {
+std::string Str;
+llvm::raw_string_ostream OS(Str);
+OS << S->getLHS()
+   << std::string(BinaryOperator::getOpcodeStr(S->getOpcode())) << " "
+   << "(" << Visit(S->getRHS()) << ") ";
+return OS.str();
+  }
 
   std::string VisitSymSymExpr(const SymSymExpr *S) {
 return "(" + Visit(S->getLHS()) + ") " +
@@ -134,8 +140,10 @@ public:
" (" + Visit(S->getRHS()) + ")";
   }
 
-  // TODO: SymbolCast doesn't appear in practice.
-  // Add the relevant code once it does.
+  std::string VisitSymbolCast(const SymbolCast *S) {
+return "cast of type '" + S->getType().getAsString() + "' of " +
+   Visit(S->getOperand());
+  }
 
   std::string VisitSymbolicRegion(const SymbolicRegion *R) {
 // Explain 'this' object here.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp?rev=307833=307832=307833=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp Wed Jul 12 12:37:57 2017
@@ -100,7 +100,7 @@ SValBuilder::getRegionValueSymbolVal(con
 
   if (T->isNullPtrType())
 return makeZeroVal(T);
-  
+
   if (!SymbolManager::canSymbolicate(T))
 return UnknownVal();
 
@@ -354,9 +354,6 @@ SVal SValBuilder::makeSymExprValNN(Progr
BinaryOperator::Opcode Op,
NonLoc LHS, NonLoc RHS,
QualType ResultTy) {
-  if (!State->isTainted(RHS) && !State->isTainted(LHS))
-return UnknownVal();
-
   const SymExpr *symLHS = LHS.getAsSymExpr();
   const SymExpr *symRHS = RHS.getAsSymExpr();
   // TODO: When the Max Complexity is reached, we should conjure a symbol
@@ -364,7 +361,7 @@ SVal SValBuilder::makeSymExprValNN(Progr
   const unsigned MaxComp = 1; // 10 28X
 
   if (symLHS && symRHS &&
-  (symLHS->computeComplexity() + symRHS->computeComplexity()) <  MaxComp)
+  (symLHS->computeComplexity() + symRHS->computeComplexity()) < MaxComp)
 return makeNonLoc(symLHS, Op, symRHS, ResultTy);
 
   if (symLHS && symLHS->computeComplexity() < MaxComp)

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=307833=307832=307833=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Wed Jul 12 12:37:57 
2017
@@ -669,12 +669,12 @@ SVal SimpleSValBuilder::evalBinOpLL(Prog
 // If one of the operands is a symbol and the other is a constant,
 // build an expression for use by the constraint manager.
 if (SymbolRef rSym = rhs.getAsLocSymbol()) {
-  // We can only build expressions with symbols on the left,
-  // so we need a reversible operator.
+ 

[PATCH] D34121: [ubsan] Teach the pointer overflow check that "p - <= p" (PR33430)

2017-07-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

@dtzWill do you have any further comments on this one?

I'd like to get another 'lgtm' before committing, and it'd be nice to get this 
in before llvm 5.0 branches (7/19).

FWIW we've been living on this for a few weeks internally without any issues:
https://github.com/apple/swift-clang/commit/3ebe7d87b9d545aebdd80452d0b79695ff871bce


https://reviews.llvm.org/D34121



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


[PATCH] D32613: [Driver] Update Fuchsia driver path handling

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307830: [Driver] Update Fuchsia driver path handling 
(authored by phosek).

Changed prior to commit:
  https://reviews.llvm.org/D32613?vs=106275=106276#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32613

Files:
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
  cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
  cfe/trunk/test/Driver/fuchsia.cpp

Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
@@ -35,18 +35,29 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
 return llvm::DebuggerKind::GDB;
   }
 
+  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList ,
+  types::ID InputType) const override;
+
   SanitizerMask getSupportedSanitizers() const override;
 
   RuntimeLibType
@@ -60,16 +71,17 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
-  std::string findLibCxxIncludePath() const override;
+  void
+  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
 return "lld";
   }
 
 protected:
-  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,44 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string computeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", computeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
+ types::ID InputType) const {
+  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
+  Triple.setTriple(computeTriple(Triple));
+  return Triple.getTriple();
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -208,19 +236,44 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "include");
+addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+  }
 }
 
-std::string Fuchsia::findLibCxxIncludePath() const {
-  return getDriver().SysRoot + "/include/c++/v1";
+void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList ,
+   ArgStringList ) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  

r307830 - [Driver] Update Fuchsia driver path handling

2017-07-12 Thread Petr Hosek via cfe-commits
Author: phosek
Date: Wed Jul 12 12:15:51 2017
New Revision: 307830

URL: http://llvm.org/viewvc/llvm-project?rev=307830=rev
Log:
[Driver] Update Fuchsia driver path handling

Several improvements to the Fuchsia driver:

* Search for C++ library headers and libraries in directories that
are part of the toolchain distribution rather than sysroot.

* Use LLVM support utlities to construct paths to make sure the driver
is also usable on Windows for cross-compiling.

* Change the driver to inherit directly from ToolChain rather than
Generic_GCC since we don't need any of the GCC related multilib logic.

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

Modified:
cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
cfe/trunk/test/Driver/fuchsia.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp?rev=307830=307829=307830=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.cpp Wed Jul 12 12:15:51 2017
@@ -131,16 +131,44 @@ void fuchsia::Linker::ConstructJob(Compi
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string computeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", computeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
+ types::ID InputType) const {
+  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
+  Triple.setTriple(computeTriple(Triple));
+  return Triple.getTriple();
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -208,19 +236,44 @@ void Fuchsia::AddClangSystemIncludeArgs(
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "include");
+addExternCSystemInclude(DriverArgs, CC1Args, P.str());
+  }
 }
 
-std::string Fuchsia::findLibCxxIncludePath() const {
-  return getDriver().SysRoot + "/include/c++/v1";
+void Fuchsia::AddClangCXXStdlibIncludeArgs(const ArgList ,
+   ArgStringList ) const {
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> P(getTargetDir(getDriver(), getTriple()));
+llvm::sys::path::append(P, "include", "c++", "v1");
+addSystemInclude(DriverArgs, CC1Args, P.str());
+break;
+  }
+
+  default:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 void Fuchsia::AddCXXStdlibLibArgs(const ArgList ,
   ArgStringList ) const {
-  (void) GetCXXStdlibType(Args);
-  CmdArgs.push_back("-lc++");
-  CmdArgs.push_back("-lc++abi");
-  CmdArgs.push_back("-lunwind");
+  switch (GetCXXStdlibType(Args)) {
+  case ToolChain::CST_Libcxx:
+CmdArgs.push_back("-lc++");
+CmdArgs.push_back("-lc++abi");
+CmdArgs.push_back("-lunwind");
+break;
+
+  case ToolChain::CST_Libstdcxx:
+llvm_unreachable("invalid stdlib name");
+  }
 }
 
 SanitizerMask Fuchsia::getSupportedSanitizers() const {

Modified: cfe/trunk/lib/Driver/ToolChains/Fuchsia.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Fuchsia.h?rev=307830=307829=307830=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Fuchsia.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/Fuchsia.h Wed Jul 12 12:15:51 2017
@@ -35,18 +35,29 @@ public:
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class 

[PATCH] D32613: [Driver] Update Fuchsia driver path handling

2017-07-12 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 106275.

Repository:
  rL LLVM

https://reviews.llvm.org/D32613

Files:
  lib/Driver/ToolChains/Fuchsia.cpp
  lib/Driver/ToolChains/Fuchsia.h
  test/Driver/fuchsia.cpp

Index: test/Driver/fuchsia.cpp
===
--- test/Driver/fuchsia.cpp
+++ test/Driver/fuchsia.cpp
@@ -1,9 +1,10 @@
 // RUN: %clangxx %s -### -no-canonical-prefixes --target=x86_64-unknown-fuchsia \
 // RUN: --sysroot=%S/platform 2>&1 -fuse-ld=ld | FileCheck %s
 // CHECK: {{.*}}clang{{.*}}" "-cc1"
+// CHECK: "-triple" "x86_64-fuchsia"
 // CHECK: "-fuse-init-array"
 // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]"
-// CHECK: "-internal-isystem" "[[SYSROOT]]{{/|}}include{{/|}}c++{{/|}}v1"
+// CHECK: "-internal-isystem" "{{.*[/\\]}}x86_64-fuchsia{{/|}}include{{/|}}c++{{/|}}v1"
 // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|}}include"
 // CHECK: {{.*}}lld{{.*}}" "-flavor" "gnu"
 // CHECK: "--sysroot=[[SYSROOT]]"
Index: lib/Driver/ToolChains/Fuchsia.h
===
--- lib/Driver/ToolChains/Fuchsia.h
+++ lib/Driver/ToolChains/Fuchsia.h
@@ -35,18 +35,29 @@
 
 namespace toolchains {
 
-class LLVM_LIBRARY_VISIBILITY Fuchsia : public Generic_ELF {
+class LLVM_LIBRARY_VISIBILITY Fuchsia : public ToolChain {
 public:
   Fuchsia(const Driver , const llvm::Triple ,
   const llvm::opt::ArgList );
 
-  bool isPIEDefault() const override { return true; }
   bool HasNativeLLVMSupport() const override { return true; }
   bool IsIntegratedAssemblerDefault() const override { return true; }
+  RuntimeLibType GetDefaultRuntimeLibType() const override {
+return ToolChain::RLT_CompilerRT;
+  }
+  CXXStdlibType GetDefaultCXXStdlibType() const override {
+return ToolChain::CST_Libcxx;
+  }
+  bool isPICDefault() const override { return false; }
+  bool isPIEDefault() const override { return true; }
+  bool isPICDefaultForced() const override { return false; }
   llvm::DebuggerKind getDefaultDebuggerTuning() const override {
 return llvm::DebuggerKind::GDB;
   }
 
+  std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList ,
+  types::ID InputType) const override;
+
   SanitizerMask getSupportedSanitizers() const override;
 
   RuntimeLibType
@@ -60,16 +71,17 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
-  std::string findLibCxxIncludePath() const override;
+  void
+  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const override;
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList ,
llvm::opt::ArgStringList ) const override;
 
   const char *getDefaultLinker() const override {
 return "lld";
   }
 
 protected:
-  Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
 };
 
Index: lib/Driver/ToolChains/Fuchsia.cpp
===
--- lib/Driver/ToolChains/Fuchsia.cpp
+++ lib/Driver/ToolChains/Fuchsia.cpp
@@ -131,16 +131,44 @@
 
 /// Fuchsia - Fuchsia tool chain which can call as(1) and ld(1) directly.
 
+static std::string computeTriple(llvm::Triple Triple) {
+  SmallString<64> T;
+  T += Triple.getArchName();
+  T += "-";
+  T += Triple.getOSName();
+  return T.str();
+}
+
+static std::string getTargetDir(const Driver ,
+llvm::Triple Triple) {
+  SmallString<128> P(llvm::sys::path::parent_path(D.Dir));
+  llvm::sys::path::append(P, "lib", computeTriple(Triple));
+  return P.str();
+}
+
 Fuchsia::Fuchsia(const Driver , const llvm::Triple ,
  const ArgList )
-: Generic_ELF(D, Triple, Args) {
-
-  getFilePaths().push_back(D.SysRoot + "/lib");
-  getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
+: ToolChain(D, Triple, Args) {
+  getProgramPaths().push_back(getDriver().getInstalledDir());
+  if (getDriver().getInstalledDir() != D.Dir)
+getProgramPaths().push_back(D.Dir);
+
+  SmallString<128> P(getTargetDir(D, getTriple()));
+  llvm::sys::path::append(P, "lib");
+  getFilePaths().push_back(P.str());
+
+  if (!D.SysRoot.empty()) {
+SmallString<128> P(D.SysRoot);
+llvm::sys::path::append(P, "lib");
+getFilePaths().push_back(P.str());
+  }
 }
 
-Tool *Fuchsia::buildAssembler() const {
-  return new tools::gnutools::Assembler(*this);
+std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList ,
+ types::ID InputType) const {
+  llvm::Triple Triple(ComputeLLVMTriple(Args, InputType));
+  Triple.setTriple(computeTriple(Triple));
+  return Triple.getTriple();
 }
 
 Tool *Fuchsia::buildLinker() const {
@@ -208,19 +236,44 @@
 return;
   }
 
-  addExternCSystemInclude(DriverArgs, CC1Args, D.SysRoot + "/include");
+  if 

[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-12 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 106268.
rnkovacs added a comment.
Herald added a subscriber: baloghadamsoftware.

- Added `char[]` exception along with a test case. There are no more false 
positives on LLVM.
- Simplified fix-its by using `clang::tooling::fixit` functions.


https://reviews.llvm.org/D32700

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp
  clang-tidy/bugprone/SuspiciousMemsetUsageCheck.h
  clang-tidy/google/CMakeLists.txt
  clang-tidy/google/GoogleTidyModule.cpp
  clang-tidy/google/MemsetZeroLengthCheck.cpp
  clang-tidy/google/MemsetZeroLengthCheck.h
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-suspicious-memset-usage.rst
  docs/clang-tidy/checks/google-runtime-memset.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/bugprone-suspicious-memset-usage.cpp
  test/clang-tidy/google-runtime-memset-zero-length.cpp

Index: test/clang-tidy/google-runtime-memset-zero-length.cpp
===
--- test/clang-tidy/google-runtime-memset-zero-length.cpp
+++ /dev/null
@@ -1,62 +0,0 @@
-// RUN: %check_clang_tidy %s google-runtime-memset %t
-
-void *memset(void *, int, __SIZE_TYPE__);
-
-namespace std {
-  using ::memset;
-}
-
-template 
-void memtmpl() {
-  memset(0, sizeof(int), i);
-  memset(0, sizeof(T), sizeof(T));
-  memset(0, sizeof(T), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(T));
-  memset(0, sizeof(int), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(0, 0, sizeof(int));
-}
-
-void foo(void *a, int xsize, int ysize) {
-  memset(a, sizeof(int), 0);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, 0, sizeof(int));
-#define M memset(a, sizeof(int), 0);
-  M
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: #define M memset(a, sizeof(int), 0);
-  ::memset(a, xsize *
-   ysize, 0);
-// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: ::memset(a, 0, xsize *
-// CHECK-FIXES-NEXT: ysize);
-  std::memset(a, sizeof(int), 0x00);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: std::memset(a, 0x00, sizeof(int));
-
-  const int v = 0;
-  memset(a, sizeof(int), v);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, v, sizeof(int));
-
-  memset(a, sizeof(int), v + v);
-// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
-// CHECK-FIXES: memset(a, v + v, sizeof(int));
-
-  memset(a, sizeof(int), v + 1);
-
-  memset(a, -1, sizeof(int));
-  memset(a, 0xcd, 1);
-
-  // Don't warn when the fill char and the length are both known to be
-  // zero.  No bug is possible.
-  memset(a, 0, v);
-  memset(a, v, 0);
-
-  // -1 is clearly not a length by virtue of being negative, so no warning
-  // despite v == 0.
-  memset(a, -1, v);
-
-  memtmpl<0, int>();
-}
Index: test/clang-tidy/bugprone-suspicious-memset-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-suspicious-memset-usage.cpp
@@ -0,0 +1,77 @@
+// RUN: %check_clang_tidy %s bugprone-suspicious-memset-usage %t
+
+void *memset(void *, int, __SIZE_TYPE__);
+
+namespace std {
+  using ::memset;
+}
+
+template 
+void mtempl(int *ptr) {
+  memset(ptr, '0', sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(ptr, 0, sizeof(T));
+  memset(ptr, 256, sizeof(T));
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: memset fill value is out of unsigned character range, gets truncated [bugprone-suspicious-memset-usage]
+  memset(0, sizeof(T), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(T));
+  memset(0, sizeof(int), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped arguments [bugprone-suspicious-memset-usage]
+// CHECK-FIXES: memset(0, 0, sizeof(int));
+}
+
+void foo(int xsize, int ysize) {
+  int i[5] = {1, 2, 3, 4, 5};
+  char ca[3] = {'a', 'b', 'c'};
+  int *p = i;
+  int l = 5;
+  char z = '1';
+  char *c = 
+  int v = 0;
+
+  memset(p, '0', l);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: memset fill value is char '0', potentially mistaken for int 0 [bugprone-suspicious-memset-usage]
+// 

[PATCH] D34301: [Sema] Make sure the definition of a referenced virtual function is emitted when it is final

2017-07-12 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

I suggest changing the API for 'canDevirtualizeCall' a bit but this is looking 
great overall. The code movement and test case changes look good.




Comment at: include/clang/AST/DeclCXX.h:1902
+  bool canDevirtualizeCall(const Expr *Base, bool IsAppleKext,
+   CXXMethodDecl *);
+

Something like `CXXMethodDecl *getDevirtualizedMethod(...)` would fit in better 
with the current API. E.g, getCorrespondingMethodInClass is done this way (and 
returns nullptr when a method is not found).



Comment at: lib/AST/DeclCXX.cpp:1693
+  const CXXMethodDecl *DM;
+  return ::canDevirtualizeCall(Base, this, IsAppleKext, DM);
+}

Instead of templating canDevirtualizeCall, you could do something like 
`const_cast(this)->getDevirtualizedMethod(...)`.


https://reviews.llvm.org/D34301



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


[PATCH] D35082: [OpenCL] Add LangAS::opencl_private to represent private address space in AST

2017-07-12 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/AST/Expr.cpp:3235
+// has non-default address space it is not treated as nullptr.
+bool PointeeHasDefaultAS = false;
+if (Ctx.getLangOpts().OpenCL)

Would we still be accepting the following:
  global int * ptr = (global void*)0;



Comment at: lib/Sema/SemaDecl.cpp:7964
+PointeeType.getAddressSpace() == LangAS::opencl_private ||
 PointeeType.getAddressSpace() == 0)
   return InvalidAddrSpacePtrKernelParam;

Could we use `LangAS::Default` instead?



Comment at: lib/Sema/SemaDecl.cpp:11846
   // an address space.
   if (T.getAddressSpace() != 0) {
 // OpenCL allows function arguments declared to be an array of a type

Could we use `LangAS::Default` here too?



Comment at: lib/Sema/SemaDecl.cpp:11851
+  (T->isArrayType() ||
+   T.getAddressSpace() == LangAS::opencl_private))) {
   Diag(NameLoc, diag::err_arg_with_address_space);

Would it be better to lift this into if condition of line 11846?



Comment at: lib/Sema/SemaType.cpp:6969
 
+  if (state.getSema().getLangOpts().OpenCL &&
+  !hasOpenCLAddressSpace && type.getAddressSpace() == 0 &&

Would it be nicer to not append any address space at all neither here nor down 
at the end of this function and keep it default instead until the Codegen? If 
it's doable I would very much prefer that. It seems like it would make the 
implementation potentially a bit cleaner to understand and easier to improve 
semantical analysis. See one example of improving original type printing in my 
comment to the test below.

Also there are at least these 3 related bugs open currently:
https://bugs.llvm.org//show_bug.cgi?id=33418
https://bugs.llvm.org//show_bug.cgi?id=33419
https://bugs.llvm.org//show_bug.cgi?id=33420

Does your change address any of those?



Comment at: test/SemaOpenCL/access-qualifier.cl:23
 #else
-void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 
'read_write' can not be used for '__read_write image1d_t' prior to OpenCL 
version 2.0}}
+void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 
'read_write' can not be used for '__private __read_write image1d_t' prior to 
OpenCL version 2.0}}
 #endif

Ok, I think that here it would be less confusing not to add any address space 
since it's missing in the original source.


https://reviews.llvm.org/D35082



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


r307822 - [OPENMP] Emit implicit taskgroup block around taskloop directives.

2017-07-12 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Jul 12 11:09:32 2017
New Revision: 307822

URL: http://llvm.org/viewvc/llvm-project?rev=307822=rev
Log:
[OPENMP] Emit implicit taskgroup block around taskloop directives.

If taskloop directive has no associated nogroup clause, it must emitted
inside implicit taskgroup block. Runtime supports it, but we need to
generate implicit taskgroup block explicitly to support future
reductions codegen.

Modified:
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/test/OpenMP/taskloop_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_codegen.cpp

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=307822=307821=307822=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Jul 12 11:09:32 2017
@@ -4157,9 +4157,15 @@ void CGOpenMPRuntime::emitTaskLoopCall(C
/*IsInitializer=*/true);
   enum { NoSchedule = 0, Grainsize = 1, NumTasks = 2 };
   llvm::Value *TaskArgs[] = {
-  UpLoc, ThreadID, Result.NewTask, IfVal, LBLVal.getPointer(),
-  UBLVal.getPointer(), CGF.EmitLoadOfScalar(StLVal, SourceLocation()),
-  llvm::ConstantInt::getSigned(CGF.IntTy, Data.Nogroup ? 1 : 0),
+  UpLoc,
+  ThreadID,
+  Result.NewTask,
+  IfVal,
+  LBLVal.getPointer(),
+  UBLVal.getPointer(),
+  CGF.EmitLoadOfScalar(StLVal, SourceLocation()),
+  llvm::ConstantInt::getNullValue(
+  CGF.IntTy), // Always 0 because taskgroup emitted by the compiler
   llvm::ConstantInt::getSigned(
   CGF.IntTy, Data.Schedule.getPointer()
  ? Data.Schedule.getInt() ? NumTasks : Grainsize
@@ -4168,10 +4174,9 @@ void CGOpenMPRuntime::emitTaskLoopCall(C
   ? CGF.Builder.CreateIntCast(Data.Schedule.getPointer(), CGF.Int64Ty,
   /*isSigned=*/false)
   : llvm::ConstantInt::get(CGF.Int64Ty, /*V=*/0),
-  Result.TaskDupFn
-  ? CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(Result.TaskDupFn,
-CGF.VoidPtrTy)
-  : llvm::ConstantPointerNull::get(CGF.VoidPtrTy)};
+  Result.TaskDupFn ? CGF.Builder.CreatePointerBitCastOrAddrSpaceCast(
+ Result.TaskDupFn, CGF.VoidPtrTy)
+   : llvm::ConstantPointerNull::get(CGF.VoidPtrTy)};
   CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_taskloop), TaskArgs);
 }
 

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=307822=307821=307822=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Wed Jul 12 11:09:32 2017
@@ -4363,7 +4363,18 @@ void CodeGenFunction::EmitOMPTaskLoopBas
 CGF.CGM.getOpenMPRuntime().emitInlinedDirective(CGF, OMPD_taskloop,
 CodeGen);
   };
-  EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Data);
+  if (Data.Nogroup)
+EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Data);
+  else {
+CGM.getOpenMPRuntime().emitTaskgroupRegion(
+*this,
+[, , , ](CodeGenFunction ,
+PrePostActionTy ) {
+  Action.Enter(CGF);
+  CGF.EmitOMPTaskBasedDirective(S, BodyGen, TaskGen, Data);
+},
+S.getLocStart());
+  }
 }
 
 void CodeGenFunction::EmitOMPTaskLoopDirective(const OMPTaskLoopDirective ) {

Modified: cfe/trunk/test/OpenMP/taskloop_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_codegen.cpp?rev=307822=307821=307822=diff
==
--- cfe/trunk/test/OpenMP/taskloop_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/taskloop_codegen.cpp Wed Jul 12 11:09:32 2017
@@ -8,6 +8,7 @@
 // CHECK-LABEL: @main
 int main(int argc, char **argv) {
 // CHECK: [[GTID:%.+]] = call i32 @__kmpc_global_thread_num(%ident_t* 
[[DEFLOC:@.+]])
+// CHECK: call void @__kmpc_taskgroup(%ident_t* [[DEFLOC]], i32 [[GTID]])
 // CHECK: [[TASKV:%.+]] = call i8* @__kmpc_omp_task_alloc(%ident_t* 
[[DEFLOC]], i32 [[GTID]], i32 33, i64 72, i64 1, i32 (i32, i8*)* bitcast (i32 
(i32, [[TDP_TY:%.+]]*)* [[TASK1:@.+]] to i32 (i32, i8*)*))
 // CHECK: [[TASK:%.+]] = bitcast i8* [[TASKV]] to [[TDP_TY]]*
 // CHECK: [[TASK_DATA:%.+]] = getelementptr inbounds [[TDP_TY]], [[TDP_TY]]* 
[[TASK]], i32 0, i32 0
@@ -19,6 +20,7 @@ int main(int argc, char **argv) {
 // CHECK: store i64 1, i64* [[ST]],
 // CHECK: [[ST_VAL:%.+]] = load i64, i64* [[ST]],
 // CHECK: call void @__kmpc_taskloop(%ident_t* [[DEFLOC]], i32 [[GTID]], i8* 
[[TASKV]], i32 1, i64* 

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-12 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!

Do you have commit access, or do you need someone to commit it for you?


https://reviews.llvm.org/D33645



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


[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-12 Thread Yan Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307818: [clang-tidy] Add a new Android check 
"android-cloexec-socket" (authored by yawanng).

Changed prior to commit:
  https://reviews.llvm.org/D34913?vs=106058=106252#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34913

Files:
  clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
  clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
  clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
  clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-socket.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/android-cloexec-socket.cpp

Index: clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
@@ -0,0 +1,35 @@
+//===--- CloexecSocketCheck.h - clang-tidy---*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+/// Finds code that uses socket() without using the SOCK_CLOEXEC flag.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/android-cloexec-socket.html
+class CloexecSocketCheck : public ClangTidyCheck {
+public:
+  CloexecSocketCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace android
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ANDROID_CLOEXEC_SOCKET_H
Index: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
===
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
@@ -5,6 +5,7 @@
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
   CloexecOpenCheck.cpp
+  CloexecSocketCheck.cpp
 
   LINK_LIBS
   clangAST
Index: clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
@@ -0,0 +1,57 @@
+//===--- CloexecSocketCheck.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 "CloexecSocketCheck.h"
+#include "../utils/ASTUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace android {
+
+static constexpr const char *SOCK_CLOEXEC = "SOCK_CLOEXEC";
+
+void CloexecSocketCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  callExpr(callee(functionDecl(isExternC(), returns(isInteger()),
+   hasName("socket"),
+   hasParameter(0, hasType(isInteger())),
+   hasParameter(1, hasType(isInteger())),
+   hasParameter(2, hasType(isInteger(
+  .bind("funcDecl")))
+  .bind("socketFn"),
+  this);
+}
+
+void CloexecSocketCheck::check(const MatchFinder::MatchResult ) {
+  const auto *MatchedCall = Result.Nodes.getNodeAs("socketFn");
+  const auto *FD = Result.Nodes.getNodeAs("funcDecl");
+  const Expr *FlagArg = MatchedCall->getArg(1);
+  SourceManager  = *Result.SourceManager;
+
+  if (utils::exprHasBitFlagWithSpelling(FlagArg->IgnoreParenCasts(), SM,
+ Result.Context->getLangOpts(), SOCK_CLOEXEC))
+return;
+
+  SourceLocation EndLoc =
+  Lexer::getLocForEndOfToken(SM.getFileLoc(FlagArg->getLocEnd()), 0, SM,
+

[clang-tools-extra] r307818 - [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-12 Thread Yan Wang via cfe-commits
Author: yawanng
Date: Wed Jul 12 10:43:36 2017
New Revision: 307818

URL: http://llvm.org/viewvc/llvm-project?rev=307818=rev
Log:
[clang-tidy] Add a new Android check "android-cloexec-socket"

Summary: socket() is better to include SOCK_CLOEXEC in its type argument to 
avoid the file descriptor leakage.

Reviewers: chh, Eugene.Zelenko, alexfh, hokein, aaron.ballman

Reviewed By: chh, alexfh

Subscribers: srhines, mgorny, JDevlieghere, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.cpp
clang-tools-extra/trunk/clang-tidy/android/CloexecSocketCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/android-cloexec-socket.rst
clang-tools-extra/trunk/test/clang-tidy/android-cloexec-socket.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.cpp
clang-tools-extra/trunk/clang-tidy/utils/ASTUtils.h
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp?rev=307818=307817=307818=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/AndroidTidyModule.cpp Wed Jul 12 
10:43:36 2017
@@ -13,6 +13,7 @@
 #include "CloexecCreatCheck.h"
 #include "CloexecFopenCheck.h"
 #include "CloexecOpenCheck.h"
+#include "CloexecSocketCheck.h"
 
 using namespace clang::ast_matchers;
 
@@ -27,6 +28,7 @@ public:
 CheckFactories.registerCheck("android-cloexec-creat");
 CheckFactories.registerCheck("android-cloexec-fopen");
 CheckFactories.registerCheck("android-cloexec-open");
+CheckFactories.registerCheck("android-cloexec-socket");
   }
 };
 

Modified: clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt?rev=307818=307817=307818=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CMakeLists.txt Wed Jul 12 
10:43:36 2017
@@ -5,6 +5,7 @@ add_clang_library(clangTidyAndroidModule
   CloexecCreatCheck.cpp
   CloexecFopenCheck.cpp
   CloexecOpenCheck.cpp
+  CloexecSocketCheck.cpp
 
   LINK_LIBS
   clangAST

Modified: clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp?rev=307818=307817=307818=diff
==
--- clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/android/CloexecOpenCheck.cpp Wed Jul 12 
10:43:36 2017
@@ -8,6 +8,7 @@
 
//===--===//
 
 #include "CloexecOpenCheck.h"
+#include "../utils/ASTUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -18,35 +19,8 @@ namespace clang {
 namespace tidy {
 namespace android {
 
-namespace {
 static constexpr const char *O_CLOEXEC = "O_CLOEXEC";
 
-bool hasCloseOnExecFlag(const Expr *Flags, const SourceManager ,
-const LangOptions ) {
-  // If the Flag is an integer constant, check it.
-  if (isa(Flags)) {
-if (!SM.isMacroBodyExpansion(Flags->getLocStart()) &&
-!SM.isMacroArgExpansion(Flags->getLocStart()))
-  return false;
-
-// Get the Marco name.
-auto MacroName = Lexer::getSourceText(
-CharSourceRange::getTokenRange(Flags->getSourceRange()), SM, LangOpts);
-
-return MacroName == O_CLOEXEC;
-  }
-  // If it's a binary OR operation.
-  if (const auto *BO = dyn_cast(Flags))
-if (BO->getOpcode() == clang::BinaryOperatorKind::BO_Or)
-  return hasCloseOnExecFlag(BO->getLHS()->IgnoreParenCasts(), SM,
-LangOpts) ||
- hasCloseOnExecFlag(BO->getRHS()->IgnoreParenCasts(), SM, 
LangOpts);
-
-  // Otherwise, assume it has the flag.
-  return true;
-}
-} // namespace
-
 void CloexecOpenCheck::registerMatchers(MatchFinder *Finder) {
   auto CharPointerType = hasType(pointerType(pointee(isAnyCharacter(;
 
@@ -82,8 +56,8 @@ void CloexecOpenCheck::check(const Match
 
   // Check the required flag.
   SourceManager  = *Result.SourceManager;
-  if (hasCloseOnExecFlag(FlagArg->IgnoreParenCasts(), SM,
- 

[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-12 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In https://reviews.llvm.org/D34913#806799, @yawanng wrote:

> In https://reviews.llvm.org/D34913#797577, @Eugene.Zelenko wrote:
>
> > Please wait for Alexander, Aaron or Haojian approval.
>
>
> Could you please check this CL? Thank you.


You could commit changes, since Alexander approved them.


https://reviews.llvm.org/D34913



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


[PATCH] D34913: [clang-tidy] Add a new Android check "android-cloexec-socket"

2017-07-12 Thread Yan Wang via Phabricator via cfe-commits
yawanng added a comment.

In https://reviews.llvm.org/D34913#797577, @Eugene.Zelenko wrote:

> Please wait for Alexander, Aaron or Haojian approval.


Could you please check this CL? Thank you.


https://reviews.llvm.org/D34913



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-12 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 106243.
wangxindsb added a comment.

- Change function name to start with a lower case letter.
- Use `StringRef` instead of `const char * ' for ReportBug() const.
- Correct the braces for single statement blocks.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,100 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
+class G {
+public:
+  G() {}
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning

[PATCH] D35306: [diagtool] Add the 'find-diagnostic-id' subcommand that converts a name of the diagnostic to its enum value

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307813: [diagtool] Add a 'find-diagnostic-id' subcommand 
that converts a name of (authored by arphaman).

Changed prior to commit:
  https://reviews.llvm.org/D35306?vs=106211=106245#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35306

Files:
  cfe/trunk/test/Misc/find-diagnostic-id.c
  cfe/trunk/tools/diagtool/CMakeLists.txt
  cfe/trunk/tools/diagtool/FindDiagnosticID.cpp


Index: cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
===
--- cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
+++ cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
@@ -0,0 +1,58 @@
+//===- FindDiagnosticID.cpp - diagtool tool for finding diagnostic id 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DiagTool.h"
+#include "DiagnosticNames.h"
+#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/CommandLine.h"
+
+DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
+ FindDiagnosticID)
+
+using namespace clang;
+using namespace diagtool;
+
+static Optional
+findDiagnostic(ArrayRef Diagnostics, StringRef Name) {
+  for (const auto  : Diagnostics) {
+StringRef DiagName = Diag.getName();
+if (DiagName == Name)
+  return Diag;
+  }
+  return None;
+}
+
+int FindDiagnosticID::run(unsigned int argc, char **argv,
+  llvm::raw_ostream ) {
+  static llvm::cl::OptionCategory FindDiagnosticIDOptions(
+  "diagtool find-diagnostic-id options");
+
+  static llvm::cl::opt DiagnosticName(
+  llvm::cl::Positional, llvm::cl::desc(""),
+  llvm::cl::Required, llvm::cl::cat(FindDiagnosticIDOptions));
+
+  std::vector Args;
+  Args.push_back("find-diagnostic-id");
+  for (const char *A : llvm::makeArrayRef(argv, argc))
+Args.push_back(A);
+
+  llvm::cl::HideUnrelatedOptions(FindDiagnosticIDOptions);
+  llvm::cl::ParseCommandLineOptions((int)Args.size(), Args.data(),
+"Diagnostic ID mapping utility");
+
+  ArrayRef AllDiagnostics = getBuiltinDiagnosticsByName();
+  Optional Diag =
+  findDiagnostic(AllDiagnostics, DiagnosticName);
+  if (!Diag) {
+llvm::errs() << "error: invalid diagnostic '" << DiagnosticName << "'\n";
+return 1;
+  }
+  OS << Diag->DiagID << "\n";
+  return 0;
+}
Index: cfe/trunk/tools/diagtool/CMakeLists.txt
===
--- cfe/trunk/tools/diagtool/CMakeLists.txt
+++ cfe/trunk/tools/diagtool/CMakeLists.txt
@@ -6,6 +6,7 @@
   diagtool_main.cpp
   DiagTool.cpp
   DiagnosticNames.cpp
+  FindDiagnosticID.cpp
   ListWarnings.cpp
   ShowEnabledWarnings.cpp
   TreeView.cpp
Index: cfe/trunk/test/Misc/find-diagnostic-id.c
===
--- cfe/trunk/test/Misc/find-diagnostic-id.c
+++ cfe/trunk/test/Misc/find-diagnostic-id.c
@@ -0,0 +1,5 @@
+// RUN: diagtool find-diagnostic-id warn_unused_variable | FileCheck %s
+// RUN: not diagtool find-diagnostic-id warn_unused_vars 2>&1 | FileCheck 
--check-prefix=ERROR %s
+
+// CHECK: {{^[0-9]+$}}
+// ERROR: error: invalid diagnostic 'warn_unused_vars'


Index: cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
===
--- cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
+++ cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
@@ -0,0 +1,58 @@
+//===- FindDiagnosticID.cpp - diagtool tool for finding diagnostic id -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DiagTool.h"
+#include "DiagnosticNames.h"
+#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/CommandLine.h"
+
+DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
+ FindDiagnosticID)
+
+using namespace clang;
+using namespace diagtool;
+
+static Optional
+findDiagnostic(ArrayRef Diagnostics, StringRef Name) {
+  for (const auto  : Diagnostics) {
+StringRef DiagName = Diag.getName();
+if (DiagName == Name)
+  return Diag;
+  }
+  return None;
+}
+
+int FindDiagnosticID::run(unsigned int argc, char **argv,
+  llvm::raw_ostream ) {
+  static llvm::cl::OptionCategory FindDiagnosticIDOptions(
+  "diagtool find-diagnostic-id options");
+
+  static llvm::cl::opt DiagnosticName(
+  llvm::cl::Positional, llvm::cl::desc(""),
+  llvm::cl::Required, llvm::cl::cat(FindDiagnosticIDOptions));
+
+  std::vector Args;
+  

r307813 - [diagtool] Add a 'find-diagnostic-id' subcommand that converts a name of

2017-07-12 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Wed Jul 12 09:41:49 2017
New Revision: 307813

URL: http://llvm.org/viewvc/llvm-project?rev=307813=rev
Log:
[diagtool] Add a 'find-diagnostic-id' subcommand that converts a name of
the diagnostic to its enum value

This will be used by a script that invokes clang in a debugger and forces it
to stop when it reports a particular diagnostic.

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

Added:
cfe/trunk/test/Misc/find-diagnostic-id.c
cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
Modified:
cfe/trunk/tools/diagtool/CMakeLists.txt

Added: cfe/trunk/test/Misc/find-diagnostic-id.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Misc/find-diagnostic-id.c?rev=307813=auto
==
--- cfe/trunk/test/Misc/find-diagnostic-id.c (added)
+++ cfe/trunk/test/Misc/find-diagnostic-id.c Wed Jul 12 09:41:49 2017
@@ -0,0 +1,5 @@
+// RUN: diagtool find-diagnostic-id warn_unused_variable | FileCheck %s
+// RUN: not diagtool find-diagnostic-id warn_unused_vars 2>&1 | FileCheck 
--check-prefix=ERROR %s
+
+// CHECK: {{^[0-9]+$}}
+// ERROR: error: invalid diagnostic 'warn_unused_vars'

Modified: cfe/trunk/tools/diagtool/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/diagtool/CMakeLists.txt?rev=307813=307812=307813=diff
==
--- cfe/trunk/tools/diagtool/CMakeLists.txt (original)
+++ cfe/trunk/tools/diagtool/CMakeLists.txt Wed Jul 12 09:41:49 2017
@@ -6,6 +6,7 @@ add_clang_executable(diagtool
   diagtool_main.cpp
   DiagTool.cpp
   DiagnosticNames.cpp
+  FindDiagnosticID.cpp
   ListWarnings.cpp
   ShowEnabledWarnings.cpp
   TreeView.cpp

Added: cfe/trunk/tools/diagtool/FindDiagnosticID.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/diagtool/FindDiagnosticID.cpp?rev=307813=auto
==
--- cfe/trunk/tools/diagtool/FindDiagnosticID.cpp (added)
+++ cfe/trunk/tools/diagtool/FindDiagnosticID.cpp Wed Jul 12 09:41:49 2017
@@ -0,0 +1,58 @@
+//===- FindDiagnosticID.cpp - diagtool tool for finding diagnostic id 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DiagTool.h"
+#include "DiagnosticNames.h"
+#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/CommandLine.h"
+
+DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
+ FindDiagnosticID)
+
+using namespace clang;
+using namespace diagtool;
+
+static Optional
+findDiagnostic(ArrayRef Diagnostics, StringRef Name) {
+  for (const auto  : Diagnostics) {
+StringRef DiagName = Diag.getName();
+if (DiagName == Name)
+  return Diag;
+  }
+  return None;
+}
+
+int FindDiagnosticID::run(unsigned int argc, char **argv,
+  llvm::raw_ostream ) {
+  static llvm::cl::OptionCategory FindDiagnosticIDOptions(
+  "diagtool find-diagnostic-id options");
+
+  static llvm::cl::opt DiagnosticName(
+  llvm::cl::Positional, llvm::cl::desc(""),
+  llvm::cl::Required, llvm::cl::cat(FindDiagnosticIDOptions));
+
+  std::vector Args;
+  Args.push_back("find-diagnostic-id");
+  for (const char *A : llvm::makeArrayRef(argv, argc))
+Args.push_back(A);
+
+  llvm::cl::HideUnrelatedOptions(FindDiagnosticIDOptions);
+  llvm::cl::ParseCommandLineOptions((int)Args.size(), Args.data(),
+"Diagnostic ID mapping utility");
+
+  ArrayRef AllDiagnostics = getBuiltinDiagnosticsByName();
+  Optional Diag =
+  findDiagnostic(AllDiagnostics, DiagnosticName);
+  if (!Diag) {
+llvm::errs() << "error: invalid diagnostic '" << DiagnosticName << "'\n";
+return 1;
+  }
+  OS << Diag->DiagID << "\n";
+  return 0;
+}


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


[PATCH] D31700: [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-07-12 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307812: [clang-tidy] Ignore blank spaces between cast's ")" 
and its sub expr. (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D31700

Files:
  clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp


Index: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -58,10 +58,9 @@
 
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult ) {
   const auto *CastExpr = Result.Nodes.getNodeAs("cast");
-  auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
-   CastExpr->getRParenLoc());
+
   // Ignore casts in macros.
-  if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
+  if (CastExpr->getExprLoc().isMacroID())
 return;
 
   // Casting to void is an idiomatic way to mute "unused variable" and similar
@@ -82,6 +81,9 @@
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
+  auto ReplaceRange = CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getLocStart());
+
   bool FnToFnCast =
   isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
 
@@ -92,7 +94,7 @@
 // pointer/reference types.
 if (SourceTypeAsWritten == DestTypeAsWritten) {
   diag(CastExpr->getLocStart(), "redundant cast to the same type")
-  << FixItHint::CreateRemoval(ParenRange);
+  << FixItHint::CreateRemoval(ReplaceRange);
   return;
 }
   }
@@ -136,7 +138,7 @@
  getLangOpts()),
   ")");
 }
-Diag << FixItHint::CreateReplacement(ParenRange, CastText);
+Diag << FixItHint::CreateReplacement(ReplaceRange, CastText);
   };
   auto ReplaceWithNamedCast = [&](StringRef CastType) {
 Diag << CastType;
Index: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
@@ -85,6 +85,22 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   // CHECK-FIXES: b1 = (const int&)b;
 
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
   Y *pB = (Y*)pX;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   Y  = (Y&)*pX;
@@ -114,6 +130,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  e = e;
 
+  e = (Enum)   e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = e;
+
+  e = (Enum)   (e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = (e);
+
   static const int kZero = 0;
   (int)kZero;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type


Index: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -58,10 +58,9 @@
 
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult ) {
   const auto *CastExpr = Result.Nodes.getNodeAs("cast");
-  auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
-   CastExpr->getRParenLoc());
+
   // Ignore casts in macros.
-  if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
+  if (CastExpr->getExprLoc().isMacroID())
 return;
 
   // Casting to void is an idiomatic way to mute "unused variable" and similar
@@ -82,6 +81,9 @@
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
+  auto ReplaceRange = 

[clang-tools-extra] r307812 - [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-07-12 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Wed Jul 12 09:38:59 2017
New Revision: 307812

URL: http://llvm.org/viewvc/llvm-project?rev=307812=rev
Log:
[clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

Summary:
Before the change:

`auto i = (Enum) 5;` => `auto i = static_cast( 5);`

After the change:

`auto i = (Enum) 5;` => `auto i = static_cast(5);`

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp

Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=307812=307811=307812=diff
==
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Wed Jul 
12 09:38:59 2017
@@ -58,10 +58,9 @@ static bool pointedUnqualifiedTypesAreEq
 
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult ) {
   const auto *CastExpr = Result.Nodes.getNodeAs("cast");
-  auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
-   CastExpr->getRParenLoc());
+
   // Ignore casts in macros.
-  if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
+  if (CastExpr->getExprLoc().isMacroID())
 return;
 
   // Casting to void is an idiomatic way to mute "unused variable" and similar
@@ -82,6 +81,9 @@ void AvoidCStyleCastsCheck::check(const
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
+  auto ReplaceRange = CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getLocStart());
+
   bool FnToFnCast =
   isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
 
@@ -92,7 +94,7 @@ void AvoidCStyleCastsCheck::check(const
 // pointer/reference types.
 if (SourceTypeAsWritten == DestTypeAsWritten) {
   diag(CastExpr->getLocStart(), "redundant cast to the same type")
-  << FixItHint::CreateRemoval(ParenRange);
+  << FixItHint::CreateRemoval(ReplaceRange);
   return;
 }
   }
@@ -136,7 +138,7 @@ void AvoidCStyleCastsCheck::check(const
  getLangOpts()),
   ")");
 }
-Diag << FixItHint::CreateReplacement(ParenRange, CastText);
+Diag << FixItHint::CreateReplacement(ReplaceRange, CastText);
   };
   auto ReplaceWithNamedCast = [&](StringRef CastType) {
 Diag << CastType;

Modified: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp?rev=307812=307811=307812=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp Wed 
Jul 12 09:38:59 2017
@@ -85,6 +85,22 @@ void f(int a, double b, const char *cpc,
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   // CHECK-FIXES: b1 = (const int&)b;
 
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
   Y *pB = (Y*)pX;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   Y  = (Y&)*pX;
@@ -114,6 +130,14 @@ void f(int a, double b, const char *cpc,
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  e = e;
 
+  e = (Enum)   e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = e;
+
+  e = (Enum)   (e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = (e);
+
   static const int kZero = 0;
   (int)kZero;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D32478: [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set

2017-07-12 Thread Francois Ferrand via Phabricator via cfe-commits
Typz added a comment.

I renamed the option to `AlignAfterOperator`, is it acceptable now?
(I also thought of `UnindentOperator`, but I think it is better to keep the 
notion of alignment)

Note that this style is used in multiple open-source projects: Skia 
, parts of QtCreator 
 code base 
(e.g. in multiple plugins: clang, cpptools, android...), the OpenEXR 
 library...


https://reviews.llvm.org/D32478



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


[PATCH] D35225: [clang-tidy] add regression test to performance-unnecessary-value-param

2017-07-12 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307810: [clang-tidy] add regression test to 
performance-unnecessary-value-param (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35225?vs=106064=106241#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35225

Files:
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
  
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
  
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp


Index: 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- 
-std=c++11 -I %T
+// RUN: diff %T/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
===
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  const ABC& v1,   const ABC& v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   const ABC& v2); // line 15
Index: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
===
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  ABC v1,   ABC v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   ABC v2); // line 15


Index: clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- -std=c++11 -I %T
+// RUN: diff %T/header.h %S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}
Index: 

[clang-tools-extra] r307810 - [clang-tidy] add regression test to performance-unnecessary-value-param

2017-07-12 Thread Chih-Hung Hsieh via cfe-commits
Author: chh
Date: Wed Jul 12 09:27:00 2017
New Revision: 307810

URL: http://llvm.org/viewvc/llvm-project?rev=307810=rev
Log:
[clang-tidy] add regression test to performance-unnecessary-value-param

This test shows the problem in https://bugs.llvm.org/show_bug.cgi?id=33734

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

Added:

clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/

clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h

clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h

clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp

Added: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h?rev=307810=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header-fixed.h
 Wed Jul 12 09:27:00 2017
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  const ABC& v1,   const ABC& v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   const ABC& v2); // line 15

Added: 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h?rev=307810=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/Inputs/performance-unnecessary-value-param/header.h
 Wed Jul 12 09:27:00 2017
@@ -0,0 +1,15 @@
+// struct ABC is expensive to copy and should be
+// passed as a const referece.
+struct ABC {
+  ABC(const ABC&);
+  int get(int) const;
+};
+
+
+int f1(int n,  ABC v1,   ABC v2); // line 9
+
+int f1(int n, ABC v1); // line 11
+
+
+
+int f2(int n,   ABC v2); // line 15

Added: 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp?rev=307810=auto
==
--- 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
 (added)
+++ 
clang-tools-extra/trunk/test/clang-tidy/performance-unnecessary-value-param-header.cpp
 Wed Jul 12 09:27:00 2017
@@ -0,0 +1,18 @@
+// RUN: cp %S/Inputs/performance-unnecessary-value-param/header.h %T/header.h
+// RUN: %check_clang_tidy %s performance-unnecessary-value-param %t -- -- 
-std=c++11 -I %T
+// RUN: diff %T/header.h 
%S/Inputs/performance-unnecessary-value-param/header-fixed.h
+
+#include "header.h"
+
+
+
+int f1(int n, ABC v1, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v1' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-MESSAGES: [[@LINE-2]]:27: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f1(int n, const ABC& v1, const ABC& v2) {
+  return v1.get(n) + v2.get(n);
+}
+int f2(int n, ABC v2) {
+  // CHECK-MESSAGES: [[@LINE-1]]:19: warning: the parameter 'v2' is copied for 
each invocation but only used as a const reference; consider making it a const 
reference [performance-unnecessary-value-param]
+  // CHECK-FIXES: int f2(int n, const ABC& v2) {
+}


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


r307809 - [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

2017-07-12 Thread Chih-Hung Hsieh via cfe-commits
Author: chh
Date: Wed Jul 12 09:25:40 2017
New Revision: 307809

URL: http://llvm.org/viewvc/llvm-project?rev=307809=rev
Log:
[clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

Fix bug https://bugs.llvm.org/show_bug.cgi?id=33734

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

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

Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=307809=307808=307809=diff
==
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Wed Jul 12 09:25:40 2017
@@ -1052,7 +1052,8 @@ static void highlightRange(const CharSou
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap ,
ArrayRef Hints,
const SourceManager ,
@@ -1069,7 +1070,8 @@ static std::string buildFixItInsertionLi
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) 
{
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@ static std::string buildFixItInsertionLi
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@ void TextDiagnostic::emitSnippetAndCaret
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.


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


[PATCH] D35230: [clang] buildFixItInsertionLine should use Hints of the same FID and LineNo

2017-07-12 Thread Chih-Hung Hsieh via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307809: [clang] buildFixItInsertionLine should use Hints of 
the same FID and LineNo (authored by chh).

Changed prior to commit:
  https://reviews.llvm.org/D35230?vs=105937=106240#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35230

Files:
  cfe/trunk/lib/Frontend/TextDiagnostic.cpp


Index: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
===
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap ,
ArrayRef Hints,
const SourceManager ,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) 
{
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.


Index: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
===
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp
@@ -1052,7 +1052,8 @@
   std::fill(CaretLine.begin()+StartColNo,CaretLine.begin()+EndColNo,'~');
 }
 
-static std::string buildFixItInsertionLine(unsigned LineNo,
+static std::string buildFixItInsertionLine(FileID FID,
+   unsigned LineNo,
const SourceColumnMap ,
ArrayRef Hints,
const SourceManager ,
@@ -1069,7 +1070,8 @@
   // code contains no newlines and is on the same line as the caret.
   std::pair HintLocInfo
 = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-  if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
+  if (FID == HintLocInfo.first &&
+  LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) &&
   StringRef(I->CodeToInsert).find_first_of("\n\r") == StringRef::npos) {
 // Insert the new code into the line just below the code
 // that the user wrote.
@@ -1105,9 +1107,6 @@
 
 PrevHintEndCol =
   HintCol + llvm::sys::locale::columnWidth(I->CodeToInsert);
-  } else {
-FixItInsertionLine.clear();
-break;
   }
 }
   }
@@ -1222,7 +1221,7 @@
 }
 
 std::string FixItInsertionLine = buildFixItInsertionLine(
-LineNo, sourceColMap, Hints, SM, DiagOpts.get());
+FID, LineNo, sourceColMap, Hints, SM, DiagOpts.get());
 
 // If the source line is too long for our terminal, select only the
 // "interesting" source region within that line.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D35118: [AArch64] Add support for handling the +sve target feature

2017-07-12 Thread Renato Golin via Phabricator via cfe-commits
rengolin added a reviewer: jmolloy.
rengolin added a subscriber: jmolloy.
rengolin added a comment.

@jmolloy Can you check this change, please?




Comment at: lib/Basic/Targets.cpp:6245
   enum FPUModeEnum {
-FPUMode,
-NeonMode
+NeonMode = (1 << 0),
+SveMode = (1 << 1)

aemerson wrote:
> rengolin wrote:
> > Is there any AArch64 arch without SIMD?
> > 
> > Anyway, that seems deliberate, @t.p.northover any idea?
> SIMD support can be disabled with +nosimd. This change doesn't affect how 
> that works.
The commit that introduced this (by James) states: "Allow the disabling of NEON 
and crypto instructions."

I wouldn't remove the FPUMode as is.

It's also surprising that this passes the test that James updated on the same 
commit. Maybe the tests weren't good enough?


Repository:
  rL LLVM

https://reviews.llvm.org/D35118



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


[PATCH] D31700: [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-07-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.

LG. Thanks!


https://reviews.llvm.org/D31700



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


[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

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

LG




Comment at: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp:39
+  // Check whether source object is not TriviallyCopyable.
+  // Only applicable to memcpy() and memmove().
+  Finder->addMatcher(

rnkovacs wrote:
> alexfh wrote:
> > What about `memset`?
> `memset` has a bit different signature than the other two. It has a fill 
> value as its second argument instead of a source object.
Ah, now I get it. We're inspecting the second argument here.


https://reviews.llvm.org/D35051



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


[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-12 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs marked 2 inline comments as done.
rnkovacs added inline comments.



Comment at: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp:39
+  // Check whether source object is not TriviallyCopyable.
+  // Only applicable to memcpy() and memmove().
+  Finder->addMatcher(

alexfh wrote:
> What about `memset`?
`memset` has a bit different signature than the other two. It has a fill value 
as its second argument instead of a source object.


https://reviews.llvm.org/D35051



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


[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-07-12 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer updated this revision to Diff 106228.
SjoerdMeijer added a comment.

This fixes:

- type mangling for `_Float16` (approved here: 
https://github.com/itanium-cxx-abi/cxx-abi/pull/22, but not yet committed. )
- removed the argument promotion for `_Float16` that I added because it turns 
out that it does not apply to `_Float16` but only to the standard float types.
- the nit in the comments of the literal parser.


https://reviews.llvm.org/D33719

Files:
  include/clang-c/Index.h
  include/clang/AST/ASTContext.h
  include/clang/AST/BuiltinTypes.def
  include/clang/Basic/Specifiers.h
  include/clang/Basic/TokenKinds.def
  include/clang/Lex/LiteralSupport.h
  include/clang/Sema/DeclSpec.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/AST/NSAPI.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/Type.cpp
  lib/AST/TypeLoc.cpp
  lib/Analysis/PrintfFormatString.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/Format/FormatToken.cpp
  lib/Index/USRGeneration.cpp
  lib/Lex/LiteralSupport.cpp
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseExpr.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseTentative.cpp
  lib/Sema/DeclSpec.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaTemplateVariadic.cpp
  lib/Sema/SemaType.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReader.cpp
  test/CodeGenCXX/float16-declarations.cpp
  test/Frontend/float16.cpp
  test/Lexer/half-literal.cpp
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -53,6 +53,7 @@
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
+BTCASE(Float16);
 BTCASE(Float128);
 BTCASE(NullPtr);
 BTCASE(Overload);
@@ -520,7 +521,7 @@
 TKIND(Char_U);
 TKIND(UChar);
 TKIND(Char16);
-TKIND(Char32);  
+TKIND(Char32);
 TKIND(UShort);
 TKIND(UInt);
 TKIND(ULong);
@@ -538,6 +539,7 @@
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);
+TKIND(Float16);
 TKIND(Float128);
 TKIND(NullPtr);
 TKIND(Overload);
Index: test/Lexer/half-literal.cpp
===
--- test/Lexer/half-literal.cpp
+++ test/Lexer/half-literal.cpp
@@ -1,3 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s
 float a = 1.0h; // expected-error{{invalid suffix 'h' on floating constant}}
 float b = 1.0H; // expected-error{{invalid suffix 'H' on floating constant}}
+
+_Float16 c = 1.f166; // expected-error{{invalid suffix 'f166' on floating constant}}
+_Float16 d = 1.f1;   // expected-error{{invalid suffix 'f1' on floating constant}}
Index: test/Frontend/float16.cpp
===
--- /dev/null
+++ test/Frontend/float16.cpp
@@ -0,0 +1,299 @@
+// RUN: %clang_cc1 -std=c++11 -ast-dump %s | FileCheck %s
+// RUN: %clang_cc1 -std=c++11 -ast-dump -fnative-half-type %s | FileCheck %s --check-prefix=CHECK-NATIVE
+
+/*  Various contexts where type _Float16 can appear. */
+
+/*  Namespace */
+namespace {
+  _Float16 f1n;
+  _Float16 f2n = 33.f16;
+  _Float16 arr1n[10];
+  _Float16 arr2n[] = { 1.2, 3.0, 3.e4 };
+  const volatile _Float16 func1n(const _Float16 ) {
+return arg + f2n + arr1n[4] - arr2n[1];
+  }
+}
+
+//CHECK: |-NamespaceDecl
+//CHECK: | |-VarDecl {{.*}} f1n '_Float16'
+//CHECK: | |-VarDecl {{.*}} f2n '_Float16' cinit
+//CHECK: | | `-FloatingLiteral {{.*}} '_Float16' 3.30e+01
+//CHECK: | |-VarDecl {{.*}} arr1n '_Float16 [10]'
+//CHECK: | |-VarDecl {{.*}} arr2n '_Float16 [3]' cinit
+//CHECK: | | `-InitListExpr {{.*}} '_Float16 [3]'
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 1.20e+00
+//CHECK: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | |   | `-FloatingLiteral {{.*}} 'double' 3.00e+00
+//CHECK: | |   `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: | | `-FloatingLiteral {{.*}} 'double' 3.00e+04
+//CHECK: | `-FunctionDecl {{.*}} func1n 'const volatile _Float16 (const _Float16 &)'
+
+/* File */
+_Float16 f1f;
+_Float16 f2f = 32.4;
+_Float16 arr1f[10];
+_Float16 arr2f[] = { -1.2, -3.0, -3.e4 };
+_Float16 func1f(_Float16 arg);
+
+//CHECK: |-VarDecl {{.*}} f1f '_Float16'
+//CHECK: |-VarDecl {{.*}} f2f '_Float16' cinit
+//CHECK: | `-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: |   `-FloatingLiteral {{.*}} 'double' 3.24e+01
+//CHECK: |-VarDecl {{.*}} arr1f '_Float16 [10]'
+//CHECK: |-VarDecl {{.*}} arr2f '_Float16 [3]' cinit
+//CHECK: | `-InitListExpr {{.*}} '_Float16 [3]'
+//CHECK: |   |-ImplicitCastExpr {{.*}} '_Float16' 
+//CHECK: |   | `-UnaryOperator {{.*}} 'double' prefix '-'
+//CHECK: |   |   `-FloatingLiteral {{.*}} 'double' 1.20e+00
+//CHECK: |   |-ImplicitCastExpr {{.*}} 

[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-12 Thread Reka Kovacs via Phabricator via cfe-commits
rnkovacs updated this revision to Diff 106234.
rnkovacs added a comment.
Herald added a subscriber: baloghadamsoftware.

Removed redundant parens and stray semicolons.


https://reviews.llvm.org/D35051

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
  clang-tidy/bugprone/UndefinedMemoryManipulationCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-undefined-memory-manipulation.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-undefined-memory-manipulation.cpp

Index: test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
@@ -0,0 +1,178 @@
+// RUN: %check_clang_tidy %s bugprone-undefined-memory-manipulation %t
+
+void *memset(void *, int, __SIZE_TYPE__);
+void *memcpy(void *, const void *, __SIZE_TYPE__);
+void *memmove(void *, const void *, __SIZE_TYPE__);
+
+namespace std {
+using ::memcpy;
+using ::memmove;
+using ::memset;
+}
+
+// TriviallyCopyable types:
+struct Plain {
+  int n;
+};
+
+enum E {
+  X,
+  Y,
+  Z
+};
+
+struct Base {
+  float b;
+};
+
+struct Derived : Base {
+  bool d;
+};
+
+// not TriviallyCopyable types:
+struct Destruct {
+  ~Destruct() {}
+};
+
+struct Copy {
+  Copy() {}
+  Copy(const Copy &) {}
+};
+
+struct Move {
+  Move() {}
+  Move(Move &&) {}
+};
+
+struct VirtualFunc {
+  virtual void f() {}
+};
+
+struct VirtualBase : virtual Base {
+  int vb;
+};
+
+template 
+void memset_temp(T *b) {
+  memset(b, 0, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+}
+
+template 
+void memcpy_temp(S *a, T *b) {
+  memcpy(a, b, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+}
+
+template 
+void memmove_temp(S *a, T *b) {
+  memmove(a, b, sizeof(T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+}
+
+void notTriviallyCopyable() {
+  Plain p; // TriviallyCopyable for variety
+  Destruct d;
+  Copy c;
+  Move m;
+  VirtualFunc vf;
+  VirtualBase vb;
+
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  std::memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  ::memset(, 0, sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  std::memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  ::memcpy(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  std::memmove(, , sizeof(int));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object is not TriviallyCopyable [bugprone-undefined-memory-manipulation]
+  ::memmove(, , sizeof(int));
+  // CHECK-MESSAGES: 

[PATCH] D35306: [diagtool] Add the 'find-diagnostic-id' subcommand that converts a name of the diagnostic to its enum value

2017-07-12 Thread don hinton via Phabricator via cfe-commits
hintonda accepted this revision.
hintonda added a comment.
This revision is now accepted and ready to land.

LGTM.

Category ids' might be useful, but I'd wait until someone actually needs them.


Repository:
  rL LLVM

https://reviews.llvm.org/D35306



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


Re: [clang-tools-extra] r307701 - Fix clang-tidy diagnostic.cpp test on Windows

2017-07-12 Thread Alexander Kornienko via cfe-commits
Thank you!

On Tue, Jul 11, 2017 at 10:22 PM, Reid Kleckner via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: rnk
> Date: Tue Jul 11 13:22:17 2017
> New Revision: 307701
>
> URL: http://llvm.org/viewvc/llvm-project?rev=307701=rev
> Log:
> Fix clang-tidy diagnostic.cpp test on Windows
>
> Modified:
> clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
>
> Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/test/clang-tidy/diagnostic.cpp?rev=307701=
> 307700=307701=diff
> 
> ==
> --- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
> +++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Tue Jul 11
> 13:22:17 2017
> @@ -13,7 +13,7 @@
>  // use it after failing to parse commands from the command line:
>  //
>  // RUN: mkdir -p %T/diagnostics/
> -// RUN: echo '[{"directory": "%T/diagnostics/","command": "clang++
> -fan-option-from-compilation-database -c %T/diagnostics/input.cpp",
> "file": "%T/diagnostics/input.cpp"}]' > %T/diagnostics/compile_
> commands.json
> +// RUN: echo '[{"directory": "%/T/diagnostics/","command": "clang++
> -fan-option-from-compilation-database -c %/T/diagnostics/input.cpp",
> "file": "%/T/diagnostics/input.cpp"}]' > %T/diagnostics/compile_
> commands.json
>  // RUN: cat %s > %T/diagnostics/input.cpp
>  // RUN: clang-tidy -checks='-*,modernize-use-override'
> %T/diagnostics/nonexistent.cpp -- 2>&1 | FileCheck -check-prefix=CHECK1
> -implicit-check-not='{{warning:|error:}}' %s
>  // RUN: clang-tidy 
> -checks='-*,clang-diagnostic-*,google-explicit-constructor'
> %T/diagnostics/input.cpp -- -fan-unknown-option 2>&1 | FileCheck
> -check-prefix=CHECK2 -implicit-check-not='{{warning:|error:}}' %s
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32700: [clang-tidy] Add bugprone-suspicious-memset-usage check.

2017-07-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh added inline comments.



Comment at: clang-tidy/bugprone/SuspiciousMemsetUsageCheck.cpp:127-130
+SourceRange LHSRange = FillChar->getSourceRange();
+SourceRange RHSRange = ByteCount->getSourceRange();
+StringRef RHSString = getAsString(Result, RHSRange);
+StringRef LHSString = getAsString(Result, LHSRange);

It looks like this can be replaced with `clang::tooling::fixit::getText()` or 
even `createReplacement`.


https://reviews.llvm.org/D32700



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


[PATCH] D35051: [clang-tidy] Add bugprone-undefined-memory-manipulation check.

2017-07-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added inline comments.
This revision now requires changes to proceed.



Comment at: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp:22
+AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
+  return !(Node.isTriviallyCopyable());
+}

nit: No need for the parentheses.



Comment at: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp:39
+  // Check whether source object is not TriviallyCopyable.
+  // Only applicable to memcpy() and memmove().
+  Finder->addMatcher(

What about `memset`?



Comment at: test/clang-tidy/bugprone-undefined-memory-manipulation.cpp:34
+struct Destruct {
+  ~Destruct() {};
+};

Remove stray semicolons after closing braces of function bodies.


https://reviews.llvm.org/D35051



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


r307795 - [clang-format] Keep level of comment before an empty line

2017-07-12 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jul 12 08:21:43 2017
New Revision: 307795

URL: http://llvm.org/viewvc/llvm-project?rev=307795=rev
Log:
[clang-format] Keep level of comment before an empty line

Summary:
This patch fixes bug https://bugs.llvm.org/show_bug.cgi?id=3313: a comment line
was aligned with the next #ifdef even in the presence of an empty line between
them.

Reviewers: djasper, klimek

Reviewed By: djasper

Subscribers: klimek, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=307795=307794=307795=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jul 12 08:21:43 2017
@@ -1694,17 +1694,26 @@ void TokenAnnotator::setCommentLineLevel
   for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(),
   E = Lines.rend();
I != E; ++I) {
-bool CommentLine = (*I)->First;
+bool CommentLine = true;
 for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
   if (!Tok->is(tok::comment)) {
 CommentLine = false;
 break;
   }
 }
-if (NextNonCommentLine && CommentLine)
-  (*I)->Level = NextNonCommentLine->Level;
-else
+
+if (NextNonCommentLine && CommentLine) {
+  // If the comment is currently aligned with the line immediately 
following
+  // it, that's probably intentional and we should keep it.
+  bool AlignedWithNextLine =
+  NextNonCommentLine->First->NewlinesBefore <= 1 &&
+  NextNonCommentLine->First->OriginalColumn ==
+  (*I)->First->OriginalColumn;
+  if (AlignedWithNextLine)
+(*I)->Level = NextNonCommentLine->Level;
+} else {
   NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
+}
 
 setCommentLineLevels((*I)->Children);
   }

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=307795=307794=307795=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jul 12 08:21:43 2017
@@ -825,12 +825,35 @@ TEST_F(FormatTest, FormatsSwitchStatemen
"  case A:\n"
"f();\n"
"break;\n"
-   "  // On B:\n"
+   "// fallthrough\n"
"  case B:\n"
"g();\n"
"break;\n"
"  }\n"
"});");
+  EXPECT_EQ("DEBUG({\n"
+"  switch (x) {\n"
+"  case A:\n"
+"f();\n"
+"break;\n"
+"  // On B:\n"
+"  case B:\n"
+"g();\n"
+"break;\n"
+"  }\n"
+"});",
+format("DEBUG({\n"
+   "  switch (x) {\n"
+   "  case A:\n"
+   "f();\n"
+   "break;\n"
+   "  // On B:\n"
+   "  case B:\n"
+   "g();\n"
+   "break;\n"
+   "  }\n"
+   "});",
+   getLLVMStyle()));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"

Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=307795=307794=307795=diff
==
--- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Jul 12 08:21:43 2017
@@ -805,6 +805,70 @@ TEST_F(FormatTestComments, ParsesComment
 format("namespace {}\n   /* Test */#define A"));
 }
 
+TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
+  // Keep the current level if the comment was originally not aligned with
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+

[PATCH] D35296: [clang-format] Keep level of comment before an empty line

2017-07-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL307795: [clang-format] Keep level of comment before an empty 
line (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D35296

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

Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1694,17 +1694,26 @@
   for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(),
   E = Lines.rend();
I != E; ++I) {
-bool CommentLine = (*I)->First;
+bool CommentLine = true;
 for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
   if (!Tok->is(tok::comment)) {
 CommentLine = false;
 break;
   }
 }
-if (NextNonCommentLine && CommentLine)
-  (*I)->Level = NextNonCommentLine->Level;
-else
+
+if (NextNonCommentLine && CommentLine) {
+  // If the comment is currently aligned with the line immediately following
+  // it, that's probably intentional and we should keep it.
+  bool AlignedWithNextLine =
+  NextNonCommentLine->First->NewlinesBefore <= 1 &&
+  NextNonCommentLine->First->OriginalColumn ==
+  (*I)->First->OriginalColumn;
+  if (AlignedWithNextLine)
+(*I)->Level = NextNonCommentLine->Level;
+} else {
   NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
+}
 
 setCommentLineLevels((*I)->Children);
   }
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -825,12 +825,35 @@
"  case A:\n"
"f();\n"
"break;\n"
-   "  // On B:\n"
+   "// fallthrough\n"
"  case B:\n"
"g();\n"
"break;\n"
"  }\n"
"});");
+  EXPECT_EQ("DEBUG({\n"
+"  switch (x) {\n"
+"  case A:\n"
+"f();\n"
+"break;\n"
+"  // On B:\n"
+"  case B:\n"
+"g();\n"
+"break;\n"
+"  }\n"
+"});",
+format("DEBUG({\n"
+   "  switch (x) {\n"
+   "  case A:\n"
+   "f();\n"
+   "break;\n"
+   "  // On B:\n"
+   "  case B:\n"
+   "g();\n"
+   "break;\n"
+   "  }\n"
+   "});",
+   getLLVMStyle()));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"
Index: cfe/trunk/unittests/Format/FormatTestComments.cpp
===
--- cfe/trunk/unittests/Format/FormatTestComments.cpp
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp
@@ -805,6 +805,70 @@
 format("namespace {}\n   /* Test */#define A"));
 }
 
+TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
+  // Keep the current level if the comment was originally not aligned with
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Keep the current level if there is an empty line between the comment and
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Align with the preprocessor directive if the comment was originally aligned
+  // with the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  

[PATCH] D32478: [clang-format] Fix AlignOperands when BreakBeforeBinaryOperators is set

2017-07-12 Thread Francois Ferrand via Phabricator via cfe-commits
Typz updated this revision to Diff 106221.
Typz marked 3 inline comments as done.
Typz added a comment.

Rename option to AlignAfterOperator


https://reviews.llvm.org/D32478

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/Format.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -102,7 +102,7 @@
   verifyFormat("var x = a() in\n"
".aa.aa;");
   FormatStyle Style = getGoogleJSStyleWithColumns(80);
-  Style.AlignOperands = true;
+  Style.AlignOperands = FormatStyle::OAS_Align;
   verifyFormat("var x = a() in\n"
".aa.aa;",
Style);
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -2702,6 +2702,9 @@
"  > c) {\n"
"}",
Style);
+  verifyFormat("return a\n"
+   "   && bbb;",
+   Style);
   verifyFormat("return (a)\n"
"   // comment\n"
"   + b;",
@@ -2730,11 +2733,103 @@
 
   Style.ColumnLimit = 60;
   verifyFormat("zz\n"
-   "= b\n"
+   "= \n"
"  >> (aa);",
Style);
 }
 
+TEST_F(FormatTest, ExpressionIndentationStrictAlign) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+  Style.AlignOperands = FormatStyle::OAS_AlignAfterOperator;
+
+  verifyFormat("bool value = a\n"
+   "   + a\n"
+   "   + a\n"
+   "  == a\n"
+   " * b\n"
+   " + b\n"
+   "  && a\n"
+   " * a\n"
+   " > c;",
+   Style);
+  verifyFormat("if (a\n"
+   "* \n"
+   "+ aa\n"
+   "== bbb) {\n}",
+   Style);
+  verifyFormat("if (a\n"
+   "+ \n"
+   "  * aa\n"
+   "== bbb) {\n}",
+   Style);
+  verifyFormat("if (a\n"
+   "== \n"
+   "   * aa\n"
+   "   + bbb) {\n}",
+   Style);
+  verifyFormat("if () {\n"
+   "} else if (a\n"
+   "   && b // break\n"
+   "  > c) {\n"
+   "}",
+   Style);
+  verifyFormat("return a\n"
+   "&& bbb;",
+   Style);
+  verifyFormat("return (a)\n"
+   " // comment\n"
+   " + b;",
+   Style);
+  verifyFormat(
+  "int aa = aa\n"
+  "   * bbb\n"
+  "   + cc;",
+  Style);
+
+  verifyFormat("a\n"
+   "=  + ;",
+   Style);
+
+  verifyFormat("return boost::fusion::at_c<0>().second\n"
+   "== boost::fusion::at_c<1>().second;",
+   Style);
+
+  Style.ColumnLimit = 60;
+  verifyFormat("z\n"
+   "= \n"
+   "   >> 

[PATCH] D35296: [clang-format] Keep level of comment before an empty line

2017-07-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 106220.
krasimir marked 2 inline comments as done.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D35296

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -805,6 +805,70 @@
 format("namespace {}\n   /* Test */#define A"));
 }
 
+TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
+  // Keep the current level if the comment was originally not aligned with
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Keep the current level if there is an empty line between the comment and
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Align with the preprocessor directive if the comment was originally aligned
+  // with the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"/* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+}
+
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -825,12 +825,35 @@
"  case A:\n"
"f();\n"
"break;\n"
-   "  // On B:\n"
+   "// fallthrough\n"
"  case B:\n"
"g();\n"
"break;\n"
"  }\n"
"});");
+  EXPECT_EQ("DEBUG({\n"
+"  switch (x) {\n"
+"  case A:\n"
+"f();\n"
+"break;\n"
+"  // On B:\n"
+"  case B:\n"
+"g();\n"
+"break;\n"
+"  }\n"
+"});",
+format("DEBUG({\n"
+   "  switch (x) {\n"
+   "  case A:\n"
+   "f();\n"
+   "break;\n"
+   "  // On B:\n"
+   "  case B:\n"
+   "g();\n"
+   "break;\n"
+   "  }\n"
+   "});",
+   getLLVMStyle()));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1694,17 +1694,26 @@
   for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(),
   E = Lines.rend();
I != E; ++I) {
-bool CommentLine = (*I)->First;
+bool CommentLine = true;
 for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
   if (!Tok->is(tok::comment)) {
 CommentLine = false;
 break;
   }
 }
-if (NextNonCommentLine && CommentLine)
-  (*I)->Level = NextNonCommentLine->Level;
-else
+
+if (NextNonCommentLine && CommentLine) {
+  // If the comment is currently aligned with the line immediately following
+  // it, that's probably intentional and we should keep it.
+  bool AlignedWithNextLine =
+  NextNonCommentLine->First->NewlinesBefore <= 1 &&
+  NextNonCommentLine->First->OriginalColumn ==
+  

[PATCH] D31700: [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> You might want to commit this at some point ;]

I somewhat forgot this minor patch.




Comment at: clang-tidy/google/AvoidCStyleCastsCheck.cpp:139
   ")");
+  ReplaceRange = CharSourceRange::getCharRange(CastExpr->getLParenLoc(),
+   SubExpr->getLocStart());

alexfh wrote:
> Why is this only done on non-parenthesized expressions? Will `(int)  (b)` 
> turn into `static_cast  (b)` as well?
Good point, I have updated the patch to cover more cases. Please take a look 
again.


https://reviews.llvm.org/D31700



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


[PATCH] D31700: [clang-tidy] Ignore blank spaces between cast's ")" and its sub expr.

2017-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 106219.
hokein marked an inline comment as done.
hokein added a comment.
Herald added subscribers: xazax.hun, JDevlieghere.

Support more cases.


https://reviews.llvm.org/D31700

Files:
  clang-tidy/google/AvoidCStyleCastsCheck.cpp
  test/clang-tidy/google-readability-casting.cpp


Index: test/clang-tidy/google-readability-casting.cpp
===
--- test/clang-tidy/google-readability-casting.cpp
+++ test/clang-tidy/google-readability-casting.cpp
@@ -85,6 +85,22 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   // CHECK-FIXES: b1 = (const int&)b;
 
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
   Y *pB = (Y*)pX;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use 
static_cast/const_cast/reinterpret_cast [
   Y  = (Y&)*pX;
@@ -114,6 +130,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  e = e;
 
+  e = (Enum)   e;
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = e;
+
+  e = (Enum)   (e);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
+  // CHECK-FIXES: {{^}}  e = (e);
+
   static const int kZero = 0;
   (int)kZero;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
Index: clang-tidy/google/AvoidCStyleCastsCheck.cpp
===
--- clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -58,10 +58,9 @@
 
 void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult ) {
   const auto *CastExpr = Result.Nodes.getNodeAs("cast");
-  auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
-   CastExpr->getRParenLoc());
+
   // Ignore casts in macros.
-  if (ParenRange.getBegin().isMacroID() || ParenRange.getEnd().isMacroID())
+  if (CastExpr->getExprLoc().isMacroID())
 return;
 
   // Casting to void is an idiomatic way to mute "unused variable" and similar
@@ -82,6 +81,9 @@
   const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
   const QualType DestType = DestTypeAsWritten.getCanonicalType();
 
+  auto ReplaceRange = CharSourceRange::getCharRange(
+  CastExpr->getLParenLoc(), 
CastExpr->getSubExprAsWritten()->getLocStart());
+
   bool FnToFnCast =
   isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
 
@@ -92,7 +94,7 @@
 // pointer/reference types.
 if (SourceTypeAsWritten == DestTypeAsWritten) {
   diag(CastExpr->getLocStart(), "redundant cast to the same type")
-  << FixItHint::CreateRemoval(ParenRange);
+  << FixItHint::CreateRemoval(ReplaceRange);
   return;
 }
   }
@@ -136,7 +138,7 @@
  getLangOpts()),
   ")");
 }
-Diag << FixItHint::CreateReplacement(ParenRange, CastText);
+Diag << FixItHint::CreateReplacement(ReplaceRange, CastText);
   };
   auto ReplaceWithNamedCast = [&](StringRef CastType) {
 Diag << CastType;


Index: test/clang-tidy/google-readability-casting.cpp
===
--- test/clang-tidy/google-readability-casting.cpp
+++ test/clang-tidy/google-readability-casting.cpp
@@ -85,6 +85,22 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
   // CHECK-FIXES: b1 = (const int&)b;
 
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) b;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
+  b1 = (int) (b);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast {{.*}}
+  // CHECK-FIXES: b1 = static_cast(b);
+
   Y *pB = (Y*)pX;
   // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
   Y  = (Y&)*pX;
@@ -114,6 +130,14 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
   // CHECK-FIXES: {{^}}  e = e;
 
+  e = (Enum)   

[PATCH] D35296: [clang-format] Keep level of comment before an empty line

2017-07-12 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.

Some small comments, otherwise looks good.




Comment at: lib/Format/TokenAnnotator.cpp:1706
+if (NextNonCommentLine && CommentLine) {
+  bool UpdateLevel = NextNonCommentLine->First->NewlinesBefore <= 1 &&
+ NextNonCommentLine->First->OriginalColumn ==

Add a comment a long the lines of:

  // If the comment is currently aligned with the line immediately following it,
  // that's probably intentional and we should keep it.

And maybe rename s/UpdateLevel/AlignedWithNextLine/



Comment at: unittests/Format/FormatTest.cpp:855
+"  }\n"
+"});", getLLVMStyle()));
   verifyFormat("switch (a) {\n"

Please format this with clang-format.


https://reviews.llvm.org/D35296



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

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

Thank you! I think we can start to run this check on real world code bases and 
evaluate the results.




Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:41
+  void checkPreCall(const CallEvent , CheckerContext ) const;
+  void ChangeMaps(bool IsBeginFunction, CheckerContext ) const;
+  void ReportBug(const char *Msg, bool PureError, const MemRegion *Reg,

Function names should start with a lower case letter. These two could be 
private. I'd prefer another name for this function like 
`registerCtorDtorCallInState`.



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:42
+  void ChangeMaps(bool IsBeginFunction, CheckerContext ) const;
+  void ReportBug(const char *Msg, bool PureError, const MemRegion *Reg,
+ CheckerContext ) const;

Use `StringRef` instead of `const char *`.  It is more idiomatic in LLVM code. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:179
+} else {
+  const char *Msg = "Call to virtual function during construction";
+  ReportBug(Msg, false, Reg, C);

I'd omit the `Msg` local variable. After that, we do not need to use braces for 
single statement blocks.



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:210
+const MemRegion *Reg = ThiSVal.getAsRegion();
+if (IsBeginFunction) {
+  State = State->set(Reg, true);

Braces for single statement blocks. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:224
+const MemRegion *Reg = ThiSVal.getAsRegion();
+if (IsBeginFunction) {
+  State = State->set(Reg, true);

Braces for single statement blocks. 



Comment at: lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp:238
+  ExplodedNode *N;
+  if (PureError) {
+N = C.generateErrorNode();

Do not use braces for single statement blocks. 


https://reviews.llvm.org/D34275



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


[PATCH] D35306: [diagtool] Add the 'find-diagnostic-id' subcommand that converts a name of the diagnostic to its enum value

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
Herald added a subscriber: mgorny.

The new subcommand prints out the enum value of the diagnostic. This will be 
used in a utility script that invokes clang and forces it to stop when some 
specific diagnostic is emitted (see https://reviews.llvm.org/D35175 for 
discussion).

@hintonda 
My current script only deals with one specific diagnostic (i.e. the enum name). 
I was thinking that it could be extended to support diagnostic groups (i.e. -W 
options), where it would stop at any warning from that group. This extension 
will require an addition to this patch (i.e. if you supply -Wgroupname, we will 
print out a list of diagnostic ids instead of just one id that corresponds to 
the specific diagnostic). Do you think this will be useful?


Repository:
  rL LLVM

https://reviews.llvm.org/D35306

Files:
  test/Misc/find-diagnostic-id.c
  tools/diagtool/CMakeLists.txt
  tools/diagtool/FindDiagnosticID.cpp


Index: tools/diagtool/FindDiagnosticID.cpp
===
--- /dev/null
+++ tools/diagtool/FindDiagnosticID.cpp
@@ -0,0 +1,58 @@
+//===- FindDiagnosticID.cpp - diagtool tool for finding diagnostic id 
-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DiagTool.h"
+#include "DiagnosticNames.h"
+#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/CommandLine.h"
+
+DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
+ FindDiagnosticID)
+
+using namespace clang;
+using namespace diagtool;
+
+static Optional
+findDiagnostic(ArrayRef Diagnostics, StringRef Name) {
+  for (const auto  : Diagnostics) {
+StringRef DiagName = Diag.getName();
+if (DiagName == Name)
+  return Diag;
+  }
+  return None;
+}
+
+int FindDiagnosticID::run(unsigned int argc, char **argv,
+  llvm::raw_ostream ) {
+  static llvm::cl::OptionCategory FindDiagnosticIDOptions(
+  "diagtool find-diagnostic-id options");
+
+  static llvm::cl::opt DiagnosticName(
+  llvm::cl::Positional, llvm::cl::desc(""),
+  llvm::cl::Required, llvm::cl::cat(FindDiagnosticIDOptions));
+
+  std::vector Args;
+  Args.push_back("find-diagnostic-id");
+  for (const char *A : llvm::makeArrayRef(argv, argc))
+Args.push_back(A);
+
+  llvm::cl::HideUnrelatedOptions(FindDiagnosticIDOptions);
+  llvm::cl::ParseCommandLineOptions((int)Args.size(), Args.data(),
+"Diagnostic ID mapping utility");
+
+  ArrayRef AllDiagnostics = getBuiltinDiagnosticsByName();
+  Optional Diag =
+  findDiagnostic(AllDiagnostics, DiagnosticName);
+  if (!Diag) {
+llvm::errs() << "error: invalid diagnostic '" << DiagnosticName << "'\n";
+return 1;
+  }
+  OS << Diag->DiagID << "\n";
+  return 0;
+}
Index: tools/diagtool/CMakeLists.txt
===
--- tools/diagtool/CMakeLists.txt
+++ tools/diagtool/CMakeLists.txt
@@ -6,6 +6,7 @@
   diagtool_main.cpp
   DiagTool.cpp
   DiagnosticNames.cpp
+  FindDiagnosticID.cpp
   ListWarnings.cpp
   ShowEnabledWarnings.cpp
   TreeView.cpp
Index: test/Misc/find-diagnostic-id.c
===
--- /dev/null
+++ test/Misc/find-diagnostic-id.c
@@ -0,0 +1,5 @@
+// RUN: diagtool find-diagnostic-id warn_unused_variable | FileCheck %s
+// RUN: not diagtool find-diagnostic-id warn_unused_vars 2>&1 | FileCheck 
--check-prefix=ERROR %s
+
+// CHECK: {{^[0-9]+$}}
+// ERROR: error: invalid diagnostic 'warn_unused_vars'


Index: tools/diagtool/FindDiagnosticID.cpp
===
--- /dev/null
+++ tools/diagtool/FindDiagnosticID.cpp
@@ -0,0 +1,58 @@
+//===- FindDiagnosticID.cpp - diagtool tool for finding diagnostic id -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "DiagTool.h"
+#include "DiagnosticNames.h"
+#include "clang/Basic/AllDiagnostics.h"
+#include "llvm/Support/CommandLine.h"
+
+DEF_DIAGTOOL("find-diagnostic-id", "Print the id of the given diagnostic",
+ FindDiagnosticID)
+
+using namespace clang;
+using namespace diagtool;
+
+static Optional
+findDiagnostic(ArrayRef Diagnostics, StringRef Name) {
+  for (const auto  : Diagnostics) {
+StringRef DiagName = Diag.getName();
+if (DiagName == Name)
+  return Diag;
+  }
+  return None;
+}
+
+int FindDiagnosticID::run(unsigned int argc, char **argv,
+  llvm::raw_ostream ) {
+  static llvm::cl::OptionCategory 

Re: [clang-tools-extra] r303735 - Modify test so that it looks for patterns in stderr as well

2017-07-12 Thread David Blaikie via cfe-commits
Thanks all!

On Wed, Jul 12, 2017 at 7:46 AM Alexander Kornienko 
wrote:

> Done in r307661.
>
> On Mon, Jul 10, 2017 at 2:08 PM, Alexander Kornienko 
> wrote:
>
>> Benjamin has actually fixed the issue by reverting to the old behavior in 
>> r306822.
>> I'll add a test for this behavior anyway.
>>
>> On Mon, Jul 10, 2017 at 11:47 AM, Alexander Kornienko 
>> wrote:
>>
>>> Sorry, missed this thread somehow. So, the behavior itself seems
>>> incorrect. Clang tools should not be trying to find a compilation database
>>> in case the command line has a `--`, but the driver fails to parse it. It
>>> should be a hard failure. We also need a reliable test for this behavior
>>> (with a compile_commands.json being put into a test directory or generated
>>> during a test).
>>>
>>>
>>> On Tue, Jun 27, 2017 at 3:33 AM, David Blaikie 
>>> wrote:
>>>


 On Mon, Jun 26, 2017 at 5:31 AM Serge Pavlov 
 wrote:

> 2017-06-26 4:05 GMT+07:00 David Blaikie :
>
>> Ah, I see now then.
>>
>> I have a symlink from the root of my source directory pointing to the
>> compile_commands.json in my build directory.
>>
>> I have this so that the vim YouCompleteMe plugin (& any other clang
>> tools) can find it, as they usually should, for using tools with the
>> llvm/clang project...
>>
>> Sounds like this test is incompatible with using the tooling
>> infrastructure in the llvm/clang project?
>>
> Any test that relies on compilation database search can fail in such
> case. Maybe the root of the tools test could contain some special
> compile_commands.json so that the search will always end up in definite
> state?
>

 Perhaps - or maybe tools could have a parameter limiting how many
 parent directories to recurse up through? But yeah, dunno what the best
 solution would be.


>
>
>>
>> On Sun, Jun 25, 2017, 10:24 AM Serge Pavlov 
>> wrote:
>>
>>> 2017-06-25 0:52 GMT+07:00 David Blaikie :
>>>


 On Sat, Jun 24, 2017 at 10:08 AM Serge Pavlov 
 wrote:

> With CMAKE_EXPORT_COMPILE_COMMANDS the file compile_commands.json
> is created in the directory
> /tools/clang/tools/extra/test/clang-tidy/Output,
>

 I'd be really surprised if this is the case - why would
 cmake/ninja/makefiles put the compile commands for the whole LLVM
 project/build in that somewhat random subdirectory?

>>>
>>> I was wrong, these json files were not created by cmake run but
>>> appear during test run. The file created by cmake is in the build root.
>>>
>>>


> but the tests from
> /llvm/tools/clang/tools/extra/test/clang-tidy run in the
> directory /tools/clang/tools/extra/test/clang-tidy, which 
> does
> not contain json files. So the test passes successfully. Ubuntu 16.04,
> cmake 3.5.1.
>

 Ah, perhaps you found a compile_commands for one of the test cases,
 not the one generated by CMake. CMake 3.5.1 doesn't support
 CMAKE_EXPORT_COMPILE_COMMANDS.

 It was added in 3.5.2, according to the documentation:
 https://cmake.org/cmake/help/v3.5/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html


>>>
>>> It was added in 2.8.5 according to documentation (
>>> http://clang.llvm.org/docs/JSONCompilationDatabase.html#supported-systems),
>>> at least the version 3.5.1 creates compilation databases.
>>>
>>> clang-tidy tries to create compilation database from source path,
>>> looking for compile_commands.json in the directory where provided source
>>> file resides and in all its parent directories. If source tree is in a
>>> subdirectory of build tree, then compile_commands.json in the build
>>> directory would be found and the test would fail. Is it your case?
>>>
>>>
> Thanks,
> --Serge
>
> 2017-06-24 9:42 GMT+07:00 David Blaikie :
>
>> Ping (+Manuel, perhaps he's got some ideas about this, given
>> background in the tooling & compilation database work, or could 
>> point this
>> to someone who does?)
>>
>>
>> On Thu, Jun 15, 2017 at 10:40 AM David Blaikie <
>> dblai...@gmail.com> wrote:
>>
>>>
>>> https://sarcasm.github.io/notes/dev/compilation-database.html#cmake
>>>
>>> If you enable the CMAKE_EXPORT_COMPILE_COMMANDS option in cmake
>>> (& have a sufficiently recent cmake), then CMake will generate a
>>> compile_commands.json in the root of the build tree. The 

[PATCH] D34949: [refactor][rename] Use a single base class for class that finds a declaration at location and for class that searches for all occurrences of a specific declaration

2017-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.

LGTM.




Comment at: include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h:33
+: public RecursiveASTVisitor {
+  using BaseType = RecursiveASTVisitor;
+  const SourceManager 

nit: I'd add a `private` specifier for these private members, and put it after 
the `public` section.


Repository:
  rL LLVM

https://reviews.llvm.org/D34949



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


Re: [clang-tools-extra] r303735 - Modify test so that it looks for patterns in stderr as well

2017-07-12 Thread Alexander Kornienko via cfe-commits
Done in r307661.

On Mon, Jul 10, 2017 at 2:08 PM, Alexander Kornienko 
wrote:

> Benjamin has actually fixed the issue by reverting to the old behavior in 
> r306822.
> I'll add a test for this behavior anyway.
>
> On Mon, Jul 10, 2017 at 11:47 AM, Alexander Kornienko 
> wrote:
>
>> Sorry, missed this thread somehow. So, the behavior itself seems
>> incorrect. Clang tools should not be trying to find a compilation database
>> in case the command line has a `--`, but the driver fails to parse it. It
>> should be a hard failure. We also need a reliable test for this behavior
>> (with a compile_commands.json being put into a test directory or generated
>> during a test).
>>
>>
>> On Tue, Jun 27, 2017 at 3:33 AM, David Blaikie 
>> wrote:
>>
>>>
>>>
>>> On Mon, Jun 26, 2017 at 5:31 AM Serge Pavlov 
>>> wrote:
>>>
 2017-06-26 4:05 GMT+07:00 David Blaikie :

> Ah, I see now then.
>
> I have a symlink from the root of my source directory pointing to the
> compile_commands.json in my build directory.
>
> I have this so that the vim YouCompleteMe plugin (& any other clang
> tools) can find it, as they usually should, for using tools with the
> llvm/clang project...
>
> Sounds like this test is incompatible with using the tooling
> infrastructure in the llvm/clang project?
>
 Any test that relies on compilation database search can fail in such
 case. Maybe the root of the tools test could contain some special
 compile_commands.json so that the search will always end up in definite
 state?

>>>
>>> Perhaps - or maybe tools could have a parameter limiting how many parent
>>> directories to recurse up through? But yeah, dunno what the best solution
>>> would be.
>>>
>>>


>
> On Sun, Jun 25, 2017, 10:24 AM Serge Pavlov 
> wrote:
>
>> 2017-06-25 0:52 GMT+07:00 David Blaikie :
>>
>>>
>>>
>>> On Sat, Jun 24, 2017 at 10:08 AM Serge Pavlov 
>>> wrote:
>>>
 With CMAKE_EXPORT_COMPILE_COMMANDS the file compile_commands.json
 is created in the directory 
 /tools/clang/tools/extra/test/clang-tidy/Output,


>>>
>>> I'd be really surprised if this is the case - why would
>>> cmake/ninja/makefiles put the compile commands for the whole LLVM
>>> project/build in that somewhat random subdirectory?
>>>
>>
>> I was wrong, these json files were not created by cmake run but
>> appear during test run. The file created by cmake is in the build root.
>>
>>
>>>
>>>
 but the tests from 
 /llvm/tools/clang/tools/extra/test/clang-tidy
 run in the directory /tools/cl
 ang/tools/extra/test/clang-tidy, which does not contain json
 files. So the test passes successfully. Ubuntu 16.04, cmake 3.5.1.

>>>
>>> Ah, perhaps you found a compile_commands for one of the test cases,
>>> not the one generated by CMake. CMake 3.5.1 doesn't support
>>> CMAKE_EXPORT_COMPILE_COMMANDS.
>>>
>>> It was added in 3.5.2, according to the documentation:
>>> https://cmake.org/cmake/help/v3.5/variable/CM
>>> AKE_EXPORT_COMPILE_COMMANDS.html
>>>
>>>
>>
>> It was added in 2.8.5 according to documentation (
>> http://clang.llvm.org/docs/JSONCompilationDatabase.html#sup
>> ported-systems), at least the version 3.5.1 creates compilation
>> databases.
>>
>> clang-tidy tries to create compilation database from source path,
>> looking for compile_commands.json in the directory where provided source
>> file resides and in all its parent directories. If source tree is in a
>> subdirectory of build tree, then compile_commands.json in the build
>> directory would be found and the test would fail. Is it your case?
>>
>>
 Thanks,
 --Serge

 2017-06-24 9:42 GMT+07:00 David Blaikie :

> Ping (+Manuel, perhaps he's got some ideas about this, given
> background in the tooling & compilation database work, or could point 
> this
> to someone who does?)
>
>
> On Thu, Jun 15, 2017 at 10:40 AM David Blaikie 
> wrote:
>
>> https://sarcasm.github.io/notes/dev/compilation-database.htm
>> l#cmake
>>
>> If you enable the CMAKE_EXPORT_COMPILE_COMMANDS option in cmake
>> (& have a sufficiently recent cmake), then CMake will generate a
>> compile_commands.json in the root of the build tree. The test finds 
>> this &
>> fails, instead of finding no compilation database & succeeding.
>>
>> (to use this, you can then symlink from the root of the source
>> tree 

[PATCH] D35175: New option that adds the DiagID enum name and index to Diagnostic output.

2017-07-12 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

Great, thanks...


https://reviews.llvm.org/D35175



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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-07-12 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 106204.
wangxindsb added a comment.

- Change IsVirtualCall(const CallExpr *CE) to be a free static function.
- Rename some variables.
- Improve the BugReporterVisitor, enclose the declaration names in single 
quotes.
- Hoist getSValBuilder() from the if statements.
- Fix some code duplications.
- Use the CXXMemberCall instead CXXInstanceCall in the CheckPreCall.
- Remove IsVirtualCall(CE) from if statements.
- Fix the error of the visitnode() method which may throw a wrong call graph 
for the code blow.

  class Y {
  public:
virtual void foobar();
Y() {
  F f1;
  foobar();
}
  };

Previous visitnode() will issue the virtual function called from the F(); 
Current visitnode() fix this bug.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int 

[PATCH] D35175: New option that adds the DiagID enum name and index to Diagnostic output.

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

I was impatient, so I already started on a patch for diagtool. I'll post it 
soon.


https://reviews.llvm.org/D35175



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


[PATCH] D35175: New option that adds the DiagID enum name and index to Diagnostic output.

2017-07-12 Thread don hinton via Phabricator via cfe-commits
hintonda added a comment.

I'd be happy to do that if it would help.  If so, should I do it here create a 
new diff?

Perhaps we might even make sense add the ability to pass in a message and find 
the matching name/index.


https://reviews.llvm.org/D35175



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


[PATCH] D35190: __builtin_constant_p should consider the parameter of a constexpr function as constant

2017-07-12 Thread Olivier Goffart via Phabricator via cfe-commits
ogoffart added a comment.

>   What if the constexpr function is called with in a non-constexpr context, 
> e.g. with a random global variable as argument?

__builtin_constant_p will still return false in this case, contrary to gcc 
(whose behavior actually depends on the optimization level).

I think if we really want to get the exact gcc behavior, we need to mix it with 
the optimizer and generate some LLVM intrinsics. But what I was interested on 
with this patch is at least get  a closer behavior as GCC in a constexpr context


https://reviews.llvm.org/D35190



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


[PATCH] D34949: [refactor][rename] Use a single base class for class that finds a declaration at location and for class that searches for all occurrences of a specific declaration

2017-07-12 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


Repository:
  rL LLVM

https://reviews.llvm.org/D34949



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


[PATCH] D31805: [clang-tidy] Mention "add the check to release note" in add_new_check.py.

2017-07-12 Thread Haojian Wu via Phabricator via cfe-commits
hokein abandoned this revision.
hokein added a comment.

> Good idea. Implemented in r307787. No alphabetic order though. Feel free to 
> fix ;)

Looks good. Thanks!

Closing this revision.


Repository:
  rL LLVM

https://reviews.llvm.org/D31805



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


[PATCH] D33644: Add default values for function parameter chunks

2017-07-12 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a reviewer: rsmith.
klimek added a comment.

+Richard, as apparently we get the source ranges for default values of built-in 
types without the preceding "=", but for user-defined types including the 
preceding "=" - is that intentional?




Comment at: lib/Sema/SemaCodeComplete.cpp:2424
+// If we don't have '=' in front of value.
+// Lexer returns built-in types values without '=' and user-defined types 
values with it.
+return " = " + DefValue;

"The Lexer returns default-values of built-in types without '=', and 
default-value of user-defined types with it."

But apart from that: that seems like a bug in the range of the default value? 
I'm now really confused :)


https://reviews.llvm.org/D33644



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


[PATCH] D35296: [clang-format] Keep level of comment before an empty line

2017-07-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 106205.
krasimir added a comment.

- Update switch tests


https://reviews.llvm.org/D35296

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -805,6 +805,70 @@
 format("namespace {}\n   /* Test */#define A"));
 }
 
+TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
+  // Keep the current level if the comment was originally not aligned with
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Keep the current level if there is an empty line between the comment and
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Align with the preprocessor directive if the comment was originally aligned
+  // with the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"/* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+}
+
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -825,12 +825,34 @@
"  case A:\n"
"f();\n"
"break;\n"
-   "  // On B:\n"
+   "// fallthrough\n"
"  case B:\n"
"g();\n"
"break;\n"
"  }\n"
"});");
+  EXPECT_EQ("DEBUG({\n"
+"  switch (x) {\n"
+"  case A:\n"
+"f();\n"
+"break;\n"
+"  // On B:\n"
+"  case B:\n"
+"g();\n"
+"break;\n"
+"  }\n"
+"});",
+  format("DEBUG({\n"
+"  switch (x) {\n"
+"  case A:\n"
+"f();\n"
+"break;\n"
+"  // On B:\n"
+"  case B:\n"
+"g();\n"
+"break;\n"
+"  }\n"
+"});", getLLVMStyle()));
   verifyFormat("switch (a) {\n"
"case (b):\n"
"  return;\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1694,17 +1694,23 @@
   for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(),
   E = Lines.rend();
I != E; ++I) {
-bool CommentLine = (*I)->First;
+bool CommentLine = true;
 for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
   if (!Tok->is(tok::comment)) {
 CommentLine = false;
 break;
   }
 }
-if (NextNonCommentLine && CommentLine)
-  (*I)->Level = NextNonCommentLine->Level;
-else
+
+if (NextNonCommentLine && CommentLine) {
+  bool UpdateLevel = NextNonCommentLine->First->NewlinesBefore <= 1 &&
+ NextNonCommentLine->First->OriginalColumn ==
+ (*I)->First->OriginalColumn;
+  if (UpdateLevel)
+(*I)->Level = NextNonCommentLine->Level;
+} else {
   NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
+}
 
 setCommentLineLevels((*I)->Children);
   }

[PATCH] D34949: [refactor][rename] Use a single base class for class that finds a declaration at location and for class that searches for all occurrences of a specific declaration

2017-07-12 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D34949



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


[PATCH] D34512: Add preliminary Cross Translation Unit support library

2017-07-12 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Yep, I want Richard's approval for the name. I think he already expressed a 
pro-pulling-out stance.


https://reviews.llvm.org/D34512



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


[PATCH] D34512: Add preliminary Cross Translation Unit support library

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

In https://reviews.llvm.org/D34512#803724, @klimek wrote:

> Specifically, ping Richard for new top-level lib in clang.


Richard proposed pulling this out into a separate library in the first place. 
Do we need his approval for the name? Or we want him to consider if this patch 
justifies the existence of a separate library?


https://reviews.llvm.org/D34512



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


[PATCH] D35296: [clang-format] Keep level of comment before an empty line

2017-07-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 106202.
krasimir added a comment.

- Switch to original column-based detection


https://reviews.llvm.org/D35296

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestComments.cpp

Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -805,6 +805,70 @@
 format("namespace {}\n   /* Test */#define A"));
 }
 
+TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) {
+  // Keep the current level if the comment was originally not aligned with
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "  /* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Keep the current level if there is an empty line between the comment and
+  // the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"  /* comment */\n"
+"\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+
+  // Align with the preprocessor directive if the comment was originally aligned
+  // with the preprocessor directive.
+  EXPECT_EQ("void f() {\n"
+"  int i;\n"
+"/* comment */\n"
+"#ifdef A\n"
+"  int j;\n"
+"}",
+format("void f() {\n"
+   "  int i;\n"
+   "/* comment */\n"
+   "#ifdef A\n"
+   "  int j;\n"
+   "}"));
+}
+
 TEST_F(FormatTestComments, SplitsLongLinesInComments) {
   EXPECT_EQ("/* This is a long\n"
 " * comment that\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1694,17 +1694,23 @@
   for (SmallVectorImpl::reverse_iterator I = Lines.rbegin(),
   E = Lines.rend();
I != E; ++I) {
-bool CommentLine = (*I)->First;
+bool CommentLine = true;
 for (const FormatToken *Tok = (*I)->First; Tok; Tok = Tok->Next) {
   if (!Tok->is(tok::comment)) {
 CommentLine = false;
 break;
   }
 }
-if (NextNonCommentLine && CommentLine)
-  (*I)->Level = NextNonCommentLine->Level;
-else
+
+if (NextNonCommentLine && CommentLine) {
+  bool UpdateLevel = NextNonCommentLine->First->NewlinesBefore <= 1 &&
+ NextNonCommentLine->First->OriginalColumn ==
+ (*I)->First->OriginalColumn;
+  if (UpdateLevel)
+(*I)->Level = NextNonCommentLine->Level;
+} else {
   NextNonCommentLine = (*I)->First->isNot(tok::r_brace) ? (*I) : nullptr;
+}
 
 setCommentLineLevels((*I)->Children);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >