Re: [PATCH] D41271: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Yvan Roux via cfe-commits
Hi Ana

On 17 January 2018 at 23:14, Ana Pazos via Phabricator via cfe-commits
 wrote:
> apazos added a comment.
>
> Committed R32276

This commit broke ARM/AArch64 buildbots. riscv-gnutools.c test fails
on these boxes.

logs are available here:
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3932/steps/ninja%20check%202/logs/FAIL%3A%20Clang%3A%3Ariscv-gnutools.c

Cheers,
Yvan

>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D41271
>
>
>
> ___
> 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] D42229: [cmake] [libcxxabi] Don't print warning when tests are disabled.

2018-01-17 Thread Don Hinton via Phabricator via cfe-commits
hintonda created this revision.
hintonda added reviewers: compnerd, bryant, beanz.
Herald added a subscriber: mgorny.
Herald added a reviewer: EricWF.
Herald added a reviewer: EricWF.

Don't print, possibly erroneous, warning if
LIBCXXABI_INCLUDE_TESTS is false.

This patch fixes a problem introduced in r291367.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D42229

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -440,18 +440,21 @@
 # soname, etc...
 add_subdirectory(src)
 
-if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT 
LIBCXXABI_ENABLE_SHARED))
-  # We can't reasonably test the system C++ library with a static libc++abi.
-  # We either need to be able to replace libc++abi at run time (with a shared
-  # libc++abi), or we need to be able to replace the C++ runtime (with a non-
-  # standalone build).
-  message(WARNING "The libc++abi tests aren't valid when libc++abi is built "
-  "standalone (i.e. outside of llvm/projects/libcxxabi ) and "
-  "is built without a shared library.  Either build a shared "
-  "library, build libc++abi at the same time as you build "
-  "libc++, or do without testing.  No check target will be "
-  "available!")
-else()
-  add_subdirectory(test)
-  add_subdirectory(fuzz)
+if (LIBCXXABI_INCLUDE_TESTS)
+  if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
+# We can't reasonably test the system C++ library with a static
+# libc++abi.  We either need to be able to replace libc++abi at
+# run time (with a shared libc++abi), or we need to be able to
+# replace the C++ runtime (with a non- standalone build).
+message(WARNING "The libc++abi tests aren't valid when libc++abi "
+"is built standalone (i.e. outside of "
+"llvm/projects/libcxxabi ) and is built without "
+"a shared library.  Either build a shared "
+"library, build libc++abi at the same time as "
+"you build libc++, or do without testing.  No "
+"check target will be available!")
+  else()
+add_subdirectory(test)
+add_subdirectory(fuzz)
+  endif()
 endif()


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -440,18 +440,21 @@
 # soname, etc...
 add_subdirectory(src)
 
-if (NOT LIBCXXABI_INCLUDE_TESTS OR (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED))
-  # We can't reasonably test the system C++ library with a static libc++abi.
-  # We either need to be able to replace libc++abi at run time (with a shared
-  # libc++abi), or we need to be able to replace the C++ runtime (with a non-
-  # standalone build).
-  message(WARNING "The libc++abi tests aren't valid when libc++abi is built "
-  "standalone (i.e. outside of llvm/projects/libcxxabi ) and "
-  "is built without a shared library.  Either build a shared "
-  "library, build libc++abi at the same time as you build "
-  "libc++, or do without testing.  No check target will be "
-  "available!")
-else()
-  add_subdirectory(test)
-  add_subdirectory(fuzz)
+if (LIBCXXABI_INCLUDE_TESTS)
+  if (LIBCXXABI_STANDALONE_BUILD AND NOT LIBCXXABI_ENABLE_SHARED)
+# We can't reasonably test the system C++ library with a static
+# libc++abi.  We either need to be able to replace libc++abi at
+# run time (with a shared libc++abi), or we need to be able to
+# replace the C++ runtime (with a non- standalone build).
+message(WARNING "The libc++abi tests aren't valid when libc++abi "
+"is built standalone (i.e. outside of "
+"llvm/projects/libcxxabi ) and is built without "
+"a shared library.  Either build a shared "
+"library, build libc++abi at the same time as "
+"you build libc++, or do without testing.  No "
+"check target will be available!")
+  else()
+add_subdirectory(test)
+add_subdirectory(fuzz)
+  endif()
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322816 - Revert rC322769: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Hiroshi Inoue via cfe-commits
Author: inouehrs
Date: Wed Jan 17 22:13:25 2018
New Revision: 322816

URL: http://llvm.org/viewvc/llvm-project?rev=322816=rev
Log:
Revert rC322769: [RISCV] Propagate -mabi and -march values to GNU assembler.

Temporarily revert rC322769 due to buildbot failurs.


Removed:

cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
cfe/trunk/test/Driver/riscv-gnutools.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=322816=322815=322816=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Jan 17 22:13:25 2018
@@ -629,18 +629,6 @@ void tools::gnutools::Assembler::Constru
   ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple(;
 break;
   }
-  case llvm::Triple::riscv32:
-  case llvm::Triple::riscv64: {
-StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
-CmdArgs.push_back("-mabi");
-CmdArgs.push_back(ABIName.data());
-if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
-  StringRef MArch = A->getValue();
-  CmdArgs.push_back("-march");
-  CmdArgs.push_back(MArch.data());
-}
-break;
-  }
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");

Removed: 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as?rev=322815=auto
==
--- 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
 (original)
+++ 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
 (removed)
@@ -1 +0,0 @@
-#!/bin/true

Removed: cfe/trunk/test/Driver/riscv-gnutools.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/riscv-gnutools.c?rev=322815=auto
==
--- cfe/trunk/test/Driver/riscv-gnutools.c (original)
+++ cfe/trunk/test/Driver/riscv-gnutools.c (removed)
@@ -1,14 +0,0 @@
-// Check gnutools are invoked with propagated values for -mabi and -march.
-
-// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
-// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
-// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
-// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32 %s
-// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
-// RUN: -march=rv32g --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
-// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
-// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32-MARCH-G %s
-
-// MABI-ILP32: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32"
-// MABI-ILP32-MARCH-G: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32" "-march" "rv32g"
-


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


r322813 - Fix Scope::dump()

2018-01-17 Thread Richard Trieu via cfe-commits
Author: rtrieu
Date: Wed Jan 17 20:28:56 2018
New Revision: 322813

URL: http://llvm.org/viewvc/llvm-project?rev=322813=rev
Log:
Fix Scope::dump()

The dump function for Scope only has 20 out of the 24 flags.  Since it looped
until no flags were left, having an unknown flag lead to an infinite loop.
That loop has been changed to a single pass for each flag, plus an assert to
alert if new flags are added.

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

Modified: cfe/trunk/lib/Sema/Scope.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Scope.cpp?rev=322813=322812=322813=diff
==
--- cfe/trunk/lib/Sema/Scope.cpp (original)
+++ cfe/trunk/lib/Sema/Scope.cpp Wed Jan 17 20:28:56 2018
@@ -143,72 +143,43 @@ void Scope::dumpImpl(raw_ostream ) co
   if (HasFlags)
 OS << "Flags: ";
 
-  while (Flags) {
-if (Flags & FnScope) {
-  OS << "FnScope";
-  Flags &= ~FnScope;
-} else if (Flags & BreakScope) {
-  OS << "BreakScope";
-  Flags &= ~BreakScope;
-} else if (Flags & ContinueScope) {
-  OS << "ContinueScope";
-  Flags &= ~ContinueScope;
-} else if (Flags & DeclScope) {
-  OS << "DeclScope";
-  Flags &= ~DeclScope;
-} else if (Flags & ControlScope) {
-  OS << "ControlScope";
-  Flags &= ~ControlScope;
-} else if (Flags & ClassScope) {
-  OS << "ClassScope";
-  Flags &= ~ClassScope;
-} else if (Flags & BlockScope) {
-  OS << "BlockScope";
-  Flags &= ~BlockScope;
-} else if (Flags & TemplateParamScope) {
-  OS << "TemplateParamScope";
-  Flags &= ~TemplateParamScope;
-} else if (Flags & FunctionPrototypeScope) {
-  OS << "FunctionPrototypeScope";
-  Flags &= ~FunctionPrototypeScope;
-} else if (Flags & FunctionDeclarationScope) {
-  OS << "FunctionDeclarationScope";
-  Flags &= ~FunctionDeclarationScope;
-} else if (Flags & AtCatchScope) {
-  OS << "AtCatchScope";
-  Flags &= ~AtCatchScope;
-} else if (Flags & ObjCMethodScope) {
-  OS << "ObjCMethodScope";
-  Flags &= ~ObjCMethodScope;
-} else if (Flags & SwitchScope) {
-  OS << "SwitchScope";
-  Flags &= ~SwitchScope;
-} else if (Flags & TryScope) {
-  OS << "TryScope";
-  Flags &= ~TryScope;
-} else if (Flags & FnTryCatchScope) {
-  OS << "FnTryCatchScope";
-  Flags &= ~FnTryCatchScope;
-} else if (Flags & SEHTryScope) {
-  OS << "SEHTryScope";
-  Flags &= ~SEHTryScope;
-} else if (Flags & SEHExceptScope) {
-  OS << "SEHExceptScope";
-  Flags &= ~SEHExceptScope;
-} else if (Flags & OpenMPDirectiveScope) {
-  OS << "OpenMPDirectiveScope";
-  Flags &= ~OpenMPDirectiveScope;
-} else if (Flags & OpenMPLoopDirectiveScope) {
-  OS << "OpenMPLoopDirectiveScope";
-  Flags &= ~OpenMPLoopDirectiveScope;
-} else if (Flags & OpenMPSimdDirectiveScope) {
-  OS << "OpenMPSimdDirectiveScope";
-  Flags &= ~OpenMPSimdDirectiveScope;
-}
+  std::pair FlagInfo[] = {
+  {FnScope, "FnScope"},
+  {BreakScope, "BreakScope"},
+  {ContinueScope, "ContinueScope"},
+  {DeclScope, "DeclScope"},
+  {ControlScope, "ControlScope"},
+  {ClassScope, "ClassScope"},
+  {BlockScope, "BlockScope"},
+  {TemplateParamScope, "TemplateParamScope"},
+  {FunctionPrototypeScope, "FunctionPrototypeScope"},
+  {FunctionDeclarationScope, "FunctionDeclarationScope"},
+  {AtCatchScope, "AtCatchScope"},
+  {ObjCMethodScope, "ObjCMethodScope"},
+  {SwitchScope, "SwitchScope"},
+  {TryScope, "TryScope"},
+  {FnTryCatchScope, "FnTryCatchScope"},
+  {OpenMPDirectiveScope, "OpenMPDirectiveScope"},
+  {OpenMPLoopDirectiveScope, "OpenMPLoopDirectiveScope"},
+  {OpenMPSimdDirectiveScope, "OpenMPSimdDirectiveScope"},
+  {EnumScope, "EnumScope"},
+  {SEHTryScope, "SEHTryScope"},
+  {SEHExceptScope, "SEHExceptScope"},
+  {SEHFilterScope, "SEHFilterScope"},
+  {CompoundStmtScope, "CompoundStmtScope"},
+  {ClassInheritanceScope, "ClassInheritanceScope"}};
 
-if (Flags)
-  OS << " | ";
+  for (auto Info : FlagInfo) {
+if (Flags & Info.first) {
+  OS << Info.second;
+  Flags &= ~Info.first;
+  if (Flags)
+OS << " | ";
+}
   }
+
+  assert(Flags == 0 && "Unknown scope flags");
+
   if (HasFlags)
 OS << '\n';
 


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


[PATCH] D42227: [Refactor] Use enum instead of magic number in handleX86ForceAlignArgPointerAttr, NFC

2018-01-17 Thread Hongbin Zheng via Phabricator via cfe-commits
etherzhhb created this revision.
etherzhhb added reviewers: aaron.ballman, echristo.
Herald added a subscriber: cfe-commits.

Simple change to use Use enum instead of magic number in 
handleX86ForceAlignArgPointerAttr. No functional change


Repository:
  rC Clang

https://reviews.llvm.org/D42227

Files:
  lib/Sema/SemaDeclAttr.cpp


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5554,7 +5554,7 @@
   // Attribute can only be applied to function types.
   if (!isa(D)) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << /* function */0;
+  << Attr.getName() << ExpectedFunction;
 return;
   }
 


Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -5554,7 +5554,7 @@
   // Attribute can only be applied to function types.
   if (!isa(D)) {
 S.Diag(Attr.getLoc(), diag::warn_attribute_wrong_decl_type)
-  << Attr.getName() << /* function */0;
+  << Attr.getName() << ExpectedFunction;
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [libcxx] a simple comment fix in include/list

2018-01-17 Thread Qian Yun via cfe-commits
Hello all,

This is a simple (and my first) patch that fixes a comment
in include/list.

Qian Yun

--- a/include/list
+++ b/include/list
@@ -1129,9 +1129,9 @@
 __l->__next_->__prev_ = __l;
 base::__end_.__next_ = __f;
 }

-// Link in nodes [__f, __l] at the front of the list
+// Link in nodes [__f, __l] at the back of the list
 template 
 inline
 void
 list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
diff --git a/include/list b/include/list
index 32e9a27bd..6456ad4f9 100644
--- a/include/list
+++ b/include/list
@@ -1129,9 +1129,9 @@
 __l->__next_->__prev_ = __l;
 base::__end_.__next_ = __f;
 }
 
-// Link in nodes [__f, __l] at the front of the list
+// Link in nodes [__f, __l] at the back of the list
 template 
 inline
 void
 list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r322810 - Fix most GCC test failures.

2018-01-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jan 17 19:41:06 2018
New Revision: 322810

URL: http://llvm.org/viewvc/llvm-project?rev=322810=rev
Log:
Fix most GCC test failures.

This patch fixes almost all currently failing tests when
using GCC ToT.

The specific changes are:

(A) Workaround gcc.gnu.org/PR83921 which rejects variables w/o initializers
in constexpr contexts -- even when the variable is an empty class. This
bug has been worked around at all callsites by adding an initializer.
Additionally a new test, constexpr_init.pass.cpp, has been added to
test that Clang doesn't suffer from these bugs.

(B) Fix streambuf.assign/swap.pass.cpp. This test was never actually
calling the swap method as intended. In fact, the swap function it
intended to call was ill-formed when instantiated. GCC diagnosed
this ill-formedness w/o needing an instantiation.

(C) size_delete11.pass.cpp was fixed by adding c++2a to the list of
unsupported dialects.

Added:

libcxx/trunk/test/std/utilities/function.objects/comparisons/constexpr_init.pass.cpp
Modified:

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp

libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp

libcxx/trunk/test/std/input.output/stream.buffers/streambuf/streambuf.protected/streambuf.assign/swap.pass.cpp

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.single/sized_delete11.pass.cpp

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp?rev=322810=322809=322810=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.end/find_end_pred.pass.cpp
 Wed Jan 17 19:41:06 2018
@@ -30,14 +30,14 @@ struct count_equal
 };
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_constexpr() {
+constexpr bool test_constexpr() {
 int ia[] = {0, 1, 2};
 int ib[] = {4, 5, 6};
 int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 0, 1, 2, 3, 0, 1, 2, 0, 1, 0};
 typedef forward_iterator   FI;
 typedef bidirectional_iterator BI;
 typedef random_access_iterator RI;
-std::equal_to eq;
+std::equal_to eq{};
 return(std::find_end(FI(std::begin(ic)), FI(std::end(ic)), 
FI(std::begin(ia)), FI(std::end(ia)), eq) == FI(ic+15))
&& (std::find_end(FI(std::begin(ic)), FI(std::end(ic)), 
FI(std::begin(ib)), FI(std::end(ib)), eq) == FI(std::end(ic)))
&& (std::find_end(BI(std::begin(ic)), BI(std::end(ic)), 
BI(std::begin(ia)), BI(std::end(ia)), eq) == BI(ic+15))

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp?rev=322810=322809=322810=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.find.first.of/find_first_of_pred.pass.cpp
 Wed Jan 17 19:41:06 2018
@@ -23,15 +23,14 @@
 #include "test_iterators.h"
 
 #if TEST_STD_VER > 17
-TEST_CONSTEXPR bool test_constexpr() {
+constexpr bool test_constexpr() {
 int ia[] = {1, 2, 3};
 int ib[] = {7, 8, 9};
 int ic[] = {0, 1, 2, 3, 4, 5, 0, 1, 2, 3};
 typedef forward_iterator   FI;
 typedef bidirectional_iterator BI;
 typedef random_access_iterator RI;
-std::equal_to eq;
-
+std::equal_to eq{};
 return(std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), 
FI(std::begin(ia)), FI(std::end(ia)), eq) == FI(ic+1))
&& (std::find_first_of(FI(std::begin(ic)), FI(std::end(ic)), 
FI(std::begin(ib)), FI(std::end(ib)), eq) == FI(std::end(ic)))
&& (std::find_first_of(BI(std::begin(ic)), BI(std::end(ic)), 
BI(std::begin(ia)), BI(std::end(ia)), eq) == BI(ic+1))

Modified: 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp?rev=322810=322809=322810=diff
==
--- 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/algorithms/alg.nonmodifying/alg.is_permutation/is_permutation_pred.pass.cpp
 Wed Jan 17 19:41:06 

[PATCH] D41318: Start setting dso_local in clang

2018-01-17 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola updated this revision to Diff 130351.
espindola added a comment.
Herald added subscribers: niosHD, sabuasal, apazos, jordy.potman.lists, 
simoncook, johnrusso, rbar, asb.

All tests have been updated.

A few missing cases in c++ codegen are handled.
We now use CodeGenOpts.RelocationModel, which is the same value that llvm uses. 
This also has the advantage that clang_cc1 default to pic, so there is a lot 
less tests to update.

Sorry for the noise, but sending for review again since there is more code.


https://reviews.llvm.org/D41318

Files:
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGVTT.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/dso-local-executable.c
  clang/test/CodeGen/dso-local-executable.cpp
  clang/test/CodeGen/mbackchain-2.c
  clang/test/CodeGen/mbackchain-3.c
  clang/test/CodeGen/mips-vector-return.c
  clang/test/CodeGen/split-stacks.c
  clang/test/CodeGenCXX/debug-info-static-member.cpp
  clang/test/CodeGenCXX/debug-info-template.cpp
  clang/test/CodeGenCXX/float16-declarations.cpp
  clang/test/CodeGenCXX/split-stacks.cpp
  clang/test/Driver/lanai-unknown-unknown.cpp
  clang/test/Driver/le32-unknown-nacl.cpp
  clang/test/Driver/le64-unknown-unknown.cpp
  clang/test/Driver/riscv32-toolchain.c
  clang/test/Driver/riscv64-toolchain.c
  clang/test/Frontend/ast-codegen.c

Index: clang/test/Frontend/ast-codegen.c
===
--- clang/test/Frontend/ast-codegen.c
+++ clang/test/Frontend/ast-codegen.c
@@ -5,9 +5,9 @@
 // CHECK: module asm "foo"
 __asm__("foo");
 
-// CHECK: @g0 = common global i32 0, align 4
+// CHECK: @g0 = common dso_local global i32 0, align 4
 int g0;
 
-// CHECK: define i32 @f0()
+// CHECK: define dso_local i32 @f0()
 int f0() {
 }
Index: clang/test/Driver/riscv64-toolchain.c
===
--- clang/test/Driver/riscv64-toolchain.c
+++ clang/test/Driver/riscv64-toolchain.c
@@ -10,82 +10,82 @@
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
 typedef __WCHAR_TYPE__ wchar_t;
 
-// CHECK: @align_c = global i32 1
+// CHECK: @align_c = dso_local global i32 1
 int align_c = __alignof(char);
 
-// CHECK: @align_s = global i32 2
+// CHECK: @align_s = dso_local global i32 2
 int align_s = __alignof(short);
 
-// CHECK: @align_i = global i32 4
+// CHECK: @align_i = dso_local global i32 4
 int align_i = __alignof(int);
 
-// CHECK: @align_wc = global i32 4
+// CHECK: @align_wc = dso_local global i32 4
 int align_wc = __alignof(wchar_t);
 
-// CHECK: @align_l = global i32 8
+// CHECK: @align_l = dso_local global i32 8
 int align_l = __alignof(long);
 
-// CHECK: @align_ll = global i32 8
+// CHECK: @align_ll = dso_local global i32 8
 int align_ll = __alignof(long long);
 
-// CHECK: @align_p = global i32 8
+// CHECK: @align_p = dso_local global i32 8
 int align_p = __alignof(void*);
 
-// CHECK: @align_f = global i32 4
+// CHECK: @align_f = dso_local global i32 4
 int align_f = __alignof(float);
 
-// CHECK: @align_d = global i32 8
+// CHECK: @align_d = dso_local global i32 8
 int align_d = __alignof(double);
 
-// CHECK: @align_ld = global i32 16
+// CHECK: @align_ld = dso_local global i32 16
 int align_ld = __alignof(long double);
 
-// CHECK: @align_vl = global i32 8
+// CHECK: @align_vl = dso_local global i32 8
 int align_vl = __alignof(va_list);
 
 // Check types
 
-// CHECK: define zeroext i8 @check_char()
+// CHECK: define dso_local zeroext i8 @check_char()
 char check_char() { return 0; }
 
-// CHECK: define signext i16 @check_short()
+// CHECK: define dso_local signext i16 @check_short()
 short check_short() { return 0; }
 
-// CHECK: define signext i32 @check_int()
+// CHECK: define dso_local signext i32 @check_int()
 int check_int() { return 0; }
 
-// CHECK: define signext i32 @check_wchar_t()
+// CHECK: define dso_local signext i32 @check_wchar_t()
 int check_wchar_t() { return 0; }
 
-// CHECK: define i64 @check_long()
+// CHECK: define dso_local i64 @check_long()
 long check_long() { return 0; }
 
-// CHECK: define i64 @check_longlong()
+// CHECK: define dso_local i64 @check_longlong()
 long long check_longlong() { return 0; }
 
-// CHECK: define zeroext i8 @check_uchar()
+// CHECK: define dso_local zeroext i8 @check_uchar()
 unsigned char check_uchar() { return 0; }
 
-// CHECK: define zeroext i16 @check_ushort()
+// CHECK: define dso_local zeroext i16 @check_ushort()
 unsigned short check_ushort() { return 0; }
 
-// CHECK: define signext i32 @check_uint()
+// CHECK: define dso_local signext i32 @check_uint()
 unsigned int check_uint() { return 0; }
 
-// CHECK: define i64 @check_ulong()
+// CHECK: define dso_local i64 @check_ulong()
 unsigned long check_ulong() { return 0; }
 
-// CHECK: define i64 @check_ulonglong()
+// CHECK: define dso_local i64 @check_ulonglong()
 unsigned long long check_ulonglong() { return 0; }
 
-// CHECK: 

r322809 - [analyzer] a few helper methods for getting and comparing symbolic values

2018-01-17 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Jan 17 19:18:36 2018
New Revision: 322809

URL: http://llvm.org/viewvc/llvm-project?rev=322809=rev
Log:
[analyzer] a few helper methods for getting and comparing symbolic values

API calls should express intent, and that's a motivation behind this patch.

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

Modified:

cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SValBuilder.cpp

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h?rev=322809=322808=322809=diff
==
--- 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
(original)
+++ 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h 
Wed Jan 17 19:18:36 2018
@@ -37,6 +37,12 @@ public:
   /// Construct a ConstraintVal indicating the constraint is underconstrained.
   ConditionTruthVal() {}
 
+  /// \return Stored value, assuming that the value is known.
+  /// Crashes otherwise.
+  bool getValue() const {
+return *Val;
+  }
+
   /// Return true if the constraint is perfectly constrained to 'true'.
   bool isConstrainedTrue() const {
 return Val.hasValue() && Val.getValue();

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h?rev=322809=322808=322809=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h 
Wed Jan 17 19:18:36 2018
@@ -212,10 +212,17 @@ public:
   assumeInclusiveRange(DefinedOrUnknownSVal Val, const llvm::APSInt ,
const llvm::APSInt ) const;
 
+  /// \brief Check if the given SVal is not constrained to zero and is not
+  ///a zero constant.
+  ConditionTruthVal isNonNull(SVal V) const;
+
   /// \brief Check if the given SVal is constrained to zero or is a zero
   ///constant.
   ConditionTruthVal isNull(SVal V) const;
 
+  /// \return Whether values \p Lhs and \p Rhs are equal.
+  ConditionTruthVal areEqual(SVal Lhs, SVal Rhs) const;
+
   /// Utility method for getting regions.
   const VarRegion* getRegion(const VarDecl *D, const LocationContext *LC) 
const;
 

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h?rev=322809=322808=322809=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h Wed 
Jan 17 19:18:36 2018
@@ -29,6 +29,8 @@ class CXXBoolLiteralExpr;
 
 namespace ento {
 
+class ConditionTruthVal;
+
 class SValBuilder {
   virtual void anchor();
 protected:
@@ -124,7 +126,12 @@ public:
 
   SVal evalBinOp(ProgramStateRef state, BinaryOperator::Opcode op,
  SVal lhs, SVal rhs, QualType type);
-  
+
+  /// \return Whether values in \p lhs and \p rhs are equal at \p state.
+  ConditionTruthVal areEqual(ProgramStateRef state, SVal lhs, SVal rhs);
+
+  SVal evalEQ(ProgramStateRef state, SVal lhs, SVal rhs);
+
   DefinedOrUnknownSVal evalEQ(ProgramStateRef state, DefinedOrUnknownSVal lhs,
   DefinedOrUnknownSVal rhs);
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=322809=322808=322809=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed Jan 17 19:18:36 2018
@@ -354,6 +354,17 @@ ProgramStateRef ProgramState::assumeInBo
   return CM.assume(this, inBound.castAs(), Assumption);
 }
 
+ConditionTruthVal ProgramState::isNonNull(SVal V) const {
+  ConditionTruthVal IsNull = isNull(V);
+  if (IsNull.isUnderconstrained())
+return IsNull;
+  return ConditionTruthVal(!IsNull.getValue());
+}
+
+ConditionTruthVal ProgramState::areEqual(SVal Lhs, SVal Rhs) const {
+  return stateMgr->getSValBuilder().areEqual(this, Lhs, Rhs);
+}
+
 ConditionTruthVal ProgramState::isNull(SVal V) const {
   if (V.isZeroConstant())
 return true;

[PATCH] D37189: Fix an assertion failure that occured when custom 'operator new[]' return non-ElementRegion and 'c++-allocator-inlining' sets true.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

That's the "Add Action..." list-box above the comment box.


Repository:
  rC Clang

https://reviews.llvm.org/D37189



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


[PATCH] D37189: Fix an assertion failure that occured when custom 'operator new[]' return non-ElementRegion and 'c++-allocator-inlining' sets true.

2018-01-17 Thread Henry Wong via Phabricator via cfe-commits
MTC added a comment.

In https://reviews.llvm.org/D37189#979795, @NoQ wrote:

> Oh well, i guess i covered this in my recent patches anyway (esp. 
> r322787/https://reviews.llvm.org/D41406). Sorry, i just fixed everything 
> differently and it became unclear how to integrate your patch into the whole 
> thing.


Hi NoQ, that's all right, I'm totally fine with it :). And I don’t know how to 
abandon this patch, if you have the authority, please help me to abandon it, 
thank you!


Repository:
  rC Clang

https://reviews.llvm.org/D37189



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


r322808 - Update for llvm change.

2018-01-17 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Wed Jan 17 18:08:38 2018
New Revision: 322808

URL: http://llvm.org/viewvc/llvm-project?rev=322808=rev
Log:
Update for llvm change.

Modified:
cfe/trunk/test/OpenMP/target_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_codegen_registration.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_codegen_registration.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_simd_codegen_registration.cpp

Modified: cfe/trunk/test/OpenMP/target_codegen_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_codegen_registration.cpp?rev=322808=322807=322808=diff
==
--- cfe/trunk/test/OpenMP/target_codegen_registration.cpp (original)
+++ cfe/trunk/test/OpenMP/target_codegen_registration.cpp Wed Jan 17 18:08:38 
2018
@@ -393,7 +393,7 @@ struct ST {
 //CHECK: ret void
 //CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
 
-//CHECK: define linkonce dso_local hidden void @[[REGFN]](i8*)
+//CHECK: define linkonce hidden void @[[REGFN]](i8*)
 //CHECK-SAME: comdat {
 //CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
 //CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),

Modified: cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp?rev=322808=322807=322808=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_codegen_registration.cpp Wed Jan 17 
18:08:38 2018
@@ -393,7 +393,7 @@ struct ST {
 //CHECK: ret void
 //CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
 
-//CHECK: define linkonce dso_local hidden void @[[REGFN]](i8*)
+//CHECK: define linkonce hidden void @[[REGFN]](i8*)
 //CHECK-SAME: comdat {
 //CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
 //CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),

Modified: cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp?rev=322808=322807=322808=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp 
(original)
+++ cfe/trunk/test/OpenMP/target_parallel_for_codegen_registration.cpp Wed Jan 
17 18:08:38 2018
@@ -402,7 +402,7 @@ struct ST {
 //CHECK: ret void
 //CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
 
-//CHECK: define linkonce dso_local hidden void @[[REGFN]](i8*)
+//CHECK: define linkonce hidden void @[[REGFN]](i8*)
 //CHECK-SAME: comdat {
 //CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
 //CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),

Modified: 
cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp?rev=322808=322807=322808=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp 
(original)
+++ cfe/trunk/test/OpenMP/target_parallel_for_simd_codegen_registration.cpp Wed 
Jan 17 18:08:38 2018
@@ -402,7 +402,7 @@ struct ST {
 //CHECK: ret void
 //CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
 
-//CHECK: define linkonce dso_local hidden void @[[REGFN]](i8*)
+//CHECK: define linkonce hidden void @[[REGFN]](i8*)
 //CHECK-SAME: comdat {
 //CHECK: call i32 @__tgt_register_lib([[DSCTY]]* [[DESC]])
 //CHECK: call i32 @__cxa_atexit(void (i8*)* @[[UNREGFN]], i8* bitcast 
([[DSCTY]]* [[DESC]] to i8*),

Modified: cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp?rev=322808=322807=322808=diff
==
--- cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp (original)
+++ cfe/trunk/test/OpenMP/target_simd_codegen_registration.cpp Wed Jan 17 
18:08:38 2018
@@ -402,7 +402,7 @@ struct ST {
 //CHECK: ret void
 //CHECK: declare i32 @__tgt_unregister_lib([[DSCTY]]*)
 
-//CHECK: define 

[PATCH] D37189: Fix an assertion failure that occured when custom 'operator new[]' return non-ElementRegion and 'c++-allocator-inlining' sets true.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Oh well, i guess i covered this in my recent patches anyway (esp. 
r322787/https://reviews.llvm.org/D41406). Sorry, i just fixed everything 
differently and it became unclear how to integrate your patch into the whole 
thing.


Repository:
  rC Clang

https://reviews.llvm.org/D37189



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


[PATCH] D36915: [Sema] Diagnose local variables and parameters captured by lambda and block expressions in a default argument

2018-01-17 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Please take a look at 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0588r1.html, which 
respecifies the rules for lambda capture and its interaction with default 
arguments, and has been voted into the C++ working paper as a defect report 
resolution. The approach there is to use a purely syntactic, scope-based 
mechanism to detect problems such as this. (In dependent contexts, we can track 
on the `DeclRefExpr` whether the name is odr-usable, in case we can't tell 
whether it's odr-used from the template definition alone.)




Comment at: include/clang/Sema/Sema.h:1062
+
+  const DeclContext *ParentOfDefaultArg = nullptr;
+

There are lots of cases where we switch context in the middle of handling an 
expression, for instance to instantiate a template (or even *parse* a template 
in MSVC-compatible delayed template parsing mode). It's not reasonable to add a 
new form of state that all those places will need to save and restore 
themselves.

Please consider whether this would make sense as a member of the 
`ExpressionEvaluationContextRecord` or similar.



Comment at: lib/Sema/SemaExpr.cpp:4520-4541
+  // Add mappings for instantiated parameters appearing before Param. This
+  // is needed to instantiate default argument expressions referencing
+  // other parameters in unevaluated contexts.
+  if (FunctionDecl *Pattern = FD->getTemplateInstantiationPattern()) {
+auto I = FD->param_begin();
+for (const auto *PVD : Pattern->parameters()) {
+  if (*I == Param)

Use `addInstantiatedParametersToScope` for this.

This bugfix looks to be independent of the fix for lambdas; can you factor it 
out into a separate patch?


https://reviews.llvm.org/D36915



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


[PATCH] D42106: [analyzer] Remove the useless method declararion 'BugReporter::RemoveUnneededCalls()'.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322804: [analyzer] NFC: Remove unused method - 
BugReporter::RemoveUnneededCalls(). (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42106

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -470,8 +470,6 @@
 return true;
   }
 
-  bool RemoveUnneededCalls(PathPieces , BugReport *R);
-
   void Register(BugType *BT);
 
   /// \brief Add the given report to the set of reports tracked by BugReporter.


Index: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
@@ -470,8 +470,6 @@
 return true;
   }
 
-  bool RemoveUnneededCalls(PathPieces , BugReport *R);
-
   void Register(BugType *BT);
 
   /// \brief Add the given report to the set of reports tracked by BugReporter.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322804 - [analyzer] NFC: Remove unused method - BugReporter::RemoveUnneededCalls().

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 17:40:31 2018
New Revision: 322804

URL: http://llvm.org/viewvc/llvm-project?rev=322804=rev
Log:
[analyzer] NFC: Remove unused method - BugReporter::RemoveUnneededCalls().

Patch by Henry Wong!

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h?rev=322804=322803=322804=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Wed 
Jan 17 17:40:31 2018
@@ -470,8 +470,6 @@ public:
 return true;
   }
 
-  bool RemoveUnneededCalls(PathPieces , BugReport *R);
-
   void Register(BugType *BT);
 
   /// \brief Add the given report to the set of reports tracked by BugReporter.


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


[PATCH] D42221: [analyzer] NFC: See if existing C++ tests work with custom operator new().

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.
NoQ added a dependency: D42219: [analyzer] Enable c++-allocator-inlining by 
default?.

In order to provide more test coverage for inlined `operator new()`, i propose 
we add more run-lines to existing test cases, which would trigger our fake 
header to provide a body for `operator new()`. Most of the code should still 
behave reasonably. When behavior intentionally changes, `#if`s are provided.


Repository:
  rC Clang

https://reviews.llvm.org/D42221

Files:
  test/Analysis/Inputs/system-header-simulator-cxx.h
  test/Analysis/MismatchedDeallocator-checker-test.mm
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/NewDelete-intersections.mm
  test/Analysis/ctor.mm
  test/Analysis/diagnostics/implicit-cxx-std-suppression.cpp
  test/Analysis/initializer.cpp
  test/Analysis/inlining/containers.cpp
  test/Analysis/malloc.cpp
  test/Analysis/new.cpp
  test/Analysis/uninit-const.cpp

Index: test/Analysis/uninit-const.cpp
===
--- test/Analysis/uninit-const.cpp
+++ test/Analysis/uninit-const.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,core,alpha.core.CallAndMessageUnInitRefArg -analyzer-output=text -DTEST_INLINABLE_ALLOCATORS -verify %s
 // Passing uninitialized const data to unknown function
 
 #include "Inputs/system-header-simulator-cxx.h"
Index: test/Analysis/new.cpp
===
--- test/Analysis/new.cpp
+++ test/Analysis/new.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -std=c++11 -DTEST_INLINABLE_ALLOCATORS -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
 void clang_analyzer_eval(bool);
Index: test/Analysis/malloc.cpp
===
--- test/Analysis/malloc.cpp
+++ test/Analysis/malloc.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -verify %s
 // RUN: %clang_analyze_cc1 -triple i386-unknown-linux-gnu -w -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -verify %s
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -triple i386-unknown-linux-gnu -w -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -DTEST_INLINABLE_ALLOCATORS -verify %s
 
 #include "Inputs/system-header-simulator-cxx.h"
 
Index: test/Analysis/inlining/containers.cpp
===
--- test/Analysis/inlining/containers.cpp
+++ test/Analysis/inlining/containers.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors -analyzer-config c++-container-inlining=false -verify %s
 // RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors -analyzer-config c++-container-inlining=true -DINLINE=1 -verify %s
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors -analyzer-config c++-container-inlining=false -DTEST_INLINABLE_ALLOCATORS -verify %s
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-config c++-inlining=destructors -analyzer-config c++-container-inlining=true -DTEST_INLINABLE_ALLOCATORS -DINLINE=1 -verify %s
 
 #ifndef HEADER
 
Index: test/Analysis/initializer.cpp
===
--- test/Analysis/initializer.cpp
+++ test/Analysis/initializer.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config c++-inlining=constructors -std=c++11 -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config c++-inlining=constructors -std=c++17 -DCPLUSPLUS17 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config 

[PATCH] D42192: [analyzer] Assume that the allocated value is non-null before construction, not after.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 130335.
NoQ added a comment.

Use `auto`.


https://reviews.llvm.org/D42192

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-null-throw.cpp
  test/Analysis/new-ctor-null.cpp

Index: test/Analysis/new-ctor-null.cpp
===
--- test/Analysis/new-ctor-null.cpp
+++ test/Analysis/new-ctor-null.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 typedef __typeof__(sizeof(int)) size_t;
 
@@ -13,11 +14,23 @@
 
 struct S {
   int x;
-  S() : x(1) {}
+  S() : x(1) {
+// FIXME: Constructor should not be called with null this, even if it was
+// returned by operator new().
+clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
+  }
   ~S() {}
 };
 
 void testArrays() {
   S *s = new S[10]; // no-crash
   s[0].x = 2; // expected-warning{{Dereference of null pointer}}
 }
+
+int global;
+void testInvalidationOnConstructionIntoNull() {
+  global = 0;
+  S *s = new S();
+  // FIXME: Should be FALSE - we should not invalidate globals.
+  clang_analyzer_eval(global); // expected-warning{{UNKNOWN}}
+}
Index: test/Analysis/new-ctor-null-throw.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-null-throw.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+
+// These are ill-formed. One cannot return nullptr from a throwing version of an
+// operator new.
+void *operator new(size_t size) {
+  return nullptr;
+}
+void *operator new[](size_t size) {
+  return nullptr;
+}
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void testArrays() {
+  S *s = new S[10]; // no-crash
+  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+}
Index: test/Analysis/new-ctor-conservative.cpp
===
--- test/Analysis/new-ctor-conservative.cpp
+++ test/Analysis/new-ctor-conservative.cpp
@@ -1,6 +1,7 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
+void clang_analyzer_warnIfReached();
 
 struct S {
   int x;
@@ -27,3 +28,19 @@
   // FIXME: Should be true once we inline array constructors.
   clang_analyzer_eval(s[0].x == 1); // expected-warning{{UNKNOWN}}
 }
+
+struct NullS {
+  NullS() {
+if (this) {}
+  }
+  NullS(int x) {
+if (!this) {
+  clang_analyzer_warnIfReached(); // no-warning
+}
+  }
+};
+
+void checkNullThis() {
+  NullS *nulls = new NullS(); // no-crash
+  NullS *nulls2 = new NullS(0);
+}
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -500,9 +500,24 @@
 // is breaking too much to evaluate the no-op symbolic cast over it, so we
 // skip it for now.
 ProgramStateRef State = I->getState();
-ValueBldr.generateNode(
-CNE, I,
-setCXXNewAllocatorValue(State, CNE, LCtx, State->getSVal(CNE, LCtx)));
+SVal RetVal = State->getSVal(CNE, LCtx);
+
+// If this allocation function is not declared as non-throwing, failures
+// /must/ be signalled by exceptions, and thus the return value will never
+// be NULL. -fno-exceptions does not influence this semantics.
+// FIXME: GCC has a -fcheck-new option, which forces it to consider the case
+// where new can return NULL. If we end up supporting that option, we can
+// consider adding a check for it here.
+// C++11 [basic.stc.dynamic.allocation]p3.
+if (const FunctionDecl *FD = CNE->getOperatorNew()) {
+  QualType Ty = FD->getType();
+  if (const auto *ProtoType = Ty->getAs())
+if (!ProtoType->isNothrow(getContext()))
+  State = State->assume(RetVal.castAs(), true);
+}
+
+ValueBldr.generateNode(CNE, I,
+   setCXXNewAllocatorValue(State, CNE, LCtx, RetVal));
   }
 
   ExplodedNodeSet DstPostPostCallCallback;
@@ -559,21 +574,21 @@
 State = Call->invalidateRegions(blockCount);
 if (!State)
   return;
-  }
 
-  // If this allocation function is not declared as non-throwing, failures
-  // /must/ be signalled by exceptions, and thus the return value will never be
-  // NULL. -fno-exceptions does not influence this semantics.
-  // FIXME: GCC has 

[PATCH] D42192: [analyzer] Assume that the allocated value is non-null before construction, not after.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:516
+if (!ProtoType->isNothrow(getContext()))
+  State = State->assume(RetVal.castAs(), true);
+}

george.karpenkov wrote:
> This is neither here nor there, but for this and many other cases I think we 
> could be considerably more readable by defining helpers `State->assumeIsTrue` 
> and `State->assumeIsFalse` (or `assumeNonNull`, or whatever is most 
> descriptive)
Dunno, `assume(x, true)` sounds descriptive enough to me, and also feels more 
like a natural spoken language.


https://reviews.llvm.org/D42192



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


[PATCH] D42219: [analyzer] Enable c++-allocator-inlining by default?

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ created this revision.
NoQ added reviewers: dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet.
Herald added subscribers: cfe-commits, rnkovacs.

Once https://reviews.llvm.org/D42192 lands, i believe it should be safe to flip 
the default value of `-analyzer-config c++-allocator-inlining` to `true` by 
default.

My evaluation (on a large mostly internal codebase, including WebKit, more than 
a day of real-world time of continuous analysis) shows that around twice as 
much false positives are getting fixed (~35) as new false positives added 
(~20). Additionally, the reason for newly added false positives is our 
increased precision and coverage due to more aggressive inlining, which exposes 
other, unrelated problems in the analyzer, which is an expected outcome of 
enabling more coverage on codebases that already have high false positive rates 
(such as many C++ codebases). Gradually improving C++ support should be 
mitigating those. One true positive was lost due to analyzer reaching the 
`max-nodes` limit due to more aggressive inlining. I didn't immediately find 
any new positives that were definitely true, but some looked fairly suspicious.

The old mode would be available for a while, so it's possible, if necessary, to 
turn the new mode off with `-analyzer-config c++-allocator-inlining=false`.

All changes in tests in the patch are FIXMEs that were resolved by enabling the 
new mode.


Repository:
  rC Clang

https://reviews.llvm.org/D42219

Files:
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  test/Analysis/NewDelete-custom.cpp
  test/Analysis/ctor.mm
  test/Analysis/new.cpp
  test/Analysis/virtualcall.cpp


Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -262,6 +262,9 @@
//expected-note-re@-2 ^}}Calling default constructor for 'M'}}
 #endif
   Y *y = new Y;
+#if !PUREONLY
+  //expected-note-re@-2 ^}}Calling default constructor for 'Y'}}
+#endif
   delete y;
   header::Z z;
 #if !PUREONLY
Index: test/Analysis/new.cpp
===
--- test/Analysis/new.cpp
+++ test/Analysis/new.cpp
@@ -34,7 +34,7 @@
 
   void *y = new (x) int;
   clang_analyzer_eval(x == y); // expected-warning{{TRUE}};
-  clang_analyzer_eval(*x == 1); // expected-warning{{UNKNOWN}};
+  clang_analyzer_eval(*x == 1); // expected-warning{{TRUE}};
 
   return y;
 }
@@ -200,8 +200,7 @@
   int n;
   new () int;
 
-  // Should warn that n is uninitialized.
-  if (n) { // no-warning
+  if (n) { // expected-warning{{Branch condition evaluates to a garbage value}}
 return 0;
   }
   return 1;
Index: test/Analysis/ctor.mm
===
--- test/Analysis/ctor.mm
+++ test/Analysis/ctor.mm
@@ -572,10 +572,9 @@
   }
 
   void testNew() {
-// FIXME: Pending proper implementation of constructors for 'new'.
 raw_pair *pp = new raw_pair();
-clang_analyzer_eval(pp->p1 == 0); // expected-warning{{UNKNOWN}}
-clang_analyzer_eval(pp->p2 == 0); // expected-warning{{UNKNOWN}}
+clang_analyzer_eval(pp->p1 == 0); // expected-warning{{TRUE}}
+clang_analyzer_eval(pp->p2 == 0); // expected-warning{{TRUE}}
   }
 
   void testArrayNew() {
@@ -679,8 +678,7 @@
 
   void testDynamic() {
 List *list = new List{1, 2};
-// FIXME: When we handle constructors with 'new', this will be TRUE.
-clang_analyzer_eval(list->usedInitializerList); // 
expected-warning{{UNKNOWN}}
+clang_analyzer_eval(list->usedInitializerList); // expected-warning{{TRUE}}
   }
 }
 
Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks 
-verify %s
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -DLEAKS=1 -fblocks -verify %s
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 
-analyzer-config c++-allocator-inlining=true -DALLOCATOR_INLINING=1 -fblocks 
-verify %s
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 
-DALLOCATOR_INLINING=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 
-analyzer-config c++-allocator-inlining=false -fblocks -verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -analyzer-config c++-allocator-inlining=false -DLEAKS=1 -fblocks 
-verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 

[PATCH] D42015: [analyzer] NFC: RetainCount: Don't dump() regions to the user.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322799: [analyzer] NFC: RetainCount: Protect from dumping 
raw region to path notes. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D42015

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1929,6 +1929,12 @@
  isa(E);
 }
 
+static std::string describeRegion(const MemRegion *MR) {
+  // Once we support more storage locations for bindings,
+  // this would need to be improved.
+  return cast(MR)->getDecl()->getName();
+}
+
 /// Returns true if this stack frame is for an Objective-C method that is a
 /// property getter or setter whose body has been synthesized by the analyzer.
 static bool isSynthesizedAccessor(const StackFrameContext *SFC) {
@@ -2395,7 +2401,7 @@
 
   if (FirstBinding) {
 os << "object allocated and stored into '"
-   << FirstBinding->getString() << '\'';
+   << describeRegion(FirstBinding) << '\'';
   }
   else
 os << "allocated object";
@@ -2523,7 +2529,7 @@
   os << "of an object";
 
   if (AllocBinding) {
-os << " stored into '" << AllocBinding->getString() << '\'';
+os << " stored into '" << describeRegion(AllocBinding) << '\'';
 if (IncludeAllocationLine) {
   FullSourceLoc SL(AllocStmt->getLocStart(), Ctx.getSourceManager());
   os << " (allocated on line " << SL.getSpellingLineNumber() << ")";


Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1929,6 +1929,12 @@
  isa(E);
 }
 
+static std::string describeRegion(const MemRegion *MR) {
+  // Once we support more storage locations for bindings,
+  // this would need to be improved.
+  return cast(MR)->getDecl()->getName();
+}
+
 /// Returns true if this stack frame is for an Objective-C method that is a
 /// property getter or setter whose body has been synthesized by the analyzer.
 static bool isSynthesizedAccessor(const StackFrameContext *SFC) {
@@ -2395,7 +2401,7 @@
 
   if (FirstBinding) {
 os << "object allocated and stored into '"
-   << FirstBinding->getString() << '\'';
+   << describeRegion(FirstBinding) << '\'';
   }
   else
 os << "allocated object";
@@ -2523,7 +2529,7 @@
   os << "of an object";
 
   if (AllocBinding) {
-os << " stored into '" << AllocBinding->getString() << '\'';
+os << " stored into '" << describeRegion(AllocBinding) << '\'';
 if (IncludeAllocationLine) {
   FullSourceLoc SL(AllocStmt->getLocStart(), Ctx.getSourceManager());
   os << " (allocated on line " << SL.getSpellingLineNumber() << ")";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322799 - [analyzer] NFC: RetainCount: Protect from dumping raw region to path notes.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 17:01:56 2018
New Revision: 322799

URL: http://llvm.org/viewvc/llvm-project?rev=322799=rev
Log:
[analyzer] NFC: RetainCount: Protect from dumping raw region to path notes.

MemRegion::getString() is a wrapper around MemRegion::dump(), which is not
user-friendly and should never be used for diagnostic messages.

Actual cases where raw dumps were reaching the user were unintentionally fixed
in r315736; these were noticed accidentally and shouldn't be reproducible
anymore. For now RetainCountChecker only tracks pointers through variable
regions, and for those dumps are "fine". However, we should still use a less
dangerous method for producing our path notes.

This patch replaces the dump with printing a variable name, asserting that this
is indeed a variable.

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

Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=322799=322798=322799=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Wed Jan 17 
17:01:56 2018
@@ -1929,6 +1929,12 @@ static bool isNumericLiteralExpression(c
  isa(E);
 }
 
+static std::string describeRegion(const MemRegion *MR) {
+  // Once we support more storage locations for bindings,
+  // this would need to be improved.
+  return cast(MR)->getDecl()->getName();
+}
+
 /// Returns true if this stack frame is for an Objective-C method that is a
 /// property getter or setter whose body has been synthesized by the analyzer.
 static bool isSynthesizedAccessor(const StackFrameContext *SFC) {
@@ -2395,7 +2401,7 @@ CFRefLeakReportVisitor::getEndPath(BugRe
 
   if (FirstBinding) {
 os << "object allocated and stored into '"
-   << FirstBinding->getString() << '\'';
+   << describeRegion(FirstBinding) << '\'';
   }
   else
 os << "allocated object";
@@ -2523,7 +2529,7 @@ void CFRefLeakReport::createDescription(
   os << "of an object";
 
   if (AllocBinding) {
-os << " stored into '" << AllocBinding->getString() << '\'';
+os << " stored into '" << describeRegion(AllocBinding) << '\'';
 if (IncludeAllocationLine) {
   FullSourceLoc SL(AllocStmt->getLocStart(), Ctx.getSourceManager());
   os << " (allocated on line " << SL.getSpellingLineNumber() << ")";


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


[PATCH] D41935: [analyzer] NFC: Mark default constructors for ProgramPoints.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322798: [analyzer] NFC: Use = default for 
default ProgramPoint constructors. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41935?vs=129391=130322#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41935

Files:
  cfe/trunk/include/clang/Analysis/ProgramPoint.h

Index: cfe/trunk/include/clang/Analysis/ProgramPoint.h
===
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h
@@ -98,7 +98,7 @@
   llvm::PointerIntPair Tag;
 
 protected:
-  ProgramPoint() {}
+  ProgramPoint() = default;
   ProgramPoint(const void *P,
Kind k,
const LocationContext *l,
@@ -234,7 +234,7 @@
   
 private:
   friend class ProgramPoint;
-  BlockEntrance() {}
+  BlockEntrance() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEntranceKind;
   }
@@ -255,7 +255,7 @@
 
 private:
   friend class ProgramPoint;
-  BlockExit() {}
+  BlockExit() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockExitKind;
   }
@@ -275,7 +275,7 @@
   const T* getStmtAs() const { return dyn_cast(getStmt()); }
 
 protected:
-  StmtPoint() {}
+  StmtPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -295,15 +295,15 @@
 
 private:
   friend class ProgramPoint;
-  PreStmt() {}
+  PreStmt() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtKind;
   }
 };
 
 class PostStmt : public StmtPoint {
 protected:
-  PostStmt() {}
+  PostStmt() = default;
   PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L,
const ProgramPointTag *tag = nullptr)
 : StmtPoint(S, data, k, L, tag) {}
@@ -334,15 +334,15 @@
 
 private:
   friend class ProgramPoint;
-  PostCondition() {}
+  PostCondition() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostConditionKind;
   }
 };
 
 class LocationCheck : public StmtPoint {
 protected:
-  LocationCheck() {}
+  LocationCheck() = default;
   LocationCheck(const Stmt *S, const LocationContext *L,
 ProgramPoint::Kind K, const ProgramPointTag *tag)
 : StmtPoint(S, nullptr, K, L, tag) {}
@@ -363,7 +363,7 @@
   
 private:
   friend class ProgramPoint;
-  PreLoad() {}
+  PreLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreLoadKind;
   }
@@ -377,7 +377,7 @@
   
 private:
   friend class ProgramPoint;
-  PreStore() {}
+  PreStore() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreStoreKind;
   }
@@ -391,7 +391,7 @@
 
 private:
   friend class ProgramPoint;
-  PostLoad() {}
+  PostLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLoadKind;
   }
@@ -418,7 +418,7 @@
 
 private:
   friend class ProgramPoint;
-  PostStore() {}
+  PostStore() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStoreKind;
   }
@@ -432,7 +432,7 @@
 
 private:
   friend class ProgramPoint;
-  PostLValue() {}
+  PostLValue() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLValueKind;
   }
@@ -448,7 +448,7 @@
 
 private:
   friend class ProgramPoint;
-  PreStmtPurgeDeadSymbols() {}
+  PreStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtPurgeDeadSymbolsKind;
   }
@@ -464,7 +464,7 @@
 
 private:
   friend class ProgramPoint;
-  PostStmtPurgeDeadSymbols() {}
+  PostStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStmtPurgeDeadSymbolsKind;
   }
@@ -488,7 +488,7 @@
 
 private:
   friend class ProgramPoint;
-  BlockEdge() {}
+  BlockEdge() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEdgeKind;
   }
@@ -517,7 +517,7 @@
 
 private:
   friend class ProgramPoint;
-  PostInitializer() {}
+  PostInitializer() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostInitializerKind;
   }
@@ -538,7 +538,7 @@
   }
 
 protected:
-  ImplicitCallPoint() {}
+  ImplicitCallPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -558,7 +558,7 @@
 
 private:
   friend class ProgramPoint;
-  PreImplicitCall() {}
+  PreImplicitCall() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreImplicitCallKind;
   }
@@ -575,7 +575,7 @@
 
 private:
   friend class ProgramPoint;
-  PostImplicitCall() {}
+  PostImplicitCall() = default;
   static bool isKind(const 

[PATCH] D41935: [analyzer] NFC: Mark default constructors for ProgramPoints.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322798: [analyzer] NFC: Use = default for 
default ProgramPoint constructors. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41935

Files:
  include/clang/Analysis/ProgramPoint.h

Index: include/clang/Analysis/ProgramPoint.h
===
--- include/clang/Analysis/ProgramPoint.h
+++ include/clang/Analysis/ProgramPoint.h
@@ -98,7 +98,7 @@
   llvm::PointerIntPair Tag;
 
 protected:
-  ProgramPoint() {}
+  ProgramPoint() = default;
   ProgramPoint(const void *P,
Kind k,
const LocationContext *l,
@@ -234,7 +234,7 @@
   
 private:
   friend class ProgramPoint;
-  BlockEntrance() {}
+  BlockEntrance() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEntranceKind;
   }
@@ -255,7 +255,7 @@
 
 private:
   friend class ProgramPoint;
-  BlockExit() {}
+  BlockExit() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockExitKind;
   }
@@ -275,7 +275,7 @@
   const T* getStmtAs() const { return dyn_cast(getStmt()); }
 
 protected:
-  StmtPoint() {}
+  StmtPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -295,15 +295,15 @@
 
 private:
   friend class ProgramPoint;
-  PreStmt() {}
+  PreStmt() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtKind;
   }
 };
 
 class PostStmt : public StmtPoint {
 protected:
-  PostStmt() {}
+  PostStmt() = default;
   PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L,
const ProgramPointTag *tag = nullptr)
 : StmtPoint(S, data, k, L, tag) {}
@@ -334,15 +334,15 @@
 
 private:
   friend class ProgramPoint;
-  PostCondition() {}
+  PostCondition() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostConditionKind;
   }
 };
 
 class LocationCheck : public StmtPoint {
 protected:
-  LocationCheck() {}
+  LocationCheck() = default;
   LocationCheck(const Stmt *S, const LocationContext *L,
 ProgramPoint::Kind K, const ProgramPointTag *tag)
 : StmtPoint(S, nullptr, K, L, tag) {}
@@ -363,7 +363,7 @@
   
 private:
   friend class ProgramPoint;
-  PreLoad() {}
+  PreLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreLoadKind;
   }
@@ -377,7 +377,7 @@
   
 private:
   friend class ProgramPoint;
-  PreStore() {}
+  PreStore() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreStoreKind;
   }
@@ -391,7 +391,7 @@
 
 private:
   friend class ProgramPoint;
-  PostLoad() {}
+  PostLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLoadKind;
   }
@@ -418,7 +418,7 @@
 
 private:
   friend class ProgramPoint;
-  PostStore() {}
+  PostStore() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStoreKind;
   }
@@ -432,7 +432,7 @@
 
 private:
   friend class ProgramPoint;
-  PostLValue() {}
+  PostLValue() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLValueKind;
   }
@@ -448,7 +448,7 @@
 
 private:
   friend class ProgramPoint;
-  PreStmtPurgeDeadSymbols() {}
+  PreStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtPurgeDeadSymbolsKind;
   }
@@ -464,7 +464,7 @@
 
 private:
   friend class ProgramPoint;
-  PostStmtPurgeDeadSymbols() {}
+  PostStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStmtPurgeDeadSymbolsKind;
   }
@@ -488,7 +488,7 @@
 
 private:
   friend class ProgramPoint;
-  BlockEdge() {}
+  BlockEdge() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEdgeKind;
   }
@@ -517,7 +517,7 @@
 
 private:
   friend class ProgramPoint;
-  PostInitializer() {}
+  PostInitializer() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostInitializerKind;
   }
@@ -538,7 +538,7 @@
   }
 
 protected:
-  ImplicitCallPoint() {}
+  ImplicitCallPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -558,7 +558,7 @@
 
 private:
   friend class ProgramPoint;
-  PreImplicitCall() {}
+  PreImplicitCall() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreImplicitCallKind;
   }
@@ -575,7 +575,7 @@
 
 private:
   friend class ProgramPoint;
-  PostImplicitCall() {}
+  PostImplicitCall() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostImplicitCallKind;
   }
@@ -589,7 +589,7 @@
 
 private:
   friend class ProgramPoint;
-  

r322798 - [analyzer] NFC: Use "= default" for default ProgramPoint constructors.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:55:29 2018
New Revision: 322798

URL: http://llvm.org/viewvc/llvm-project?rev=322798=rev
Log:
[analyzer] NFC: Use "= default" for default ProgramPoint constructors.

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

Modified:
cfe/trunk/include/clang/Analysis/ProgramPoint.h

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=322798=322797=322798=diff
==
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed Jan 17 16:55:29 2018
@@ -98,7 +98,7 @@ private:
   llvm::PointerIntPair Tag;
 
 protected:
-  ProgramPoint() {}
+  ProgramPoint() = default;
   ProgramPoint(const void *P,
Kind k,
const LocationContext *l,
@@ -234,7 +234,7 @@ public:
   
 private:
   friend class ProgramPoint;
-  BlockEntrance() {}
+  BlockEntrance() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEntranceKind;
   }
@@ -255,7 +255,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  BlockExit() {}
+  BlockExit() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockExitKind;
   }
@@ -275,7 +275,7 @@ public:
   const T* getStmtAs() const { return dyn_cast(getStmt()); }
 
 protected:
-  StmtPoint() {}
+  StmtPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -295,7 +295,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PreStmt() {}
+  PreStmt() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtKind;
   }
@@ -303,7 +303,7 @@ private:
 
 class PostStmt : public StmtPoint {
 protected:
-  PostStmt() {}
+  PostStmt() = default;
   PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L,
const ProgramPointTag *tag = nullptr)
 : StmtPoint(S, data, k, L, tag) {}
@@ -334,7 +334,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostCondition() {}
+  PostCondition() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostConditionKind;
   }
@@ -342,7 +342,7 @@ private:
 
 class LocationCheck : public StmtPoint {
 protected:
-  LocationCheck() {}
+  LocationCheck() = default;
   LocationCheck(const Stmt *S, const LocationContext *L,
 ProgramPoint::Kind K, const ProgramPointTag *tag)
 : StmtPoint(S, nullptr, K, L, tag) {}
@@ -363,7 +363,7 @@ public:
   
 private:
   friend class ProgramPoint;
-  PreLoad() {}
+  PreLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreLoadKind;
   }
@@ -377,7 +377,7 @@ public:
   
 private:
   friend class ProgramPoint;
-  PreStore() {}
+  PreStore() = default;
   static bool isKind(const ProgramPoint ) {
 return location.getKind() == PreStoreKind;
   }
@@ -391,7 +391,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostLoad() {}
+  PostLoad() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLoadKind;
   }
@@ -418,7 +418,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostStore() {}
+  PostStore() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStoreKind;
   }
@@ -432,7 +432,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostLValue() {}
+  PostLValue() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostLValueKind;
   }
@@ -448,7 +448,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PreStmtPurgeDeadSymbols() {}
+  PreStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PreStmtPurgeDeadSymbolsKind;
   }
@@ -464,7 +464,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostStmtPurgeDeadSymbols() {}
+  PostStmtPurgeDeadSymbols() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostStmtPurgeDeadSymbolsKind;
   }
@@ -488,7 +488,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  BlockEdge() {}
+  BlockEdge() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == BlockEdgeKind;
   }
@@ -517,7 +517,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PostInitializer() {}
+  PostInitializer() = default;
   static bool isKind(const ProgramPoint ) {
 return Location.getKind() == PostInitializerKind;
   }
@@ -538,7 +538,7 @@ public:
   }
 
 protected:
-  ImplicitCallPoint() {}
+  ImplicitCallPoint() = default;
 private:
   friend class ProgramPoint;
   static bool isKind(const ProgramPoint ) {
@@ -558,7 +558,7 @@ public:
 
 private:
   friend class ProgramPoint;
-  PreImplicitCall() {}
+  PreImplicitCall() = default;
   static bool 

[PATCH] D41934: [analyzer] Fix CXXNewExpr callback order.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322797: [analyzer] operator new: Fix callback order for 
CXXNewExpr. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41934

Files:
  lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/cxxnewexpr-callback-inline.cpp
  test/Analysis/cxxnewexpr-callback-noinline.cpp

Index: test/Analysis/cxxnewexpr-callback-inline.cpp
===
--- test/Analysis/cxxnewexpr-callback-inline.cpp
+++ test/Analysis/cxxnewexpr-callback-inline.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder -analyzer-config c++-allocator-inlining=true,debug.AnalysisOrder:PreStmtCXXNewExpr=true,debug.AnalysisOrder:PostStmtCXXNewExpr=true,debug.AnalysisOrder:PreCall=true,debug.AnalysisOrder:PostCall=true,debug.AnalysisOrder:NewAllocator=true %s 2>&1 | FileCheck %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+namespace std {
+  void *malloc(size_t);
+}
+
+void *operator new(size_t size) { return std::malloc(size); }
+
+struct S {
+  S() {}
+};
+
+void foo();
+
+void test() {
+  S *s = new S();
+  foo();
+}
+
+// CHECK:  PreCall (operator new)
+// CHECK-NEXT: PreCall (std::malloc)
+// CHECK-NEXT: PostCall (std::malloc)
+// CHECK-NEXT: PostCall (operator new)
+// CHECK-NEXT: NewAllocator
+// CHECK-NEXT: PreCall (S::S)
+// CHECK-NEXT: PostCall (S::S)
+// CHECK-NEXT: PreStmt
+// CHECK-NEXT: PostStmt
+// CHECK-NEXT: PreCall (foo)
+// CHECK-NEXT: PostCall (foo)
Index: test/Analysis/cxxnewexpr-callback-noinline.cpp
===
--- test/Analysis/cxxnewexpr-callback-noinline.cpp
+++ test/Analysis/cxxnewexpr-callback-noinline.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.AnalysisOrder -analyzer-config c++-allocator-inlining=false,debug.AnalysisOrder:PreStmtCXXNewExpr=true,debug.AnalysisOrder:PostStmtCXXNewExpr=true,debug.AnalysisOrder:PreCall=true,debug.AnalysisOrder:PostCall=true,debug.AnalysisOrder:NewAllocator=true %s 2>&1 | FileCheck %s
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+namespace std {
+  void *malloc(size_t);
+}
+
+void *operator new(size_t size) { return std::malloc(size); }
+
+struct S {
+  S() {}
+};
+
+void foo();
+
+void test() {
+  S *s = new S();
+  foo();
+}
+
+// CHECK:  PreCall (S::S)
+// CHECK-NEXT: PostCall (S::S)
+// CHECK-NEXT: PreStmt
+// CHECK-NEXT: PostStmt
+// CHECK-NEXT: PreCall (foo)
+// CHECK-NEXT: PostCall (foo)
+// CHECK-NEXT: PreCall (std::malloc)
+// CHECK-NEXT: PostCall (std::malloc)
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1324,8 +1324,16 @@
 
 case Stmt::CXXNewExprClass: {
   Bldr.takeNodes(Pred);
+
+  ExplodedNodeSet PreVisit;
+  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
+
   ExplodedNodeSet PostVisit;
-  VisitCXXNewExpr(cast(S), Pred, PostVisit);
+  for (ExplodedNodeSet::iterator i = PreVisit.begin(),
+ e = PreVisit.end(); i != e ; ++i) {
+VisitCXXNewExpr(cast(S), *i, PostVisit);
+  }
+
   getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this);
   Bldr.addNodes(Dst);
   break;
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -372,7 +372,9 @@
   getCheckerManager().runCheckersForPostObjCMessage(Dst, DstPostCall, *Msg,
 *this,
 /*WasInlined=*/true);
-} else if (CE) {
+} else if (CE &&
+   !(isa(CE) && // Called when visiting CXXNewExpr.
+ AMgr.getAnalyzerOptions().mayInlineCXXAllocator())) {
   getCheckerManager().runCheckersForPostStmt(Dst, DstPostCall, CE,
  *this, /*WasInlined=*/true);
 } else {
Index: lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
+++ lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
@@ -15,8 +15,10 @@
 //===--===//
 
 #include "ClangSACheckers.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include 

r322797 - [analyzer] operator new: Fix callback order for CXXNewExpr.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:53:50 2018
New Revision: 322797

URL: http://llvm.org/viewvc/llvm-project?rev=322797=rev
Log:
[analyzer] operator new: Fix callback order for CXXNewExpr.

PreStmt was never called.

Additionally, under c++-allocator-inlining=true, PostStmt was
called twice when the allocator was inlined: once after evaluating the
new-expression itself, once after evaluating the allocator call which, for the
lack of better options, uses the new-expression as the call site.

This patch fixes both problems.

Differential Revision: https://reviews.llvm.org/D41934
rdar://problem/12180598

Added:
cfe/trunk/test/Analysis/cxxnewexpr-callback-inline.cpp
cfe/trunk/test/Analysis/cxxnewexpr-callback-noinline.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp?rev=322797=322796=322797=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp Wed Jan 17 
16:53:50 2018
@@ -15,8 +15,10 @@
 
//===--===//
 
 #include "ClangSACheckers.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 
 using namespace clang;
@@ -29,6 +31,11 @@ class AnalysisOrderChecker
  check::PostStmt,
  check::PreStmt,
  check::PostStmt,
+ check::PreStmt,
+ check::PostStmt,
+ check::PreCall,
+ check::PostCall,
+ check::NewAllocator,
  check::Bind,
  check::RegionChanges> {
   bool isCallbackEnabled(AnalyzerOptions , StringRef CallbackName) const {
@@ -72,6 +79,40 @@ public:
   llvm::errs() << "PostStmt\n";
   }
 
+  void checkPreStmt(const CXXNewExpr *NE, CheckerContext ) const {
+if (isCallbackEnabled(C, "PreStmtCXXNewExpr"))
+  llvm::errs() << "PreStmt\n";
+  }
+
+  void checkPostStmt(const CXXNewExpr *NE, CheckerContext ) const {
+if (isCallbackEnabled(C, "PostStmtCXXNewExpr"))
+  llvm::errs() << "PostStmt\n";
+  }
+
+  void checkPreCall(const CallEvent , CheckerContext ) const {
+if (isCallbackEnabled(C, "PreCall")) {
+  llvm::errs() << "PreCall";
+  if (const NamedDecl *ND = dyn_cast_or_null(Call.getDecl()))
+llvm::errs() << " (" << ND->getQualifiedNameAsString() << ')';
+  llvm::errs() << '\n';
+}
+  }
+
+  void checkPostCall(const CallEvent , CheckerContext ) const {
+if (isCallbackEnabled(C, "PostCall")) {
+  llvm::errs() << "PostCall";
+  if (const NamedDecl *ND = dyn_cast_or_null(Call.getDecl()))
+llvm::errs() << " (" << ND->getQualifiedNameAsString() << ')';
+  llvm::errs() << '\n';
+}
+  }
+
+  void checkNewAllocator(const CXXNewExpr *CNE, SVal Target,
+ CheckerContext ) const {
+if (isCallbackEnabled(C, "NewAllocator"))
+  llvm::errs() << "NewAllocator\n";
+  }
+
   void checkBind(SVal Loc, SVal Val, const Stmt *S, CheckerContext ) const {
 if (isCallbackEnabled(C, "Bind"))
   llvm::errs() << "Bind\n";

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=322797=322796=322797=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jan 17 16:53:50 2018
@@ -1324,8 +1324,16 @@ void ExprEngine::Visit(const Stmt *S, Ex
 
 case Stmt::CXXNewExprClass: {
   Bldr.takeNodes(Pred);
+
+  ExplodedNodeSet PreVisit;
+  getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this);
+
   ExplodedNodeSet PostVisit;
-  VisitCXXNewExpr(cast(S), Pred, PostVisit);
+  for (ExplodedNodeSet::iterator i = PreVisit.begin(),
+ e = PreVisit.end(); i != e ; ++i) {
+VisitCXXNewExpr(cast(S), *i, PostVisit);
+  }
+
   getCheckerManager().runCheckersForPostStmt(Dst, PostVisit, S, *this);
   Bldr.addNodes(Dst);
   break;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=322797=322796=322797=diff

[PATCH] D41800: [analyzer] Use a custom program point for the check::NewAllocator callback.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322796: [analyzer] operator new: Add a new ProgramPoint for 
check::NewAllocator. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41800

Files:
  include/clang/Analysis/ProgramPoint.h
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/CoreEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/NewDelete-path-notes.cpp

Index: lib/StaticAnalyzer/Core/CoreEngine.cpp
===
--- lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -275,7 +275,8 @@
  Loc.getAs() ||
  Loc.getAs() ||
  Loc.getAs() ||
- Loc.getAs());
+ Loc.getAs() ||
+ Loc.getAs());
   HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
   break;
   }
Index: lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -488,12 +488,7 @@
 
 void runChecker(CheckerManager::CheckNewAllocatorFunc checkFn,
 NodeBuilder , ExplodedNode *Pred) {
-  // TODO: Does this deserve a custom program point? For now we're re-using
-  // PostImplicitCall because we're guaranteed to use the non-implicit
-  // PostStmt for the PostCall callback, because we have some sort of
-  // call site (CXXNewExpr) in this scenario.
-  ProgramPoint L = PostImplicitCall(NE->getOperatorNew(), NE->getLocStart(),
-Pred->getLocationContext());
+  ProgramPoint L = PostAllocatorCall(NE, Pred->getLocationContext());
   CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
   checkFn(NE, Target, C);
 }
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2930,6 +2930,8 @@
   Out << "\\lPostStore\\l";
 else if (Loc.getAs())
   Out << "\\lPostLValue\\l";
+else if (Loc.getAs())
+  Out << "\\lPostAllocatorCall\\l";
 
 break;
   }
Index: include/clang/Analysis/ProgramPoint.h
===
--- include/clang/Analysis/ProgramPoint.h
+++ include/clang/Analysis/ProgramPoint.h
@@ -73,8 +73,9 @@
   PostStoreKind,
   PostConditionKind,
   PostLValueKind,
+  PostAllocatorCallKind,
   MinPostStmtKind = PostStmtKind,
-  MaxPostStmtKind = PostLValueKind,
+  MaxPostStmtKind = PostAllocatorCallKind,
   PostInitializerKind,
   CallEnterKind,
   CallExitBeginKind,
@@ -580,6 +581,20 @@
   }
 };
 
+class PostAllocatorCall : public StmtPoint {
+public:
+  PostAllocatorCall(const Stmt *S, const LocationContext *L,
+const ProgramPointTag *Tag = nullptr)
+  : StmtPoint(S, nullptr, PostAllocatorCallKind, L, Tag) {}
+
+private:
+  friend class ProgramPoint;
+  PostAllocatorCall() {}
+  static bool isKind(const ProgramPoint ) {
+return Location.getKind() == PostAllocatorCallKind;
+  }
+};
+
 /// Represents a point when we begin processing an inlined call.
 /// CallEnter uses the caller's location context.
 class CallEnter : public ProgramPoint {
Index: test/Analysis/NewDelete-path-notes.cpp
===
--- test/Analysis/NewDelete-path-notes.cpp
+++ test/Analysis/NewDelete-path-notes.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=text -analyzer-config c++-allocator-inlining=true -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=cplusplus.NewDelete,unix.Malloc -analyzer-output=plist -analyzer-config path-diagnostics-alternate=false %s -o %t.plist
 // RUN: FileCheck --input-file=%t.plist %s
 
@@ -40,25 +41,25 @@
 // CHECK-NEXT: start
 // CHECK-NEXT:  
 // CHECK-NEXT:   
-// CHECK-NEXT:line6
+// CHECK-NEXT:line7
 // CHECK-NEXT:col3
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:   
-// CHECK-NEXT:line6
+// CHECK-NEXT:line7
 // CHECK-NEXT:col5
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:  
 // CHECK-NEXT: end
 // CHECK-NEXT:  
 // CHECK-NEXT:   
-// CHECK-NEXT:line6
+// CHECK-NEXT:line7
 // CHECK-NEXT:col12
 // CHECK-NEXT:file0
 // CHECK-NEXT:   
 // CHECK-NEXT:  

r322796 - [analyzer] operator new: Add a new ProgramPoint for check::NewAllocator.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:50:19 2018
New Revision: 322796

URL: http://llvm.org/viewvc/llvm-project?rev=322796=rev
Log:
[analyzer] operator new: Add a new ProgramPoint for check::NewAllocator.

Add PostAllocatorCall program point to represent the moment in the analysis
between the operator new() call and the constructor call. Pointer cast from
"void *" to the correct object pointer type has already happened by this point.

The new program point, unlike the previously used PostImplicitCall, contains a
reference to the new-expression, which allows adding path diagnostics over it.

Differential Revision: https://reviews.llvm.org/D41800
rdar://problem/12180598

Modified:
cfe/trunk/include/clang/Analysis/ProgramPoint.h
cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/NewDelete-path-notes.cpp

Modified: cfe/trunk/include/clang/Analysis/ProgramPoint.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/ProgramPoint.h?rev=322796=322795=322796=diff
==
--- cfe/trunk/include/clang/Analysis/ProgramPoint.h (original)
+++ cfe/trunk/include/clang/Analysis/ProgramPoint.h Wed Jan 17 16:50:19 2018
@@ -73,8 +73,9 @@ public:
   PostStoreKind,
   PostConditionKind,
   PostLValueKind,
+  PostAllocatorCallKind,
   MinPostStmtKind = PostStmtKind,
-  MaxPostStmtKind = PostLValueKind,
+  MaxPostStmtKind = PostAllocatorCallKind,
   PostInitializerKind,
   CallEnterKind,
   CallExitBeginKind,
@@ -580,6 +581,20 @@ private:
   }
 };
 
+class PostAllocatorCall : public StmtPoint {
+public:
+  PostAllocatorCall(const Stmt *S, const LocationContext *L,
+const ProgramPointTag *Tag = nullptr)
+  : StmtPoint(S, nullptr, PostAllocatorCallKind, L, Tag) {}
+
+private:
+  friend class ProgramPoint;
+  PostAllocatorCall() {}
+  static bool isKind(const ProgramPoint ) {
+return Location.getKind() == PostAllocatorCallKind;
+  }
+};
+
 /// Represents a point when we begin processing an inlined call.
 /// CallEnter uses the caller's location context.
 class CallEnter : public ProgramPoint {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp?rev=322796=322795=322796=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp Wed Jan 17 16:50:19 
2018
@@ -488,12 +488,7 @@ namespace {
 
 void runChecker(CheckerManager::CheckNewAllocatorFunc checkFn,
 NodeBuilder , ExplodedNode *Pred) {
-  // TODO: Does this deserve a custom program point? For now we're re-using
-  // PostImplicitCall because we're guaranteed to use the non-implicit
-  // PostStmt for the PostCall callback, because we have some sort of
-  // call site (CXXNewExpr) in this scenario.
-  ProgramPoint L = PostImplicitCall(NE->getOperatorNew(), 
NE->getLocStart(),
-Pred->getLocationContext());
+  ProgramPoint L = PostAllocatorCall(NE, Pred->getLocationContext());
   CheckerContext C(Bldr, Eng, Pred, L, WasInlined);
   checkFn(NE, Target, C);
 }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp?rev=322796=322795=322796=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CoreEngine.cpp Wed Jan 17 16:50:19 2018
@@ -275,7 +275,8 @@ void CoreEngine::dispatchWorkItem(Explod
  Loc.getAs() ||
  Loc.getAs() ||
  Loc.getAs() ||
- Loc.getAs());
+ Loc.getAs() ||
+ Loc.getAs());
   HandlePostStmt(WU.getBlock(), WU.getIndex(), Pred);
   break;
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=322796=322795=322796=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jan 17 16:50:19 2018
@@ -2930,6 +2930,8 @@ struct DOTGraphTraits :
   Out << "\\lPostStore\\l";
 else if (Loc.getAs())
   Out << "\\lPostLValue\\l";
+else if (Loc.getAs())
+  Out << "\\lPostAllocatorCall\\l";
 
 break;
   }

Modified: 

[PATCH] D42217: Set Module Metadata "AvoidPLT" when -fno-plt is used.

2018-01-17 Thread Sriraman Tallam via Phabricator via cfe-commits
tmsriram created this revision.
tmsriram added reviewers: rnk, rafael.

Set Module Metadata "AvoidPLT" when -fno-plt is used.

Please see:
https://reviews.llvm.org/D42216 for more details.

This allows processing of calls to intrinsics easily.


https://reviews.llvm.org/D42217

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGen/noplt.c


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s 
-check-prefix=CHECK-NOPLT -check-prefix=CHECK-NOPLT-METADATA
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
 // CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
+// CHECK-NOPLT-METADATA: !"AvoidPLT"
 int foo();
 
 int bar() {
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -555,6 +555,10 @@
   getModule().setPIELevel(static_cast(PLevel));
   }
 
+  if (CodeGenOpts.NoPLT) {
+getModule().setAvoidPLT();
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)


Index: test/CodeGen/noplt.c
===
--- test/CodeGen/noplt.c
+++ test/CodeGen/noplt.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT -check-prefix=CHECK-NOPLT-METADATA
 
 // CHECK-NOPLT: Function Attrs: nonlazybind
 // CHECK-NOPLT-NEXT: declare {{.*}}i32 @foo
+// CHECK-NOPLT-METADATA: !"AvoidPLT"
 int foo();
 
 int bar() {
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -555,6 +555,10 @@
   getModule().setPIELevel(static_cast(PLevel));
   }
 
+  if (CodeGenOpts.NoPLT) {
+getModule().setAvoidPLT();
+  }
+
   SimplifyPersonality();
 
   if (getCodeGenOpts().EmitDeclMetadata)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41797: [analyzer] Suppress escape of this-pointer during construction.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322795: [analyzer] Suppress this pointer escape 
during construction. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41797

Files:
  lib/StaticAnalyzer/Core/CallEvent.cpp
  test/Analysis/NewDeleteLeaks-PR19102.cpp


Index: test/Analysis/NewDeleteLeaks-PR19102.cpp
===
--- test/Analysis/NewDeleteLeaks-PR19102.cpp
+++ test/Analysis/NewDeleteLeaks-PR19102.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks 
-analyzer-config c++-allocator-inlining=true -verify %s
 
 class A0 {};
 
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -672,8 +672,13 @@
 
 void CXXConstructorCall::getExtraInvalidatedValues(ValueList ,
RegionAndSymbolInvalidationTraits *ETraits) const {
-  if (Data)
-Values.push_back(loc::MemRegionVal(static_cast(Data)));
+  if (Data) {
+loc::MemRegionVal MV(static_cast(Data));
+if (SymbolRef Sym = MV.getAsSymbol(true))
+  ETraits->setTrait(Sym,
+RegionAndSymbolInvalidationTraits::TK_SuppressEscape);
+Values.push_back(MV);
+  }
 }
 
 void CXXConstructorCall::getInitialStackFrameContents(


Index: test/Analysis/NewDeleteLeaks-PR19102.cpp
===
--- test/Analysis/NewDeleteLeaks-PR19102.cpp
+++ test/Analysis/NewDeleteLeaks-PR19102.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -analyzer-config c++-allocator-inlining=true -verify %s
 
 class A0 {};
 
Index: lib/StaticAnalyzer/Core/CallEvent.cpp
===
--- lib/StaticAnalyzer/Core/CallEvent.cpp
+++ lib/StaticAnalyzer/Core/CallEvent.cpp
@@ -672,8 +672,13 @@
 
 void CXXConstructorCall::getExtraInvalidatedValues(ValueList ,
RegionAndSymbolInvalidationTraits *ETraits) const {
-  if (Data)
-Values.push_back(loc::MemRegionVal(static_cast(Data)));
+  if (Data) {
+loc::MemRegionVal MV(static_cast(Data));
+if (SymbolRef Sym = MV.getAsSymbol(true))
+  ETraits->setTrait(Sym,
+RegionAndSymbolInvalidationTraits::TK_SuppressEscape);
+Values.push_back(MV);
+  }
 }
 
 void CXXConstructorCall::getInitialStackFrameContents(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322795 - [analyzer] Suppress "this" pointer escape during construction.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:44:41 2018
New Revision: 322795

URL: http://llvm.org/viewvc/llvm-project?rev=322795=rev
Log:
[analyzer] Suppress "this" pointer escape during construction.

Pointer escape event notifies checkers that a pointer can no longer be reliably
tracked by the analyzer. For example, if a pointer is passed into a function
that has no body available, or written into a global, MallocChecker would
no longer report memory leaks for such pointer.

In case of operator new() under -analyzer-config c++-allocator-inlining=true,
MallocChecker would start tracking the pointer allocated by operator new()
only to immediately meet a pointer escape event notifying the checker that the
pointer has escaped into a constructor (assuming that the body of the
constructor is not available) and immediately stop tracking it. Even though
it is theoretically possible for such constructor to put "this" into
a global container that would later be freed, we prefer to preserve the old
behavior of MallocChecker, i.e. a memory leak warning, in order to
be able to find any memory leaks in C++ at all. In fact, c++-allocator-inlining
*reduces* the amount of false positives coming from this-pointers escaping in
constructors, because it'd be able to inline constructors in some cases.

With other checkers working similarly, we simply suppress the escape event for
this-value of the constructor, regardless of analyzer options.

Differential Revision: https://reviews.llvm.org/D41797
rdar://problem/12180598

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
cfe/trunk/test/Analysis/NewDeleteLeaks-PR19102.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp?rev=322795=322794=322795=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CallEvent.cpp Wed Jan 17 16:44:41 2018
@@ -672,8 +672,13 @@ SVal CXXConstructorCall::getCXXThisVal()
 
 void CXXConstructorCall::getExtraInvalidatedValues(ValueList ,
RegionAndSymbolInvalidationTraits *ETraits) const {
-  if (Data)
-Values.push_back(loc::MemRegionVal(static_cast(Data)));
+  if (Data) {
+loc::MemRegionVal MV(static_cast(Data));
+if (SymbolRef Sym = MV.getAsSymbol(true))
+  ETraits->setTrait(Sym,
+RegionAndSymbolInvalidationTraits::TK_SuppressEscape);
+Values.push_back(MV);
+  }
 }
 
 void CXXConstructorCall::getInitialStackFrameContents(

Modified: cfe/trunk/test/Analysis/NewDeleteLeaks-PR19102.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NewDeleteLeaks-PR19102.cpp?rev=322795=322794=322795=diff
==
--- cfe/trunk/test/Analysis/NewDeleteLeaks-PR19102.cpp (original)
+++ cfe/trunk/test/Analysis/NewDeleteLeaks-PR19102.cpp Wed Jan 17 16:44:41 2018
@@ -1,4 +1,5 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks 
-verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks 
-analyzer-config c++-allocator-inlining=true -verify %s
 
 class A0 {};
 


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


[PATCH] D42208: Use an enum value instead of an string

2018-01-17 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola added a comment.

322792


https://reviews.llvm.org/D42208



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


Re: r322769 - [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Rafael Avila de Espindola via cfe-commits
With this I am getting a test failure on linux:

 TEST 'Clang :: Driver/riscv-gnutools.c' FAILED 

Script:
--
/home/admin/llvm/build/bin/clang -target riscv32-linux-unknown-elf 
-fno-integrated-as  
--gcc-toolchain=/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk
  
--sysroot=/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot
 /home/admin/llvm/llvm-project/clang/test/Driver/riscv-gnutools.c -###  2>&1 | 
/home/admin/llvm/build/bin/FileCheck -check-prefix=MABI-ILP32 
/home/admin/llvm/llvm-project/clang/test/Driver/riscv-gnutools.c
/home/admin/llvm/build/bin/clang -target riscv32-linux-unknown-elf 
-fno-integrated-as  -march=rv32g 
--gcc-toolchain=/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk
  
--sysroot=/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot
 /home/admin/llvm/llvm-project/clang/test/Driver/riscv-gnutools.c -###  2>&1 | 
/home/admin/llvm/build/bin/FileCheck -check-prefix=MABI-ILP32-MARCH-G 
/home/admin/llvm/llvm-project/clang/test/Driver/riscv-gnutools.c
--
Exit Code: 1

Command Output (stderr):
--
/home/admin/llvm/llvm-project/clang/test/Driver/riscv-gnutools.c:12:16: error: 
expected string not found in input
// MABI-ILP32: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32"
   ^
:1:1: note: scanning from here
clang version 7.0.0
^
:7:42: note: possible intended match here
 
"/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin/ld"
 
"--sysroot=/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot"
 "--hash-style=both" "--eh-frame-hdr" "-m" "elf32lriscv" "-dynamic-linker" 
"/lib/ld-linux-riscv32-ilp32.so.1" "-o" "a.out" "crt1.o" "crti.o" 
"/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/lib32/ilp32/crtbegin.o"
 
"-L/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/lib32/ilp32"
 
"-L/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot/lib/../lib32"
 
"-L/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot/lib32/ilp32"
 
"-L/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot/usr/lib32/ilp32"
 
"-L/home/admin/llvm/llvm-project/clang/test/Driver/Inputs/multilib_riscv_linux_sdk/sysroot/lib"
 "/tmp/lit_tmp_9u9TOy/riscv-gnutools-ebce8c.o" "-lgcc" "--as-needed" "-lgcc_s" 
"--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" 
"crtend.o" "crtn.o"
 ^

--

Cheers,
Rafael




Ana Pazos via cfe-commits  writes:

> Author: apazos
> Date: Wed Jan 17 14:09:58 2018
> New Revision: 322769
>
> URL: http://llvm.org/viewvc/llvm-project?rev=322769=rev
> Log:
> [RISCV] Propagate -mabi and -march values to GNU assembler.
>
> When using -fno-integrated-as flag, the gnu assembler produces code
> with some default march/mabi which later causes linker failure due
> to incompatible mabi/march.
>
> In this patch we explicitly propagate -mabi and -march flags to the
> GNU assembler.
>
> In this patch we explicitly propagate -mabi and -march flags to the GNU 
> assembler.
>
> Differential Revision: https://reviews.llvm.org/D41271
>
> Added:
> 
> cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
> cfe/trunk/test/Driver/riscv-gnutools.c
> Modified:
> cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
>
> Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=322769=322768=322769=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Jan 17 14:09:58 2018
> @@ -629,6 +629,18 @@ void tools::gnutools::Assembler::Constru
>ppc::getPPCAsmModeForCPU(getCPUName(Args, 
> getToolChain().getTriple(;
>  break;
>}
> +  case llvm::Triple::riscv32:
> +  case llvm::Triple::riscv64: {
> +StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
> +CmdArgs.push_back("-mabi");
> +CmdArgs.push_back(ABIName.data());
> +if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
> +  StringRef MArch = A->getValue();
> +  CmdArgs.push_back("-march");
> +  CmdArgs.push_back(MArch.data());
> +}
> +break;
> +  }
>case llvm::Triple::sparc:
>case llvm::Triple::sparcel: {
>  CmdArgs.push_back("-32");
>
> Added: 
> 

[libcxx] r322794 - libcxx: Define set_unexpected, _get_unexpected and __uncaught_exceptions without dllimport.

2018-01-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 17 16:33:35 2018
New Revision: 322794

URL: http://llvm.org/viewvc/llvm-project?rev=322794=rev
Log:
libcxx: Define set_unexpected, _get_unexpected and __uncaught_exceptions 
without dllimport.

It turns out that the MSVC headers define these functions without
dllimport even when compiling with /MD. This change fixes the resulting
compile-time error.

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

Modified:
libcxx/trunk/src/support/runtime/exception_msvc.ipp

Modified: libcxx/trunk/src/support/runtime/exception_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_msvc.ipp?rev=322794=322793=322794=diff
==
--- libcxx/trunk/src/support/runtime/exception_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_msvc.ipp Wed Jan 17 16:33:35 2018
@@ -22,11 +22,11 @@ _LIBCPP_CRT_FUNC terminate_handler __cde
 _LIBCPP_CRT_FUNC terminate_handler __cdecl _get_terminate();
 
 typedef void (__cdecl* unexpected_handler)();
-_LIBCPP_CRT_FUNC unexpected_handler __cdecl set_unexpected(
+unexpected_handler __cdecl set_unexpected(
 unexpected_handler _NewUnexpectedHandler) throw();
-_LIBCPP_CRT_FUNC unexpected_handler __cdecl _get_unexpected();
+unexpected_handler __cdecl _get_unexpected();
 
-_LIBCPP_CRT_FUNC int __cdecl __uncaught_exceptions();
+int __cdecl __uncaught_exceptions();
 }
 
 namespace std {


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


[PATCH] D42213: [ASTMatchers] [NFC] Fix code examples

2018-01-17 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
Herald added subscribers: cfe-commits, klimek.

Repository:
  rC Clang

https://reviews.llvm.org/D42213

Files:
  include/clang/ASTMatchers/ASTMatchers.h


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(


Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -800,7 +800,7 @@
 ///   A b;
 ///   A c;
 ///
-///   template f() {};
+///   template void f() {};
 ///   void func() { f(); };
 /// \endcode
 /// classTemplateSpecializationDecl(hasTemplateArgument(
@@ -880,12 +880,12 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// classTemplateSpecializationDecl(hasAnyTemplateArgument(
-/// refersToDeclaration(fieldDecl(hasName("next"
+/// refersToDeclaration(fieldDecl(hasName("next")
 ///   matches the specialization \c A<::next> with \c fieldDecl(...) matching
 /// \c B::next
 AST_MATCHER_P(TemplateArgument, refersToDeclaration,
@@ -899,8 +899,8 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
-///   struct B { B* next; };
+///   struct B { int next; };
+///   template struct A {};
 ///   A<::next> a;
 /// \endcode
 /// templateSpecializationType(hasAnyTemplateArgument(
@@ -917,7 +917,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -932,7 +932,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
@@ -953,7 +953,7 @@
 ///
 /// Given
 /// \code
-///   template struct A {};
+///   template struct C {};
 ///   C<42> c;
 /// \endcode
 /// classTemplateSpecializationDecl(
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322792 - Use an enum value instead of a string.

2018-01-17 Thread Rafael Espindola via cfe-commits
Author: rafael
Date: Wed Jan 17 16:20:03 2018
New Revision: 322792

URL: http://llvm.org/viewvc/llvm-project?rev=322792=rev
Log:
Use an enum value instead of a string.

The old StringSwitch use was also broken. It assumed that a
StringSwitch returns Optional instead of T and was missing a
.Default.

Modified:
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Frontend/CodeGenOptions.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=322792=322791=322792=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Wed Jan 17 16:20:03 2018
@@ -16,6 +16,7 @@
 
 #include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Sanitizers.h"
+#include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -167,7 +168,7 @@ public:
   std::string SplitDwarfFile;
 
   /// The name of the relocation model to use.
-  std::string RelocationModel;
+  llvm::Reloc::Model RelocationModel;
 
   /// The thread model to use
   std::string ThreadModel;

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=322792=322791=322792=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Jan 17 16:20:03 2018
@@ -362,21 +362,6 @@ getCodeModel(const CodeGenOptions 
   return static_cast(CodeModel);
 }
 
-static llvm::Reloc::Model getRelocModel(const CodeGenOptions ) {
-  // Keep this synced with the equivalent code in
-  // lib/Frontend/CompilerInvocation.cpp
-  llvm::Optional RM;
-  RM = llvm::StringSwitch(CodeGenOpts.RelocationModel)
-  .Case("static", llvm::Reloc::Static)
-  .Case("pic", llvm::Reloc::PIC_)
-  .Case("ropi", llvm::Reloc::ROPI)
-  .Case("rwpi", llvm::Reloc::RWPI)
-  .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
-  .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC);
-  assert(RM.hasValue() && "invalid PIC model!");
-  return *RM;
-}
-
 static TargetMachine::CodeGenFileType getCodeGenFileType(BackendAction Action) 
{
   if (Action == Backend_EmitObj)
 return TargetMachine::CGFT_ObjectFile;
@@ -692,7 +677,7 @@ void EmitAssemblyHelper::CreateTargetMac
   Optional CM = getCodeModel(CodeGenOpts);
   std::string FeaturesStr =
   llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ",");
-  llvm::Reloc::Model RM = getRelocModel(CodeGenOpts);
+  llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;
   CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);
 
   llvm::TargetOptions Options;
@@ -1113,7 +1098,7 @@ static void runThinLTOBackend(ModuleSumm
   Conf.CPU = TOpts.CPU;
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
-  Conf.RelocModel = getRelocModel(CGOpts);
+  Conf.RelocModel = CGOpts.RelocationModel;
   Conf.CGOptLevel = getCGOptLevel(CGOpts);
   initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
   Conf.SampleProfile = std::move(SampleProfile);

Modified: cfe/trunk/lib/Frontend/CodeGenOptions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CodeGenOptions.cpp?rev=322792=322791=322792=diff
==
--- cfe/trunk/lib/Frontend/CodeGenOptions.cpp (original)
+++ cfe/trunk/lib/Frontend/CodeGenOptions.cpp Wed Jan 17 16:20:03 2018
@@ -17,7 +17,7 @@ CodeGenOptions::CodeGenOptions() {
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
 #include "clang/Frontend/CodeGenOptions.def"
 
-  RelocationModel = "pic";
+  RelocationModel = llvm::Reloc::PIC_;
   memcpy(CoverageVersion, "402*", 4);
 }
 

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=322792=322791=322792=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Jan 17 16:20:03 2018
@@ -330,15 +330,23 @@ static StringRef getCodeModel(ArgList 
   return "default";
 }
 
-static StringRef getRelocModel(ArgList , DiagnosticsEngine ) {
+static llvm::Reloc::Model getRelocModel(ArgList ,
+DiagnosticsEngine ) {
   if (Arg *A = Args.getLastArg(OPT_mrelocation_model)) {
 StringRef Value = A->getValue();
-if (Value == "static" || Value == "pic" || Value == "ropi" ||
-Value == "rwpi" || Value == "ropi-rwpi" || Value == "dynamic-no-pic")
-  return Value;
+auto RM = 

Re: r322769 - [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Mikhail Zolotukhin via cfe-commits
Hi,

Looks like the test is failing on MacOS [1]. Could you please take a look?

Thanks,
Michael

[1] 
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/45726/consoleFull#9955924438254eaf0-7326-4999-85b0-388101f2d404
 



> On Jan 17, 2018, at 2:09 PM, Ana Pazos via cfe-commits 
>  wrote:
> 
> Author: apazos
> Date: Wed Jan 17 14:09:58 2018
> New Revision: 322769
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=322769=rev
> Log:
> [RISCV] Propagate -mabi and -march values to GNU assembler.
> 
> When using -fno-integrated-as flag, the gnu assembler produces code
> with some default march/mabi which later causes linker failure due
> to incompatible mabi/march.
> 
> In this patch we explicitly propagate -mabi and -march flags to the
> GNU assembler.
> 
> In this patch we explicitly propagate -mabi and -march flags to the GNU 
> assembler.
> 
> Differential Revision: https://reviews.llvm.org/D41271
> 
> Added:
>
> cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
>cfe/trunk/test/Driver/riscv-gnutools.c
> Modified:
>cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> 
> Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=322769=322768=322769=diff
> ==
> --- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
> +++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Jan 17 14:09:58 2018
> @@ -629,6 +629,18 @@ void tools::gnutools::Assembler::Constru
>   ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple(;
> break;
>   }
> +  case llvm::Triple::riscv32:
> +  case llvm::Triple::riscv64: {
> +StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
> +CmdArgs.push_back("-mabi");
> +CmdArgs.push_back(ABIName.data());
> +if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
> +  StringRef MArch = A->getValue();
> +  CmdArgs.push_back("-march");
> +  CmdArgs.push_back(MArch.data());
> +}
> +break;
> +  }
>   case llvm::Triple::sparc:
>   case llvm::Triple::sparcel: {
> CmdArgs.push_back("-32");
> 
> Added: 
> cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as?rev=322769=auto
> ==
> --- 
> cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
>  (added)
> +++ 
> cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
>  Wed Jan 17 14:09:58 2018
> @@ -0,0 +1 @@
> +#!/bin/true
> 
> Added: cfe/trunk/test/Driver/riscv-gnutools.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/riscv-gnutools.c?rev=322769=auto
> ==
> --- cfe/trunk/test/Driver/riscv-gnutools.c (added)
> +++ cfe/trunk/test/Driver/riscv-gnutools.c Wed Jan 17 14:09:58 2018
> @@ -0,0 +1,14 @@
> +// Check gnutools are invoked with propagated values for -mabi and -march.
> +
> +// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
> +// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
> +// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
> +// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32 %s
> +// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
> +// RUN: -march=rv32g --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
> +// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
> +// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32-MARCH-G %s
> +
> +// MABI-ILP32: 
> "{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
>  "-mabi" "ilp32"
> +// MABI-ILP32-MARCH-G: 
> "{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
>  "-mabi" "ilp32" "-march" "rv32g"
> +
> 
> 
> ___
> 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


r322791 - [analyzer] operator new: Fix path diagnostics around the operator call.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:10:21 2018
New Revision: 322791

URL: http://llvm.org/viewvc/llvm-project?rev=322791=rev
Log:
[analyzer] operator new: Fix path diagnostics around the operator call.

Implements finding appropriate source locations for intermediate diagnostic
pieces in path-sensitive bug reports that need to descend into an inlined
operator new() call that was called via new-expression. The diagnostics have
worked correctly when operator new() was called "directly".

Differential Revision: https://reviews.llvm.org/D41409
rdar://problem/12180598

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
cfe/trunk/test/Analysis/new-ctor-malloc.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=322791=322790=322791=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Wed Jan 17 16:10:21 
2018
@@ -574,8 +574,11 @@ getLocationForCaller(const StackFrameCon
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::NewAllocator: {
+const CFGNewAllocator  = Source.castAs();
+return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
-  case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:

Modified: cfe/trunk/test/Analysis/new-ctor-malloc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/new-ctor-malloc.cpp?rev=322791=322790=322791=diff
==
--- cfe/trunk/test/Analysis/new-ctor-malloc.cpp (original)
+++ cfe/trunk/test/Analysis/new-ctor-malloc.cpp Wed Jan 17 16:10:21 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
 
@@ -7,12 +7,15 @@ typedef __typeof__(sizeof(int)) size_t;
 void *malloc(size_t size);
 
 void *operator new(size_t size) throw() {
-  void *x = malloc(size);
-  if (!x)
+  void *x = malloc(size); // expected-note {{Memory is allocated}}
+  if (!x) // expected-note{{Assuming 'x' is non-null}}
+  // expected-note@-1 {{Taking false branch}}
 return nullptr;
   return x;
 }
 
 void checkNewAndConstructorInlining() {
-  int *s = new int;
+  int *s = new int; // expected-note   {{Calling 'operator new'}}
+// expected-note@-1{{Returning from 'operator new'}}
 } // expected-warning {{Potential leak of memory pointed to by 's'}}
+  // expected-note@-1 {{Potential leak of memory pointed to by 's'}}


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


[PATCH] D41409: [analyzer] Fix intermediate diagnostics on paths that go through operator new().

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322791: [analyzer] operator new: Fix path diagnostics around 
the operator call. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41409

Files:
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp
  test/Analysis/new-ctor-malloc.cpp


Index: test/Analysis/new-ctor-malloc.cpp
===
--- test/Analysis/new-ctor-malloc.cpp
+++ test/Analysis/new-ctor-malloc.cpp
@@ -1,18 +1,21 @@
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config 
c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
 
 typedef __typeof__(sizeof(int)) size_t;
 
 void *malloc(size_t size);
 
 void *operator new(size_t size) throw() {
-  void *x = malloc(size);
-  if (!x)
+  void *x = malloc(size); // expected-note {{Memory is allocated}}
+  if (!x) // expected-note{{Assuming 'x' is non-null}}
+  // expected-note@-1 {{Taking false branch}}
 return nullptr;
   return x;
 }
 
 void checkNewAndConstructorInlining() {
-  int *s = new int;
+  int *s = new int; // expected-note   {{Calling 'operator new'}}
+// expected-note@-1{{Returning from 'operator new'}}
 } // expected-warning {{Potential leak of memory pointed to by 's'}}
+  // expected-note@-1 {{Potential leak of memory pointed to by 's'}}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -574,8 +574,11 @@
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::NewAllocator: {
+const CFGNewAllocator  = Source.castAs();
+return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
-  case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:


Index: test/Analysis/new-ctor-malloc.cpp
===
--- test/Analysis/new-ctor-malloc.cpp
+++ test/Analysis/new-ctor-malloc.cpp
@@ -1,18 +1,21 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection,unix.Malloc -analyzer-config c++-allocator-inlining=true -analyzer-output=text -std=c++11 -verify %s
 
 void clang_analyzer_eval(bool);
 
 typedef __typeof__(sizeof(int)) size_t;
 
 void *malloc(size_t size);
 
 void *operator new(size_t size) throw() {
-  void *x = malloc(size);
-  if (!x)
+  void *x = malloc(size); // expected-note {{Memory is allocated}}
+  if (!x) // expected-note{{Assuming 'x' is non-null}}
+  // expected-note@-1 {{Taking false branch}}
 return nullptr;
   return x;
 }
 
 void checkNewAndConstructorInlining() {
-  int *s = new int;
+  int *s = new int; // expected-note   {{Calling 'operator new'}}
+// expected-note@-1{{Returning from 'operator new'}}
 } // expected-warning {{Potential leak of memory pointed to by 's'}}
+  // expected-note@-1 {{Potential leak of memory pointed to by 's'}}
Index: lib/StaticAnalyzer/Core/PathDiagnostic.cpp
===
--- lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -574,8 +574,11 @@
   return PathDiagnosticLocation::createEnd(CallerBody, SM, CallerCtx);
 return PathDiagnosticLocation::create(CallerInfo->getDecl(), SM);
   }
+  case CFGElement::NewAllocator: {
+const CFGNewAllocator  = Source.castAs();
+return PathDiagnosticLocation(Alloc.getAllocatorExpr(), SM, CallerCtx);
+  }
   case CFGElement::TemporaryDtor:
-  case CFGElement::NewAllocator:
 llvm_unreachable("not yet implemented!");
   case CFGElement::LifetimeEnds:
   case CFGElement::LoopExit:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41408: [analyzer] NFC: Fix nothrow operator new definition in a test.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322790: [analyzer] NFC: operator new: Fix new(nothrow) 
definition in tests. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41408?vs=127580=130307#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41408

Files:
  cfe/trunk/test/Analysis/NewDelete-custom.cpp


Index: cfe/trunk/test/Analysis/NewDelete-custom.cpp
===
--- cfe/trunk/test/Analysis/NewDelete-custom.cpp
+++ cfe/trunk/test/Analysis/NewDelete-custom.cpp
@@ -4,16 +4,16 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 
-DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
 
 void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return 
allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t ) throw() { 
return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 


Index: cfe/trunk/test/Analysis/NewDelete-custom.cpp
===
--- cfe/trunk/test/Analysis/NewDelete-custom.cpp
+++ cfe/trunk/test/Analysis/NewDelete-custom.cpp
@@ -4,16 +4,16 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
 
 void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t ) throw() { return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322790 - [analyzer] NFC: operator new: Fix new(nothrow) definition in tests.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 16:03:43 2018
New Revision: 322790

URL: http://llvm.org/viewvc/llvm-project?rev=322790=rev
Log:
[analyzer] NFC: operator new: Fix new(nothrow) definition in tests.

Fix the const qualifier so that the operator defined in the tests indeed does
override the default global nothrow version of new.

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

Modified:
cfe/trunk/test/Analysis/NewDelete-custom.cpp

Modified: cfe/trunk/test/Analysis/NewDelete-custom.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NewDelete-custom.cpp?rev=322790=322789=322790=diff
==
--- cfe/trunk/test/Analysis/NewDelete-custom.cpp (original)
+++ cfe/trunk/test/Analysis/NewDelete-custom.cpp Wed Jan 17 16:03:43 2018
@@ -4,7 +4,7 @@
 // RUN: %clang_analyze_cc1 
-analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc 
-std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 
-DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#if !LEAKS
+#if !(LEAKS && !ALLOCATOR_INLINING)
 // expected-no-diagnostics
 #endif
 
@@ -13,7 +13,7 @@ void *allocator(std::size_t size);
 
 void *operator new[](std::size_t size) throw() { return allocator(size); }
 void *operator new(std::size_t size) throw() { return allocator(size); }
-void *operator new(std::size_t size, std::nothrow_t& nothrow) throw() { return 
allocator(size); }
+void *operator new(std::size_t size, const std::nothrow_t ) throw() { 
return allocator(size); }
 void *operator new(std::size_t, double d);
 
 class C {
@@ -59,16 +59,13 @@ void testNewExpr() {
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
-  void *p = operator new(0, std::nothrow);
+  void *p = operator new(0, std::nothrow); // call is inlined, no warn
 }
-#if LEAKS
-// expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
-#endif
 
 void testNewExprNoThrow() {
   int *p = new(std::nothrow) int;
 }
-#if LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 


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


[PATCH] D42208: Use an enum value instead of an string

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

Looks good!


https://reviews.llvm.org/D42208



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


[PATCH] D41406: [analyzer] Add a new checker callback, check::NewAllocator.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322787: [analyzer] operator new: Add a new checker callback, 
check::NewAllocator. (authored by dergachev, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41406?vs=129369=130304#toc

Repository:
  rC Clang

https://reviews.llvm.org/D41406

Files:
  include/clang/StaticAnalyzer/Core/Checker.h
  include/clang/StaticAnalyzer/Core/CheckerManager.h
  lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Core/CheckerManager.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/NewDelete-custom.cpp
  test/Analysis/new-ctor-malloc.cpp

Index: include/clang/StaticAnalyzer/Core/Checker.h
===
--- include/clang/StaticAnalyzer/Core/Checker.h
+++ include/clang/StaticAnalyzer/Core/Checker.h
@@ -283,6 +283,22 @@
   }
 };
 
+class NewAllocator {
+  template 
+  static void _checkNewAllocator(void *checker, const CXXNewExpr *NE,
+ SVal Target, CheckerContext ) {
+((const CHECKER *)checker)->checkNewAllocator(NE, Target, C);
+  }
+
+public:
+  template 
+  static void _register(CHECKER *checker, CheckerManager ) {
+mgr._registerForNewAllocator(
+CheckerManager::CheckNewAllocatorFunc(checker,
+  _checkNewAllocator));
+  }
+};
+
 class LiveSymbols {
   template 
   static void _checkLiveSymbols(void *checker, ProgramStateRef state,
Index: include/clang/StaticAnalyzer/Core/CheckerManager.h
===
--- include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -303,6 +303,13 @@
  ExplodedNodeSet , ExplodedNode *Pred,
  ExprEngine );
 
+  /// \brief Run checkers between C++ operator new and constructor calls.
+  void runCheckersForNewAllocator(const CXXNewExpr *NE, SVal Target,
+  ExplodedNodeSet ,
+  ExplodedNode *Pred,
+  ExprEngine ,
+  bool wasInlined = false);
+
   /// \brief Run checkers for live symbols.
   ///
   /// Allows modifying SymbolReaper object. For example, checkers can explicitly
@@ -437,6 +444,9 @@
   
   typedef CheckerFn
   CheckBranchConditionFunc;
+
+  typedef CheckerFn
+  CheckNewAllocatorFunc;
   
   typedef CheckerFn
   CheckDeadSymbolsFunc;
@@ -494,6 +504,8 @@
 
   void _registerForBranchCondition(CheckBranchConditionFunc checkfn);
 
+  void _registerForNewAllocator(CheckNewAllocatorFunc checkfn);
+
   void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn);
 
   void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn);
@@ -603,6 +615,8 @@
 
   std::vector BranchConditionCheckers;
 
+  std::vector NewAllocatorCheckers;
+
   std::vector LiveSymbolsCheckers;
 
   std::vector DeadSymbolsCheckers;
Index: test/Analysis/NewDelete-custom.cpp
===
--- test/Analysis/NewDelete-custom.cpp
+++ test/Analysis/NewDelete-custom.cpp
@@ -1,8 +1,10 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -fblocks -verify %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -DLEAKS=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DALLOCATOR_INLINING=1 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,unix.Malloc -std=c++11 -analyzer-config c++-allocator-inlining=true -DLEAKS=1 -DALLOCATOR_INLINING=1 -fblocks -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
-#ifndef LEAKS
+#if !LEAKS
 // expected-no-diagnostics
 #endif
 
@@ -26,7 +28,7 @@
 
   C *c3 = ::new C;
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'c3'}}
 #endif
 
@@ -37,7 +39,7 @@
 void testNewExprArray() {
   int *p = new int[0];
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
@@ -50,30 +52,30 @@
 void testNewExpr() {
   int *p = new int;
 }
-#ifdef LEAKS
+#if LEAKS && !ALLOCATOR_INLINING
 // expected-warning@-2{{Potential leak of memory pointed to by 'p'}}
 #endif
 
 
 //- Custom NoThrow placement operators
 void testOpNewNoThrow() {
   void *p = operator new(0, std::nothrow);
 }
-#ifdef 

[PATCH] D42208: Use an enum value instea of an string

2018-01-17 Thread Rafael Avila de Espindola via Phabricator via cfe-commits
espindola created this revision.
espindola added reviewers: rnk, rsmith.

The old StringSwitch use was  also broken. It assumed that a StringSwitch 
returns Optional instead of T and was missing a .Default.


https://reviews.llvm.org/D42208

Files:
  clang/include/clang/Frontend/CodeGenOptions.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Frontend/CodeGenOptions.cpp
  clang/lib/Frontend/CompilerInvocation.cpp

Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -330,15 +330,23 @@
   return "default";
 }
 
-static StringRef getRelocModel(ArgList , DiagnosticsEngine ) {
+static llvm::Reloc::Model getRelocModel(ArgList ,
+DiagnosticsEngine ) {
   if (Arg *A = Args.getLastArg(OPT_mrelocation_model)) {
 StringRef Value = A->getValue();
-if (Value == "static" || Value == "pic" || Value == "ropi" ||
-Value == "rwpi" || Value == "ropi-rwpi" || Value == "dynamic-no-pic")
-  return Value;
+auto RM = llvm::StringSwitch(Value)
+  .Case("static", llvm::Reloc::Static)
+  .Case("pic", llvm::Reloc::PIC_)
+  .Case("ropi", llvm::Reloc::ROPI)
+  .Case("rwpi", llvm::Reloc::RWPI)
+  .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
+  .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC)
+  .Default(None);
+if (RM.hasValue())
+  return *RM;
 Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value;
   }
-  return "pic";
+  return llvm::Reloc::PIC_;
 }
 
 /// \brief Create a new Regex instance out of the string value in \p RpassArg.
Index: clang/lib/Frontend/CodeGenOptions.cpp
===
--- clang/lib/Frontend/CodeGenOptions.cpp
+++ clang/lib/Frontend/CodeGenOptions.cpp
@@ -17,7 +17,7 @@
 #define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
 #include "clang/Frontend/CodeGenOptions.def"
 
-  RelocationModel = "pic";
+  RelocationModel = llvm::Reloc::PIC_;
   memcpy(CoverageVersion, "402*", 4);
 }
 
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -362,21 +362,6 @@
   return static_cast(CodeModel);
 }
 
-static llvm::Reloc::Model getRelocModel(const CodeGenOptions ) {
-  // Keep this synced with the equivalent code in
-  // lib/Frontend/CompilerInvocation.cpp
-  llvm::Optional RM;
-  RM = llvm::StringSwitch(CodeGenOpts.RelocationModel)
-  .Case("static", llvm::Reloc::Static)
-  .Case("pic", llvm::Reloc::PIC_)
-  .Case("ropi", llvm::Reloc::ROPI)
-  .Case("rwpi", llvm::Reloc::RWPI)
-  .Case("ropi-rwpi", llvm::Reloc::ROPI_RWPI)
-  .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC);
-  assert(RM.hasValue() && "invalid PIC model!");
-  return *RM;
-}
-
 static TargetMachine::CodeGenFileType getCodeGenFileType(BackendAction Action) {
   if (Action == Backend_EmitObj)
 return TargetMachine::CGFT_ObjectFile;
@@ -692,7 +677,7 @@
   Optional CM = getCodeModel(CodeGenOpts);
   std::string FeaturesStr =
   llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(), ",");
-  llvm::Reloc::Model RM = getRelocModel(CodeGenOpts);
+  llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;
   CodeGenOpt::Level OptLevel = getCGOptLevel(CodeGenOpts);
 
   llvm::TargetOptions Options;
@@ -1113,7 +1098,7 @@
   Conf.CPU = TOpts.CPU;
   Conf.CodeModel = getCodeModel(CGOpts);
   Conf.MAttrs = TOpts.Features;
-  Conf.RelocModel = getRelocModel(CGOpts);
+  Conf.RelocModel = CGOpts.RelocationModel;
   Conf.CGOptLevel = getCGOptLevel(CGOpts);
   initTargetOptions(Conf.Options, CGOpts, TOpts, LOpts, HeaderOpts);
   Conf.SampleProfile = std::move(SampleProfile);
Index: clang/include/clang/Frontend/CodeGenOptions.h
===
--- clang/include/clang/Frontend/CodeGenOptions.h
+++ clang/include/clang/Frontend/CodeGenOptions.h
@@ -16,6 +16,7 @@
 
 #include "clang/Basic/DebugInfoOptions.h"
 #include "clang/Basic/Sanitizers.h"
+#include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Regex.h"
 #include "llvm/Target/TargetOptions.h"
 #include 
@@ -167,7 +168,7 @@
   std::string SplitDwarfFile;
 
   /// The name of the relocation model to use.
-  std::string RelocationModel;
+  llvm::Reloc::Model RelocationModel;
 
   /// The thread model to use
   std::string ThreadModel;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322787 - [analyzer] operator new: Add a new checker callback, check::NewAllocator.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 15:46:13 2018
New Revision: 322787

URL: http://llvm.org/viewvc/llvm-project?rev=322787=rev
Log:
[analyzer] operator new: Add a new checker callback, check::NewAllocator.

The callback runs after operator new() and before the construction and allows
the checker to access the casted return value of operator new() (in the
sense of r322780) which is not available in the PostCall callback for the
allocator call.

Update MallocChecker to use the new callback instead of PostStmt,
which gets called after the constructor.

Differential Revision: https://reviews.llvm.org/D41406
rdar://problem/12180598

Added:
cfe/trunk/test/Analysis/new-ctor-malloc.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
cfe/trunk/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/NewDelete-custom.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h?rev=322787=322786=322787=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h Wed Jan 17 15:46:13 
2018
@@ -283,6 +283,22 @@ public:
   }
 };
 
+class NewAllocator {
+  template 
+  static void _checkNewAllocator(void *checker, const CXXNewExpr *NE,
+ SVal Target, CheckerContext ) {
+((const CHECKER *)checker)->checkNewAllocator(NE, Target, C);
+  }
+
+public:
+  template 
+  static void _register(CHECKER *checker, CheckerManager ) {
+mgr._registerForNewAllocator(
+CheckerManager::CheckNewAllocatorFunc(checker,
+  _checkNewAllocator));
+  }
+};
+
 class LiveSymbols {
   template 
   static void _checkLiveSymbols(void *checker, ProgramStateRef state,

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=322787=322786=322787=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Wed Jan 17 
15:46:13 2018
@@ -303,6 +303,13 @@ public:
  ExplodedNodeSet , ExplodedNode *Pred,
  ExprEngine );
 
+  /// \brief Run checkers between C++ operator new and constructor calls.
+  void runCheckersForNewAllocator(const CXXNewExpr *NE, SVal Target,
+  ExplodedNodeSet ,
+  ExplodedNode *Pred,
+  ExprEngine ,
+  bool wasInlined = false);
+
   /// \brief Run checkers for live symbols.
   ///
   /// Allows modifying SymbolReaper object. For example, checkers can 
explicitly
@@ -437,6 +444,9 @@ public:
   
   typedef CheckerFn
   CheckBranchConditionFunc;
+
+  typedef CheckerFn
+  CheckNewAllocatorFunc;
   
   typedef CheckerFn
   CheckDeadSymbolsFunc;
@@ -494,6 +504,8 @@ public:
 
   void _registerForBranchCondition(CheckBranchConditionFunc checkfn);
 
+  void _registerForNewAllocator(CheckNewAllocatorFunc checkfn);
+
   void _registerForLiveSymbols(CheckLiveSymbolsFunc checkfn);
 
   void _registerForDeadSymbols(CheckDeadSymbolsFunc checkfn);
@@ -603,6 +615,8 @@ private:
 
   std::vector BranchConditionCheckers;
 
+  std::vector NewAllocatorCheckers;
+
   std::vector LiveSymbolsCheckers;
 
   std::vector DeadSymbolsCheckers;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp?rev=322787=322786=322787=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CheckerDocumentation.cpp Wed Jan 17 
15:46:13 2018
@@ -42,6 +42,7 @@ class CheckerDocumentation : public Chec
check::PreCall,
check::PostCall,
check::BranchCondition,
+   check::NewAllocator,
check::Location,
check::Bind,
check::DeadSymbols,
@@ -126,6 +127,22 @@ public:
   /// 

[PATCH] D42043: c-index: CXString: fix MSAN read-past-end bug

2018-01-17 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added reviewers: akyrtzi, benlangmuir.
vsk added inline comments.



Comment at: tools/c-index-test/c-index-test.c:3268
 
-  filename = clang_getFileName(file);
-  index_data->main_filename = clang_getCString(filename);
-  clang_disposeString(filename);
+  index_data->main_filename = clang_getFileName(file);
 

This looks like a separate bug fix. Is it possible to separate the 
main_filename changes from this patch?



Comment at: tools/libclang/CXString.cpp:59
 CXString createEmpty() {
   CXString Str;
+  Str.Contents = (const void *) "";

Why shouldn't this be defined as createRef("")?



Comment at: tools/libclang/CXString.cpp:213
+  if (string.IsNullTerminated) {
+CString = (const char *) string.Contents;
+  } else {

Basic question: If a non-owning CXString is null-terminated, what provides the 
guarantee that the string is in fact valid when getCString() is called? Is the 
user of the C API responsible for ensuring the lifetime of the string is valid?



Comment at: tools/libclang/CXString.h:108
 
 #endif

Generally unrelated whitespace changes should be left out of patches.


Repository:
  rC Clang

https://reviews.llvm.org/D42043



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


r322783 - [ASTMatchers] Support generating docs for single-line matchers

2018-01-17 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Jan 17 15:14:49 2018
New Revision: 322783

URL: http://llvm.org/viewvc/llvm-project?rev=322783=rev
Log:
[ASTMatchers] Support generating docs for single-line matchers

clang-format likes this format. PR35989.

Modified:
cfe/trunk/docs/tools/dump_ast_matchers.py
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/tools/dump_ast_matchers.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/tools/dump_ast_matchers.py?rev=322783=322782=322783=diff
==
--- cfe/trunk/docs/tools/dump_ast_matchers.py (original)
+++ cfe/trunk/docs/tools/dump_ast_matchers.py Wed Jan 17 15:14:49 2018
@@ -237,7 +237,7 @@ def act_on_decl(declaration, comment, al
(?:,\s*([^\s,]+)\s*
   ,\s*([^\s,]+)\s*)?
(?:,\s*\d+\s*)?
-  \)\s*{\s*$""", declaration, flags=re.X)
+  \)\s*{""", declaration, flags=re.X)
 if m:
   p, n, result, name = m.groups()[0:4]
   args = m.groups()[4:]

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=322783=322782=322783=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Jan 17 15:14:49 2018
@@ -3581,9 +3581,7 @@ AST_POLYMORPHIC_MATCHER_P(parameterCount
 /// \code
 ///   void nope();
 /// \endcode
-AST_MATCHER(FunctionDecl, isNoReturn) {
-  return Node.isNoReturn();
-}
+AST_MATCHER(FunctionDecl, isNoReturn) { return Node.isNoReturn(); }
 
 /// \brief Matches the return type of a function declaration.
 ///


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


r322781 - [analyzer] operator new: Fix ambigious type name.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 15:03:25 2018
New Revision: 322781

URL: http://llvm.org/viewvc/llvm-project?rev=322781=rev
Log:
[analyzer] operator new: Fix ambigious type name.

Hopefully fixes an MSVC buildbot failure.

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

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=322781=322780=322781=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jan 17 15:03:25 2018
@@ -65,7 +65,7 @@ REGISTER_TRAIT_WITH_PROGRAMSTATE(Initial
 
 typedef llvm::ImmutableMap
-CXXNewAllocatorValuesTy;
+CXXNewAllocatorValuesMap;
 
 // Keeps track of return values of various operator new() calls between
 // evaluation of the inlined operator new(), through the constructor call,
@@ -75,7 +75,8 @@ typedef llvm::ImmutableMap

[PATCH] D41266: [analyzer] With c++-allocator-inlining, fix memory space for operator new pointers.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322780: [analyzer] operator new: Fix memory space for the 
returned region. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41266

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/NewDelete-checker-test.cpp
  test/Analysis/new-ctor-null.cpp

Index: test/Analysis/NewDelete-checker-test.cpp
===
--- test/Analysis/NewDelete-checker-test.cpp
+++ test/Analysis/NewDelete-checker-test.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -fblocks -verify %s
 // RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -fblocks -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDelete -std=c++11 -fblocks -analyzer-config c++-allocator-inlining=true -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,cplusplus.NewDeleteLeaks -DLEAKS -std=c++11 -fblocks -analyzer-config c++-allocator-inlining=true -verify %s
 #include "Inputs/system-header-simulator-cxx.h"
 
 typedef __typeof__(sizeof(int)) size_t;
Index: test/Analysis/new-ctor-null.cpp
===
--- test/Analysis/new-ctor-null.cpp
+++ test/Analysis/new-ctor-null.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *operator new(size_t size) throw() {
+  return nullptr;
+}
+void *operator new[](size_t size) throw() {
+  return nullptr;
+}
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void testArrays() {
+  S *s = new S[10]; // no-crash
+  s[0].x = 2; // expected-warning{{Dereference of null pointer}}
+}
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -479,8 +479,10 @@
 
   ExplodedNodeSet DstPostCall;
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
-  for (auto I : DstPreCall)
+  for (auto I : DstPreCall) {
+// FIXME: Provide evalCall for checkers?
 defaultEvalCall(CallBldr, I, *Call);
+  }
   // If the call is inlined, DstPostCall will be empty and we bail out now.
 
   // Store return value of operator new() for future use, until the actual
@@ -507,7 +509,6 @@
  *Call, *this);
 }
 
-
 void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
ExplodedNodeSet ) {
   // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
@@ -520,18 +521,8 @@
   SVal symVal = UnknownVal();
   FunctionDecl *FD = CNE->getOperatorNew();
 
-  bool IsStandardGlobalOpNewFunction = false;
-  if (FD && !isa(FD) && !FD->isVariadic()) {
-if (FD->getNumParams() == 2) {
-  QualType T = FD->getParamDecl(1)->getType();
-  if (const IdentifierInfo *II = T.getBaseTypeIdentifier())
-// NoThrow placement new behaves as a standard new.
-IsStandardGlobalOpNewFunction = II->getName().equals("nothrow_t");
-}
-else
-  // Placement forms are considered non-standard.
-  IsStandardGlobalOpNewFunction = (FD->getNumParams() == 1);
-  }
+  bool IsStandardGlobalOpNewFunction =
+  FD->isReplaceableGlobalAllocationFunction();
 
   ProgramStateRef State = Pred->getState();
 
@@ -587,9 +578,8 @@
   if (CNE->isArray()) {
 // FIXME: allocating an array requires simulating the constructors.
 // For now, just return a symbolicated region.
-if (!AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
-  const SubRegion *NewReg =
-  symVal.castAs().getRegionAs();
+if (const SubRegion *NewReg =
+dyn_cast_or_null(symVal.getAsRegion())) {
   QualType ObjTy = CNE->getType()->getAs()->getPointeeType();
   const ElementRegion *EleReg =
   getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
Index: lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
@@ -573,7 +573,19 @@
   QualType ResultTy = Call.getResultType();
   SValBuilder  = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
-  SVal R = SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+
+  // See if we need to conjure a heap pointer instead of
+  // a regular unknown pointer.
+  bool IsHeapPointer = false;
+  if (const auto *CNE = dyn_cast(E))
+if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
+  // FIXME: 

r322780 - [analyzer] operator new: Fix memory space for the returned region.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 14:58:35 2018
New Revision: 322780

URL: http://llvm.org/viewvc/llvm-project?rev=322780=rev
Log:
[analyzer] operator new: Fix memory space for the returned region.

Make sure that with c++-allocator-inlining=true we have the return value of
conservatively evaluated operator new() in the correct memory space (heap).
This is a regression/omission that worked well in c++-allocator-inlining=false.

Heap regions are superior to regular symbolic regions because they have
stricter aliasing constraints: heap regions do not alias each other or global
variables.

Differential Revision: https://reviews.llvm.org/D41266
rdar://problem/12180598

Added:
cfe/trunk/test/Analysis/new-ctor-null.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/NewDelete-checker-test.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=322780=322779=322780=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Wed Jan 17 14:58:35 2018
@@ -479,8 +479,10 @@ void ExprEngine::VisitCXXNewAllocatorCal
 
   ExplodedNodeSet DstPostCall;
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
-  for (auto I : DstPreCall)
+  for (auto I : DstPreCall) {
+// FIXME: Provide evalCall for checkers?
 defaultEvalCall(CallBldr, I, *Call);
+  }
   // If the call is inlined, DstPostCall will be empty and we bail out now.
 
   // Store return value of operator new() for future use, until the actual
@@ -507,7 +509,6 @@ void ExprEngine::VisitCXXNewAllocatorCal
  *Call, *this);
 }
 
-
 void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, ExplodedNode *Pred,
ExplodedNodeSet ) {
   // FIXME: Much of this should eventually migrate to CXXAllocatorCall.
@@ -520,18 +521,8 @@ void ExprEngine::VisitCXXNewExpr(const C
   SVal symVal = UnknownVal();
   FunctionDecl *FD = CNE->getOperatorNew();
 
-  bool IsStandardGlobalOpNewFunction = false;
-  if (FD && !isa(FD) && !FD->isVariadic()) {
-if (FD->getNumParams() == 2) {
-  QualType T = FD->getParamDecl(1)->getType();
-  if (const IdentifierInfo *II = T.getBaseTypeIdentifier())
-// NoThrow placement new behaves as a standard new.
-IsStandardGlobalOpNewFunction = II->getName().equals("nothrow_t");
-}
-else
-  // Placement forms are considered non-standard.
-  IsStandardGlobalOpNewFunction = (FD->getNumParams() == 1);
-  }
+  bool IsStandardGlobalOpNewFunction =
+  FD->isReplaceableGlobalAllocationFunction();
 
   ProgramStateRef State = Pred->getState();
 
@@ -587,9 +578,8 @@ void ExprEngine::VisitCXXNewExpr(const C
   if (CNE->isArray()) {
 // FIXME: allocating an array requires simulating the constructors.
 // For now, just return a symbolicated region.
-if (!AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
-  const SubRegion *NewReg =
-  symVal.castAs().getRegionAs();
+if (const SubRegion *NewReg =
+dyn_cast_or_null(symVal.getAsRegion())) {
   QualType ObjTy = CNE->getType()->getAs()->getPointeeType();
   const ElementRegion *EleReg =
   getStoreManager().GetElementZeroRegion(NewReg, ObjTy);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp?rev=322780=322779=322780=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp Wed Jan 17 
14:58:35 2018
@@ -573,7 +573,19 @@ ProgramStateRef ExprEngine::bindReturnVa
   QualType ResultTy = Call.getResultType();
   SValBuilder  = getSValBuilder();
   unsigned Count = currBldrCtx->blockCount();
-  SVal R = SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
+
+  // See if we need to conjure a heap pointer instead of
+  // a regular unknown pointer.
+  bool IsHeapPointer = false;
+  if (const auto *CNE = dyn_cast(E))
+if (CNE->getOperatorNew()->isReplaceableGlobalAllocationFunction()) {
+  // FIXME: Delegate this to evalCall in MallocChecker?
+  IsHeapPointer = true;
+}
+
+  SVal R = IsHeapPointer
+   ? SVB.getConjuredHeapSymbolVal(E, LCtx, Count)
+   : SVB.conjureSymbolVal(nullptr, E, LCtx, ResultTy, Count);
   return State->BindExpr(E, LCtx, R);
 }
 

Modified: cfe/trunk/test/Analysis/NewDelete-checker-test.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/NewDelete-checker-test.cpp?rev=322780=322779=322780=diff

r322779 - [Sema] Allow conversion between long double and __float128.

2018-01-17 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Wed Jan 17 14:56:57 2018
New Revision: 322779

URL: http://llvm.org/viewvc/llvm-project?rev=322779=rev
Log:
[Sema] Allow conversion between long double and __float128.

We should only ban this if long double is a double double. x86's 80 bit
long double is fine and supported by the backend.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/Sema/float128-ld-incompatibility.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=322779=322778=322779=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jan 17 14:56:57 2018
@@ -1092,13 +1092,12 @@ static bool unsupportedTypeConversion(co
   Float128AndLongDouble |= (LHSElemType == S.Context.LongDoubleTy &&
 RHSElemType == S.Context.Float128Ty);
 
-  /* We've handled the situation where __float128 and long double have the same
- representation. The only other allowable conversion is if long double is
- really just double.
-  */
+  // We've handled the situation where __float128 and long double have the same
+  // representation. We allow all conversions for all possible long double 
types
+  // except PPC's double double.
   return Float128AndLongDouble &&
-((S.Context.LongDoubleTy) !=
- ::APFloat::IEEEdouble());
+((S.Context.LongDoubleTy) ==
+ ::APFloat::PPCDoubleDouble());
 }
 
 typedef ExprResult PerformCastFn(Sema , Expr *operand, QualType toType);

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=322779=322778=322779=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jan 17 14:56:57 2018
@@ -1764,8 +1764,8 @@ static bool IsStandardConversion(Sema 
(FromType == S.Context.LongDoubleTy &&
 ToType == S.Context.Float128Ty));
   if (Float128AndLongDouble &&
-  ((S.Context.LongDoubleTy) !=
-   ::APFloat::IEEEdouble()))
+  ((S.Context.LongDoubleTy) ==
+   ::APFloat::PPCDoubleDouble()))
 return false;
 }
 // Floating point conversions (C++ 4.8).

Modified: cfe/trunk/test/Sema/float128-ld-incompatibility.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/float128-ld-incompatibility.cpp?rev=322779=322778=322779=diff
==
--- cfe/trunk/test/Sema/float128-ld-incompatibility.cpp (original)
+++ cfe/trunk/test/Sema/float128-ld-incompatibility.cpp Wed Jan 17 14:56:57 2018
@@ -1,10 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 \
 // RUN: -triple powerpc64le-unknown-linux-gnu -target-cpu pwr8 \
 // RUN: -target-feature +float128 %s
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -triple x86_64-unknown-linux-gnu 
-Wno-unused-value -Wno-parentheses %s
 
 __float128 qf();
 long double ldf();
 
+#ifdef __PPC__
 // FIXME: once operations between long double and __float128 are implemented 
for
 //targets where the types are different, these next two will change
 long double ld{qf()}; // expected-error {{cannot initialize a variable of type 
'long double' with an rvalue of type '__float128'}}
@@ -17,6 +19,7 @@ auto test1(__float128 q, long double ld)
 auto test2(long double a, __float128 b) -> decltype(a + b) { // expected-error 
{{invalid operands to binary expression ('long double' and '__float128')}}
   return a + b;  // expected-error {{invalid operands to binary expression 
('long double' and '__float128')}}
 }
+#endif
 
 void test3(bool b) {
   long double ld;


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


[PATCH] D41523: xmmintrin.h documentation fixes and updates

2018-01-17 Thread Douglas Yung via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322778: [DOXYGEN] Fix doxygen and content issues in 
xmmintrin.h (authored by dyung, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41523

Files:
  lib/Headers/xmmintrin.h

Index: lib/Headers/xmmintrin.h
===
--- lib/Headers/xmmintrin.h
+++ lib/Headers/xmmintrin.h
@@ -1011,6 +1011,8 @@
 /// \brief Compares two 32-bit float values in the low-order bits of both
 ///operands for equality and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS 
@@ -1022,7 +1024,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the
+///two lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comieq_ss(__m128 __a, __m128 __b)
 {
@@ -1033,6 +1036,8 @@
 ///operands to determine if the first operand is less than the second
 ///operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS 
@@ -1044,7 +1049,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the two
+/// lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comilt_ss(__m128 __a, __m128 __b)
 {
@@ -1055,6 +1061,8 @@
 ///operands to determine if the first operand is less than or equal to the
 ///second operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1065,7 +1073,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the two
+/// lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comile_ss(__m128 __a, __m128 __b)
 {
@@ -1076,6 +1085,8 @@
 ///operands to determine if the first operand is greater than the second
 ///operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1086,7 +1097,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the
+/// two lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comigt_ss(__m128 __a, __m128 __b)
 {
@@ -1097,6 +1109,8 @@
 ///operands to determine if the first operand is greater than or equal to
 ///the second operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1107,7 +1121,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the two
+///lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comige_ss(__m128 __a, __m128 __b)
 {
@@ -1118,6 +1133,8 @@
 ///operands to determine if the first operand is not equal to the second
 ///operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 1 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1128,7 +1145,8 @@
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the
+/// two lower 32-bit values is NaN, 1 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comineq_ss(__m128 __a, __m128 

r322778 - [DOXYGEN] Fix doxygen and content issues in xmmintrin.h

2018-01-17 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Wed Jan 17 14:53:15 2018
New Revision: 322778

URL: http://llvm.org/viewvc/llvm-project?rev=322778=rev
Log:
[DOXYGEN] Fix doxygen and content issues in xmmintrin.h

- Fix inaccurate instruction listings.
- Fix small issues in _mm_getcsr and _mm_setcsr.
- Fix description of NaN handling in comparison intrinsics.
- Fix inaccurate description of _mm_movemask_pi8.
- Fix inaccurate instruction mappings.
- Fix typos.
- Clarify wording on some descriptions.
- Fix bit ranges in return value.
- Fix typo in _mm_move_ms intrinsic instruction since it operates on 
singe-precision values, not double.
- This patch was made by Craig Flores

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


Modified:
cfe/trunk/lib/Headers/xmmintrin.h

Modified: cfe/trunk/lib/Headers/xmmintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/xmmintrin.h?rev=322778=322777=322778=diff
==
--- cfe/trunk/lib/Headers/xmmintrin.h (original)
+++ cfe/trunk/lib/Headers/xmmintrin.h Wed Jan 17 14:53:15 2018
@@ -1011,6 +1011,8 @@ _mm_cmpunord_ps(__m128 __a, __m128 __b)
 /// \brief Compares two 32-bit float values in the low-order bits of both
 ///operands for equality and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS 
@@ -1022,7 +1024,8 @@ _mm_cmpunord_ps(__m128 __a, __m128 __b)
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the
+///two lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comieq_ss(__m128 __a, __m128 __b)
 {
@@ -1033,6 +1036,8 @@ _mm_comieq_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is less than the second
 ///operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS 
@@ -1044,7 +1049,8 @@ _mm_comieq_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the two
+/// lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comilt_ss(__m128 __a, __m128 __b)
 {
@@ -1055,6 +1061,8 @@ _mm_comilt_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is less than or equal to the
 ///second operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1065,7 +1073,8 @@ _mm_comilt_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the two
+/// lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comile_ss(__m128 __a, __m128 __b)
 {
@@ -1076,6 +1085,8 @@ _mm_comile_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is greater than the second
 ///operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1086,7 +1097,8 @@ _mm_comile_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in the comparison.
-/// \returns An integer containing the comparison results.
+/// \returns An integer containing the comparison results. If either of the
+/// two lower 32-bit values is NaN, 0 is returned.
 static __inline__ int __DEFAULT_FN_ATTRS
 _mm_comigt_ss(__m128 __a, __m128 __b)
 {
@@ -1097,6 +1109,8 @@ _mm_comigt_ss(__m128 __a, __m128 __b)
 ///operands to determine if the first operand is greater than or equal to
 ///the second operand and returns the result of the comparison.
 ///
+///If either of the two lower 32-bit values is NaN, 0 is returned.
+///
 /// \headerfile 
 ///
 /// This intrinsic corresponds to the  VCOMISS / COMISS  instructions.
@@ -1107,7 +1121,8 @@ _mm_comigt_ss(__m128 __a, __m128 __b)
 /// \param __b
 ///A 128-bit vector of [4 x float]. The lower 32 bits of this operand are
 ///used in 

[PATCH] D41250: [analyzer] Model implied cast around operator new().

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322777: [analyzer] operator new: Model the cast of returned 
pointer into object type. (authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D41250

Files:
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-inlined.cpp

Index: test/Analysis/new-ctor-inlined.cpp
===
--- test/Analysis/new-ctor-inlined.cpp
+++ test/Analysis/new-ctor-inlined.cpp
@@ -38,3 +38,18 @@
   Sp *p = new Sp(new Sp(0));
   clang_analyzer_eval(p->p->p == 0); // expected-warning{{TRUE}}
 }
+
+void checkNewPOD() {
+  int *i = new int;
+  clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}
+  int *j = new int();
+  clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}
+  int *k = new int(5);
+  clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
+}
+
+void checkTrivialCopy() {
+  S s;
+  S *t = new S(s); // no-crash
+  clang_analyzer_eval(t->x == 1); // expected-warning{{TRUE}}
+}
Index: test/Analysis/new-ctor-conservative.cpp
===
--- test/Analysis/new-ctor-conservative.cpp
+++ test/Analysis/new-ctor-conservative.cpp
@@ -12,3 +12,18 @@
   S *s = new S;
   clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
 }
+
+void checkNewPOD() {
+  int *i = new int;
+  clang_analyzer_eval(*i == 0); // expected-warning{{UNKNOWN}}
+  int *j = new int();
+  clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}
+  int *k = new int(5);
+  clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}
+}
+
+void checkNewArray() {
+  S *s = new S[10];
+  // FIXME: Should be true once we inline array constructors.
+  clang_analyzer_eval(s[0].x == 1); // expected-warning{{UNKNOWN}}
+}
Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -119,9 +119,17 @@
 if (AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
   // TODO: Detect when the allocator returns a null pointer.
   // Constructor shall not be called in this case.
-  if (const MemRegion *MR =
-  getCXXNewAllocatorValue(State, CNE, LCtx).getAsRegion())
+  if (const SubRegion *MR = dyn_cast_or_null(
+  getCXXNewAllocatorValue(State, CNE, LCtx).getAsRegion())) {
+if (CNE->isArray()) {
+  // TODO: This code exists only to trigger the suppression for
+  // array constructors. In fact, we need to call the constructor
+  // for every allocated element, not just the first one!
+  return getStoreManager().GetElementZeroRegion(
+  MR, CNE->getType()->getPointeeType());
+}
 return MR;
+  }
 }
   } else if (auto *DS = dyn_cast(StmtElem->getStmt())) {
 if (const auto *Var = dyn_cast(DS->getSingleDecl())) {
@@ -473,12 +481,22 @@
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
   for (auto I : DstPreCall)
 defaultEvalCall(CallBldr, I, *Call);
+  // If the call is inlined, DstPostCall will be empty and we bail out now.
 
   // Store return value of operator new() for future use, until the actual
   // CXXNewExpr gets processed.
   ExplodedNodeSet DstPostValue;
   StmtNodeBuilder ValueBldr(DstPostCall, DstPostValue, *currBldrCtx);
   for (auto I : DstPostCall) {
+// FIXME: Because CNE serves as the "call site" for the allocator (due to
+// lack of a better expression in the AST), the conjured return value symbol
+// is going to be of the same type (C++ object pointer type). Technically
+// this is not correct because the operator new's prototype always says that
+// it returns a 'void *'. So we should change the type of the symbol,
+// and then evaluate the cast over the symbolic pointer from 'void *' to
+// the object pointer type. But without changing the symbol's type it
+// is breaking too much to evaluate the no-op symbolic cast over it, so we
+// skip it for now.
 ProgramStateRef State = I->getState();
 ValueBldr.generateNode(
 CNE, I,
@@ -564,25 +582,28 @@
 
   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
 
+  SVal Result = symVal;
+
   if (CNE->isArray()) {
 // FIXME: allocating an array requires simulating the constructors.
 // For now, just return a symbolicated region.
-const SubRegion *NewReg =
-symVal.castAs().getRegionAs();
-QualType ObjTy = CNE->getType()->getAs()->getPointeeType();
-const ElementRegion *EleReg =
-  getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
-State = State->BindExpr(CNE, Pred->getLocationContext(),
-

r322777 - [analyzer] operator new: Model the cast of returned pointer into object type.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 14:51:19 2018
New Revision: 322777

URL: http://llvm.org/viewvc/llvm-project?rev=322777=rev
Log:
[analyzer] operator new: Model the cast of returned pointer into object type.

According to [basic.stc.dynamic.allocation], the return type of any C++
overloaded operator new() is "void *". However, type of the new-expression
"new T()" and the type of "this" during construction of "T" are both "T *".

Hence an implicit cast, which is not present in the AST, needs to be performed
before the construction. This patch adds such cast in the case when the
allocator was indeed inlined. For now, in the case where the allocator was *not*
inlined we still use the same symbolic value (which is a pure SymbolicRegion of
type "T *") because it is consistent with how we represent the casts and causes
less surprise in the checkers after switching to the new behavior.

The better approach would be to represent that value as a cast over a
SymbolicRegion of type "void *", however we have technical difficulties
conjuring such region without any actual expression of type "void *" present in
the AST.

Differential Revision: https://reviews.llvm.org/D41250
rdar://problem/12180598

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/new-ctor-conservative.cpp
cfe/trunk/test/Analysis/new-ctor-inlined.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp?rev=322777=322776=322777=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp Wed Jan 17 14:51:19 2018
@@ -119,9 +119,17 @@ ExprEngine::getRegionForConstructedObjec
 if (AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
   // TODO: Detect when the allocator returns a null pointer.
   // Constructor shall not be called in this case.
-  if (const MemRegion *MR =
-  getCXXNewAllocatorValue(State, CNE, LCtx).getAsRegion())
+  if (const SubRegion *MR = dyn_cast_or_null(
+  getCXXNewAllocatorValue(State, CNE, LCtx).getAsRegion())) {
+if (CNE->isArray()) {
+  // TODO: This code exists only to trigger the suppression for
+  // array constructors. In fact, we need to call the constructor
+  // for every allocated element, not just the first one!
+  return getStoreManager().GetElementZeroRegion(
+  MR, CNE->getType()->getPointeeType());
+}
 return MR;
+  }
 }
   } else if (auto *DS = dyn_cast(StmtElem->getStmt())) {
 if (const auto *Var = dyn_cast(DS->getSingleDecl())) {
@@ -473,12 +481,22 @@ void ExprEngine::VisitCXXNewAllocatorCal
   StmtNodeBuilder CallBldr(DstPreCall, DstPostCall, *currBldrCtx);
   for (auto I : DstPreCall)
 defaultEvalCall(CallBldr, I, *Call);
+  // If the call is inlined, DstPostCall will be empty and we bail out now.
 
   // Store return value of operator new() for future use, until the actual
   // CXXNewExpr gets processed.
   ExplodedNodeSet DstPostValue;
   StmtNodeBuilder ValueBldr(DstPostCall, DstPostValue, *currBldrCtx);
   for (auto I : DstPostCall) {
+// FIXME: Because CNE serves as the "call site" for the allocator (due to
+// lack of a better expression in the AST), the conjured return value 
symbol
+// is going to be of the same type (C++ object pointer type). Technically
+// this is not correct because the operator new's prototype always says 
that
+// it returns a 'void *'. So we should change the type of the symbol,
+// and then evaluate the cast over the symbolic pointer from 'void *' to
+// the object pointer type. But without changing the symbol's type it
+// is breaking too much to evaluate the no-op symbolic cast over it, so we
+// skip it for now.
 ProgramStateRef State = I->getState();
 ValueBldr.generateNode(
 CNE, I,
@@ -564,16 +582,20 @@ void ExprEngine::VisitCXXNewExpr(const C
 
   StmtNodeBuilder Bldr(Pred, Dst, *currBldrCtx);
 
+  SVal Result = symVal;
+
   if (CNE->isArray()) {
 // FIXME: allocating an array requires simulating the constructors.
 // For now, just return a symbolicated region.
-const SubRegion *NewReg =
-symVal.castAs().getRegionAs();
-QualType ObjTy = CNE->getType()->getAs()->getPointeeType();
-const ElementRegion *EleReg =
-  getStoreManager().GetElementZeroRegion(NewReg, ObjTy);
-State = State->BindExpr(CNE, Pred->getLocationContext(),
-loc::MemRegionVal(EleReg));
+if (!AMgr.getAnalyzerOptions().mayInlineCXXAllocator()) {
+  const SubRegion *NewReg =
+  symVal.castAs().getRegionAs();
+  

[libcxx] r322776 - Fix nodiscard failure tests on compilers w/o -verify.

2018-01-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jan 17 14:48:09 2018
New Revision: 322776

URL: http://llvm.org/viewvc/llvm-project?rev=322776=rev
Log:
Fix nodiscard failure tests on compilers w/o -verify.

Previously .fail.cpp tests for nodiscard were run with -Wunused-result
being a warning, not an error, when the compiler didn't support -verify.

When -verify isn't enabled this change judiciously adds -Werror=unused-result
when to only the failure tests containing the // expected-error string for 
nodiscard.

As a drive-by change, this patch also adds a missing // UNSUPPORTED: c++2a to
a test which was only supposed to run in C++ <= 11.

Modified:

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
libcxx/trunk/utils/libcxx/test/format.py

Modified: 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp?rev=322776=322775=322776=diff
==
--- 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.array/sized_delete_array11.pass.cpp
 Wed Jan 17 14:48:09 2018
@@ -12,7 +12,7 @@
 // Note that sized delete operator definitions below are simply ignored
 // when sized deallocation is not supported, e.g., prior to C++14.
 
-// UNSUPPORTED: c++14, c++17
+// UNSUPPORTED: c++14, c++17, c++2a
 // UNSUPPORTED: sanitizer-new-delete
 
 #include 

Modified: libcxx/trunk/utils/libcxx/test/format.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/utils/libcxx/test/format.py?rev=322776=322775=322776=diff
==
--- libcxx/trunk/utils/libcxx/test/format.py (original)
+++ libcxx/trunk/utils/libcxx/test/format.py Wed Jan 17 14:48:09 2018
@@ -242,7 +242,18 @@ class LibcxxTestFormat(object):
 test_cxx.useWarnings()
 if '-Wuser-defined-warnings' in test_cxx.warning_flags:
 test_cxx.warning_flags += ['-Wno-error=user-defined-warnings']
-
+else:
+# We still need to enable certain warnings on .fail.cpp test when
+# -verify isn't enabled. Such as -Werror=unused-result. However,
+# we don't want it enabled too liberally, which might incorrectly
+# allow unrelated failure tests to 'pass'.
+#
+# Therefore, we check if the test was expected to fail because of
+# nodiscard before enabling it
+test_str = "ignoring return value of function declared with " \
+  + "'nodiscard' attribute"
+if test_str in contents:
+test_cxx.flags += ['-Werror=unused-result']
 cmd, out, err, rc = test_cxx.compile(source_path, out=os.devnull)
 expected_rc = 0 if use_verify else 1
 if rc == expected_rc:


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


[PATCH] D40925: Add option -fkeep-static-consts

2018-01-17 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

OK. My concern is that users need to use `__attribute__((used))` or something 
more robust if they want SVN identifiers to reliably appear in the output. 
Adding this flag just creates a trap that will fail once they turn on `-O2`. 
I'd rather not have it in the interface to avoid that user confusion.


https://reviews.llvm.org/D40925



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


[PATCH] D40939: [analyzer] NFC: Avoid element regions of void type.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322775: [analyzer] NFC: Forbid array elements of void type. 
(authored by dergachev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D40939

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp


Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -962,7 +962,10 @@
   CXXThisRegion(const PointerType *thisPointerTy,
 const StackArgumentsSpaceRegion *sReg)
   : TypedValueRegion(sReg, CXXThisRegionKind),
-ThisPointerTy(thisPointerTy) {}
+ThisPointerTy(thisPointerTy) {
+assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
+   "Invalid region type!");
+  }
 
   static void ProfileRegion(llvm::FoldingSetNodeID ,
 const PointerType *PT,
@@ -1076,6 +1079,8 @@
 assert((!Idx.getAs() ||
 Idx.castAs().getValue().isSigned()) &&
"The index must be signed");
+assert(!elementType.isNull() && !elementType->isVoidType() &&
+   "Invalid region type!");
   }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer. Note that arithmetic on void pointers is a GCC 
extension.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));
Index: lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -2209,9 +2209,17 @@
 ProgramStateRef state = Node->getState();
 
 if (IsGLValueLike) {
-  SVal V = state->getLValue(A->getType(),
-  state->getSVal(Idx, LCtx),
-  state->getSVal(Base, LCtx));
+  QualType T = A->getType();
+
+  // One of the forbidden LValue types! We still need to have sensible
+  // symbolic locations to represent this stuff. Note that arithmetic on
+  // void pointers is a GCC extension.
+  if (T->isVoidType())
+T = getContext().CharTy;
+
+  SVal V = state->getLValue(T,
+state->getSVal(Idx, LCtx),
+state->getSVal(Base, LCtx));
   Bldr.generateNode(A, Node, state->BindExpr(A, LCtx, V), nullptr,
   ProgramPoint::PostLValueKind);
 } else if (IsVectorType) {


Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -962,7 +962,10 @@
   CXXThisRegion(const PointerType *thisPointerTy,
 const StackArgumentsSpaceRegion *sReg)
   : TypedValueRegion(sReg, CXXThisRegionKind),
-ThisPointerTy(thisPointerTy) {}
+ThisPointerTy(thisPointerTy) {
+assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
+   "Invalid region type!");
+  }
 
   static void ProfileRegion(llvm::FoldingSetNodeID ,
 const PointerType *PT,
@@ -1076,6 +1079,8 @@
 assert((!Idx.getAs() ||
 Idx.castAs().getValue().isSigned()) &&
"The index must be signed");
+assert(!elementType.isNull() && !elementType->isVoidType() &&
+   "Invalid region type!");
   }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,
Index: lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -988,6 +988,12 @@
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer. Note that arithmetic on void pointers is a GCC extension.
+if (elementType->isVoidType())
+  

r322775 - [analyzer] NFC: Forbid array elements of void type.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 14:40:36 2018
New Revision: 322775

URL: http://llvm.org/viewvc/llvm-project?rev=322775=rev
Log:
[analyzer] NFC: Forbid array elements of void type.

Represent the symbolic value for results of pointer arithmetic on void pointers
in a different way: instead of making void-typed element regions, make
char-typed element regions.

Add an assertion that ensures that no void-typed regions are ever constructed.

This is a refactoring of internals that should not immediately affect
the analyzer's (default) behavior.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=322775=322774=322775=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Wed 
Jan 17 14:40:36 2018
@@ -962,7 +962,10 @@ class CXXThisRegion : public TypedValueR
   CXXThisRegion(const PointerType *thisPointerTy,
 const StackArgumentsSpaceRegion *sReg)
   : TypedValueRegion(sReg, CXXThisRegionKind),
-ThisPointerTy(thisPointerTy) {}
+ThisPointerTy(thisPointerTy) {
+assert(ThisPointerTy->getPointeeType()->getAsCXXRecordDecl() &&
+   "Invalid region type!");
+  }
 
   static void ProfileRegion(llvm::FoldingSetNodeID ,
 const PointerType *PT,
@@ -1076,6 +1079,8 @@ class ElementRegion : public TypedValueR
 assert((!Idx.getAs() ||
 Idx.castAs().getValue().isSigned()) &&
"The index must be signed");
+assert(!elementType.isNull() && !elementType->isVoidType() &&
+   "Invalid region type!");
   }
 
   static void ProfileRegion(llvm::FoldingSetNodeID& ID, QualType elementType,

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=322775=322774=322775=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jan 17 14:40:36 2018
@@ -2209,9 +2209,17 @@ void ExprEngine::VisitArraySubscriptExpr
 ProgramStateRef state = Node->getState();
 
 if (IsGLValueLike) {
-  SVal V = state->getLValue(A->getType(),
-  state->getSVal(Idx, LCtx),
-  state->getSVal(Base, LCtx));
+  QualType T = A->getType();
+
+  // One of the forbidden LValue types! We still need to have sensible
+  // symbolic locations to represent this stuff. Note that arithmetic on
+  // void pointers is a GCC extension.
+  if (T->isVoidType())
+T = getContext().CharTy;
+
+  SVal V = state->getLValue(T,
+state->getSVal(Idx, LCtx),
+state->getSVal(Base, LCtx));
   Bldr.generateNode(A, Node, state->BindExpr(A, LCtx, V), nullptr,
   ProgramPoint::PostLValueKind);
 } else if (IsVectorType) {

Modified: cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp?rev=322775=322774=322775=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp Wed Jan 17 14:40:36 
2018
@@ -988,6 +988,12 @@ SVal SimpleSValBuilder::evalBinOpLN(Prog
 elementType = resultTy->getPointeeType();
 }
 
+// Represent arithmetic on void pointers as arithmetic on char pointers.
+// It is fine when a TypedValueRegion of char value type represents
+// a void pointer. Note that arithmetic on void pointers is a GCC 
extension.
+if (elementType->isVoidType())
+  elementType = getContext().CharTy;
+
 if (Optional indexV = index.getAs()) {
   return loc::MemRegionVal(MemMgr.getElementRegion(elementType, *indexV,
superR, getContext()));


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


[PATCH] D40560: [analyzer] Get construction into `operator new` running in simple cases.

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322774: [analyzer] operator new: Use the correct region for 
the constructor. (authored by dergachev, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D40560?vs=130249=130276#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D40560

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  cfe/trunk/test/Analysis/inline.cpp
  cfe/trunk/test/Analysis/new-ctor-conservative.cpp
  cfe/trunk/test/Analysis/new-ctor-inlined.cpp
  cfe/trunk/test/Analysis/new-ctor-recursive.cpp
  cfe/trunk/test/Analysis/new-ctor-symbolic.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -642,8 +642,8 @@
   const CXXConstructExpr *findDirectConstructorForCurrentCFGElement();
 
   /// For a CXXConstructExpr, walk forward in the current CFG block to find the
-  /// CFGElement for the DeclStmt or CXXInitCtorInitializer for which is
-  /// directly constructed by this constructor. Returns None if the current
+  /// CFGElement for the DeclStmt or CXXInitCtorInitializer or CXXNewExpr which
+  /// is directly constructed by this constructor. Returns None if the current
   /// constructor expression did not directly construct into an existing
   /// region.
   Optional findElementDirectlyInitializedByCurrentConstructor();
@@ -655,6 +655,30 @@
   /// if not.
   const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
  ExplodedNode *Pred);
+
+  /// Store the region returned by operator new() so that the constructor
+  /// that follows it knew what location to initialize. The value should be
+  /// cleared once the respective CXXNewExpr CFGStmt element is processed.
+  static ProgramStateRef
+  setCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+  const LocationContext *CallerLC, SVal V);
+
+  /// Retrieve the location returned by the current operator new().
+  static SVal
+  getCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+  const LocationContext *CallerLC);
+
+  /// Clear the location returned by the respective operator new(). This needs
+  /// to be done as soon as CXXNewExpr CFG block is evaluated.
+  static ProgramStateRef
+  clearCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+const LocationContext *CallerLC);
+
+  /// Check if all allocator values are clear for the given context range
+  /// (including FromLC, not including ToLC). This is useful for assertions.
+  static bool areCXXNewAllocatorValuesClear(ProgramStateRef State,
+const LocationContext *FromLC,
+const LocationContext *ToLC);
 };
 
 /// Traits for storing the call processing policy inside GDM.
Index: cfe/trunk/test/Analysis/new-ctor-inlined.cpp
===
--- cfe/trunk/test/Analysis/new-ctor-inlined.cpp
+++ cfe/trunk/test/Analysis/new-ctor-inlined.cpp
@@ -0,0 +1,40 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *conjure();
+void exit(int);
+
+void *operator new(size_t size) throw() {
+  void *x = conjure();
+  if (x == 0)
+exit(1);
+  return x;
+}
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void checkNewAndConstructorInlining() {
+  S *s = new S;
+  // Check that the symbol for 's' is not dying.
+  clang_analyzer_eval(s != 0); // expected-warning{{TRUE}}
+  // Check that bindings are correct (and also not dying).
+  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
+}
+
+struct Sp {
+  Sp *p;
+  Sp(Sp *p): p(p) {}
+  ~Sp() {}
+};
+
+void checkNestedNew() {
+  Sp *p = new Sp(new Sp(0));
+  clang_analyzer_eval(p->p->p == 0); // expected-warning{{TRUE}}
+}
Index: cfe/trunk/test/Analysis/new-ctor-conservative.cpp
===
--- cfe/trunk/test/Analysis/new-ctor-conservative.cpp
+++ cfe/trunk/test/Analysis/new-ctor-conservative.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+
+struct S {
+  int x;
+  S() : x(1) {}
+  ~S() {}
+};
+
+void 

r322774 - [analyzer] operator new: Use the correct region for the constructor.

2018-01-17 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jan 17 14:34:23 2018
New Revision: 322774

URL: http://llvm.org/viewvc/llvm-project?rev=322774=rev
Log:
[analyzer] operator new: Use the correct region for the constructor.

The -analyzer-config c++-allocator-inlining experimental option allows the
analyzer to reason about C++ operator new() similarly to how it reasons about
regular functions. In this mode, operator new() is correctly called before the
construction of an object, with the help of a special CFG element.

However, the subsequent construction of the object was still not performed into
the region of memory returned by operator new(). The patch fixes it.

Passing the value from operator new() to the constructor and then to the
new-expression itself was tricky because operator new() has no call site of its
own in the AST. The new expression itself is not a good call site because it
has an incorrect type (operator new() returns 'void *', while the new expression
is a pointer to the allocated object type). Additionally, lifetime of the new
expression in the environment makes it unsuitable for passing the value.
For that reason, an additional program state trait is introduced to keep track
of the return value.

Finally this patch relaxes restrictions on the memory region class that are
required for inlining the constructor. This change affects the old mode as well
(c++-allocator-inlining=false) and seems safe because these restrictions were
an overkill compared to the actual problems observed.

Differential Revision: https://reviews.llvm.org/D40560
rdar://problem/12180598

Added:
cfe/trunk/test/Analysis/new-ctor-conservative.cpp
cfe/trunk/test/Analysis/new-ctor-inlined.cpp
cfe/trunk/test/Analysis/new-ctor-recursive.cpp
cfe/trunk/test/Analysis/new-ctor-symbolic.cpp
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
cfe/trunk/test/Analysis/inline.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h?rev=322774=322773=322774=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h Wed 
Jan 17 14:34:23 2018
@@ -642,8 +642,8 @@ private:
   const CXXConstructExpr *findDirectConstructorForCurrentCFGElement();
 
   /// For a CXXConstructExpr, walk forward in the current CFG block to find the
-  /// CFGElement for the DeclStmt or CXXInitCtorInitializer for which is
-  /// directly constructed by this constructor. Returns None if the current
+  /// CFGElement for the DeclStmt or CXXInitCtorInitializer or CXXNewExpr which
+  /// is directly constructed by this constructor. Returns None if the current
   /// constructor expression did not directly construct into an existing
   /// region.
   Optional findElementDirectlyInitializedByCurrentConstructor();
@@ -655,6 +655,30 @@ private:
   /// if not.
   const MemRegion *getRegionForConstructedObject(const CXXConstructExpr *CE,
  ExplodedNode *Pred);
+
+  /// Store the region returned by operator new() so that the constructor
+  /// that follows it knew what location to initialize. The value should be
+  /// cleared once the respective CXXNewExpr CFGStmt element is processed.
+  static ProgramStateRef
+  setCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+  const LocationContext *CallerLC, SVal V);
+
+  /// Retrieve the location returned by the current operator new().
+  static SVal
+  getCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+  const LocationContext *CallerLC);
+
+  /// Clear the location returned by the respective operator new(). This needs
+  /// to be done as soon as CXXNewExpr CFG block is evaluated.
+  static ProgramStateRef
+  clearCXXNewAllocatorValue(ProgramStateRef State, const CXXNewExpr *CNE,
+const LocationContext *CallerLC);
+
+  /// Check if all allocator values are clear for the given context range
+  /// (including FromLC, not including ToLC). This is useful for assertions.
+  static bool areCXXNewAllocatorValuesClear(ProgramStateRef State,
+const LocationContext *FromLC,
+const LocationContext *ToLC);
 };
 
 /// Traits for storing the call processing policy inside GDM.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=322774=322773=322774=diff

[PATCH] D41271: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Ana Pazos via Phabricator via cfe-commits
apazos added a comment.

Committed R322769


Repository:
  rL LLVM

https://reviews.llvm.org/D41271



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


r322769 - [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Ana Pazos via cfe-commits
Author: apazos
Date: Wed Jan 17 14:09:58 2018
New Revision: 322769

URL: http://llvm.org/viewvc/llvm-project?rev=322769=rev
Log:
[RISCV] Propagate -mabi and -march values to GNU assembler.

When using -fno-integrated-as flag, the gnu assembler produces code
with some default march/mabi which later causes linker failure due
to incompatible mabi/march.

In this patch we explicitly propagate -mabi and -march flags to the
GNU assembler.

In this patch we explicitly propagate -mabi and -march flags to the GNU 
assembler.

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

Added:

cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
cfe/trunk/test/Driver/riscv-gnutools.c
Modified:
cfe/trunk/lib/Driver/ToolChains/Gnu.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Gnu.cpp?rev=322769=322768=322769=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp Wed Jan 17 14:09:58 2018
@@ -629,6 +629,18 @@ void tools::gnutools::Assembler::Constru
   ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple(;
 break;
   }
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64: {
+StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
+CmdArgs.push_back("-mabi");
+CmdArgs.push_back(ABIName.data());
+if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+  StringRef MArch = A->getValue();
+  CmdArgs.push_back("-march");
+  CmdArgs.push_back(MArch.data());
+}
+break;
+  }
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");

Added: 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as?rev=322769=auto
==
--- 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
 (added)
+++ 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
 Wed Jan 17 14:09:58 2018
@@ -0,0 +1 @@
+#!/bin/true

Added: cfe/trunk/test/Driver/riscv-gnutools.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/riscv-gnutools.c?rev=322769=auto
==
--- cfe/trunk/test/Driver/riscv-gnutools.c (added)
+++ cfe/trunk/test/Driver/riscv-gnutools.c Wed Jan 17 14:09:58 2018
@@ -0,0 +1,14 @@
+// Check gnutools are invoked with propagated values for -mabi and -march.
+
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32 %s
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: -march=rv32g --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32-MARCH-G %s
+
+// MABI-ILP32: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32"
+// MABI-ILP32-MARCH-G: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32" "-march" "rv32g"
+


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


[PATCH] D41271: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Ana Pazos via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322769: [RISCV] Propagate -mabi and -march values to GNU 
assembler. (authored by apazos, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41271?vs=129981=130272#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41271

Files:
  cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
  
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
  cfe/trunk/test/Driver/riscv-gnutools.c


Index: 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
===
--- 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
+++ 
cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
@@ -0,0 +1 @@
+#!/bin/true
Index: cfe/trunk/test/Driver/riscv-gnutools.c
===
--- cfe/trunk/test/Driver/riscv-gnutools.c
+++ cfe/trunk/test/Driver/riscv-gnutools.c
@@ -0,0 +1,14 @@
+// Check gnutools are invoked with propagated values for -mabi and -march.
+
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32 %s
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: -march=rv32g --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32-MARCH-G %s
+
+// MABI-ILP32: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32"
+// MABI-ILP32-MARCH-G: 
"{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as"
 "-mabi" "ilp32" "-march" "rv32g"
+
Index: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
@@ -629,6 +629,18 @@
   ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple(;
 break;
   }
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64: {
+StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
+CmdArgs.push_back("-mabi");
+CmdArgs.push_back(ABIName.data());
+if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+  StringRef MArch = A->getValue();
+  CmdArgs.push_back("-march");
+  CmdArgs.push_back(MArch.data());
+}
+break;
+  }
   case llvm::Triple::sparc:
   case llvm::Triple::sparcel: {
 CmdArgs.push_back("-32");


Index: cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
===
--- cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
+++ cfe/trunk/test/Driver/Inputs/multilib_riscv_linux_sdk/riscv64-unknown-linux-gnu/bin/as
@@ -0,0 +1 @@
+#!/bin/true
Index: cfe/trunk/test/Driver/riscv-gnutools.c
===
--- cfe/trunk/test/Driver/riscv-gnutools.c
+++ cfe/trunk/test/Driver/riscv-gnutools.c
@@ -0,0 +1,14 @@
+// Check gnutools are invoked with propagated values for -mabi and -march.
+
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32 %s
+// RUN: %clang -target riscv32-linux-unknown-elf -fno-integrated-as \
+// RUN: -march=rv32g --gcc-toolchain=%S/Inputs/multilib_riscv_linux_sdk \
+// RUN: --sysroot=%S/Inputs/multilib_riscv_linux_sdk/sysroot %s -### \
+// RUN: 2>&1 | FileCheck -check-prefix=MABI-ILP32-MARCH-G %s
+
+// MABI-ILP32: "{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as" "-mabi" "ilp32"
+// MABI-ILP32-MARCH-G: "{{.*}}/Inputs/multilib_riscv_linux_sdk/lib/gcc/riscv64-unknown-linux-gnu/7.2.0/../../../../riscv64-unknown-linux-gnu/bin{{/|}}as" "-mabi" "ilp32" "-march" "rv32g"
+
Index: cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
===
--- cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
+++ cfe/trunk/lib/Driver/ToolChains/Gnu.cpp
@@ -629,6 +629,18 @@
   ppc::getPPCAsmModeForCPU(getCPUName(Args, getToolChain().getTriple(;
 break;
   }
+  case llvm::Triple::riscv32:
+  case llvm::Triple::riscv64: {
+StringRef ABIName = riscv::getRISCVABI(Args, getToolChain().getTriple());
+CmdArgs.push_back("-mabi");
+ 

[libcxxabi] r322768 - Fix standalone test-suite run.

2018-01-17 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Wed Jan 17 14:07:09 2018
New Revision: 322768

URL: http://llvm.org/viewvc/llvm-project?rev=322768=rev
Log:
Fix standalone test-suite run.

This patch updates libc++abi's HandleOutOfTreeLLVM.cmake to match
libc++'s -- and more importantly, to fix a bug where llvm-lit wasn't
found/created when libc++abi was built out-of-tree. This prevented
the test suite from running.

Modified:
libcxxabi/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
libcxxabi/trunk/test/CMakeLists.txt

Modified: libcxxabi/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake?rev=322768=322767=322768=diff
==
--- libcxxabi/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake (original)
+++ libcxxabi/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake Wed Jan 17 14:07:09 
2018
@@ -107,14 +107,22 @@ macro(configure_out_of_tree_llvm)
 set(LLVM_ENABLE_SPHINX OFF)
   endif()
 
-  # Required LIT Configuration 
-  # Define the default arguments to use with 'lit', and an option for the user
-  # to override.
-  set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
-  if (MSVC OR XCODE)
-set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
+  # In a standalone build, we don't have llvm to automatically generate the
+  # llvm-lit script for us.  So we need to provide an explicit directory that
+  # the configurator should write the script into.
+  set(LLVM_LIT_OUTPUT_DIR "${libcxxabi_BINARY_DIR}/bin")
+
+  if (LLVM_INCLUDE_TESTS)
+# Required LIT Configuration 

+# Define the default arguments to use with 'lit', and an option for the 
user
+# to override.
+set(LLVM_EXTERNAL_LIT "${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py")
+set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
+if (MSVC OR XCODE)
+  set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
+endif()
+set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for 
lit")
   endif()
-  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for 
lit")
 
   # Required doc configuration
   if (LLVM_ENABLE_SPHINX)

Modified: libcxxabi/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/test/CMakeLists.txt?rev=322768=322767=322768=diff
==
--- libcxxabi/trunk/test/CMakeLists.txt (original)
+++ libcxxabi/trunk/test/CMakeLists.txt Wed Jan 17 14:07:09 2018
@@ -24,10 +24,6 @@ set(LIBCXXABI_EXECUTOR "None" CACHE STRI
 "Executor to use when running tests.")
 
 set(AUTO_GEN_COMMENT "## Autogenerated by libcxxabi configuration.\n# Do not 
edit!")
-configure_file(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
-  @ONLY)
 
 if (LIBCXXABI_ENABLE_SHARED)
   set(LIBCXXABI_TEST_DEPS cxxabi_shared)
@@ -46,6 +42,11 @@ if (NOT LIBCXXABI_STANDALONE_BUILD)
   endif()
 endif()
 
+
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
+
 add_lit_testsuite(check-cxxabi "Running libcxxabi tests"
   ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS ${LIBCXXABI_TEST_DEPS}


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


[PATCH] D41963: [clang-tidy] Adding Fuchsia checker for thread local storage.

2018-01-17 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett abandoned this revision.
juliehockett added a comment.

After some discussion, we decided that the false positive risk for non-kernel 
code isn't worth the check.


https://reviews.llvm.org/D41963



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


[PATCH] D41271: [RISCV] Propagate -mabi and -march values to GNU assembler.

2018-01-17 Thread Ana Pazos via Phabricator via cfe-commits
apazos added a comment.

Thanks for the clarifications Alex. 
No need to fix  these known issues right now.
I will proceed with checking in this change.


https://reviews.llvm.org/D41271



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


[libclc] r322763 - rootn: Port from amd_builtins

2018-01-17 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Jan 17 13:22:14 2018
New Revision: 322763

URL: http://llvm.org/viewvc/llvm-project?rev=322763=rev
Log:
rootn: Port from amd_builtins

Passes piglit on turks and carrizo
fp64 passes ctx on carrizo

v2: fix formatting
check fp32 denormal support at runtime

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/rootn.h
libclc/trunk/generic/include/clc/math/rootn.inc
libclc/trunk/generic/include/math/clc_rootn.h
libclc/trunk/generic/include/math/clc_rootn.inc
libclc/trunk/generic/lib/math/clc_rootn.cl
libclc/trunk/generic/lib/math/rootn.cl
libclc/trunk/generic/lib/math/rootn.inc
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322763=322762=322763=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Jan 17 13:22:14 2018
@@ -91,6 +91,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/rootn.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/rootn.h?rev=322763=auto
==
--- libclc/trunk/generic/include/clc/math/rootn.h (added)
+++ libclc/trunk/generic/include/clc/math/rootn.h Wed Jan 17 13:22:14 2018
@@ -0,0 +1,3 @@
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/clc/math/rootn.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/rootn.inc?rev=322763=auto
==
--- libclc/trunk/generic/include/clc/math/rootn.inc (added)
+++ libclc/trunk/generic/include/clc/math/rootn.inc Wed Jan 17 13:22:14 2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE rootn(__CLC_GENTYPE a, __CLC_INTN b);

Added: libclc/trunk/generic/include/math/clc_rootn.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_rootn.h?rev=322763=auto
==
--- libclc/trunk/generic/include/math/clc_rootn.h (added)
+++ libclc/trunk/generic/include/math/clc_rootn.h Wed Jan 17 13:22:14 2018
@@ -0,0 +1,3 @@
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/math/clc_rootn.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_rootn.inc?rev=322763=auto
==
--- libclc/trunk/generic/include/math/clc_rootn.inc (added)
+++ libclc/trunk/generic/include/math/clc_rootn.inc Wed Jan 17 13:22:14 2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_rootn(__CLC_GENTYPE a, __CLC_INTN 
b);

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322763=322762=322763=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jan 17 13:22:14 2018
@@ -144,6 +144,8 @@ math/clc_pown.cl
 math/pown.cl
 math/clc_powr.cl
 math/powr.cl
+math/clc_rootn.cl
+math/rootn.cl
 math/sin.cl
 math/sincos.cl
 math/sincos_helpers.cl

Added: libclc/trunk/generic/lib/math/clc_rootn.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_rootn.cl?rev=322763=auto
==
--- libclc/trunk/generic/lib/math/clc_rootn.cl (added)
+++ libclc/trunk/generic/lib/math/clc_rootn.cl Wed Jan 17 13:22:14 2018
@@ -0,0 +1,379 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF 

[libclc] r322761 - pown: Port from amd_builtins

2018-01-17 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Jan 17 13:22:03 2018
New Revision: 322761

URL: http://llvm.org/viewvc/llvm-project?rev=322761=rev
Log:
pown: Port from amd_builtins

Passes piglit on turks and carrizo
fp64 passes CTS on carrizo

v2: fix formatting
check fp32 denormal support at runtime

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/pown.inc
libclc/trunk/generic/include/math/clc_pown.h
libclc/trunk/generic/include/math/clc_pown.inc
libclc/trunk/generic/lib/math/clc_pown.cl
libclc/trunk/generic/lib/math/pown.inc
Modified:
libclc/trunk/generic/include/clc/math/pown.h
libclc/trunk/generic/lib/SOURCES
libclc/trunk/generic/lib/math/pown.cl

Modified: libclc/trunk/generic/include/clc/math/pown.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/pown.h?rev=322761=322760=322761=diff
==
--- libclc/trunk/generic/include/clc/math/pown.h (original)
+++ libclc/trunk/generic/include/clc/math/pown.h Wed Jan 17 13:22:03 2018
@@ -1,24 +1,3 @@
-#define _CLC_POWN_INTRINSIC "llvm.powi"
-
-#define _CLC_POWN_DECL(GENTYPE, INTTYPE) \
-  _CLC_OVERLOAD _CLC_DECL GENTYPE pown(GENTYPE x, INTTYPE y);
-
-#define _CLC_VECTOR_POWN_DECL(GENTYPE, INTTYPE) \
-  _CLC_POWN_DECL(GENTYPE##2, INTTYPE##2)  \
-  _CLC_POWN_DECL(GENTYPE##3, INTTYPE##3)  \
-  _CLC_POWN_DECL(GENTYPE##4, INTTYPE##4)  \
-  _CLC_POWN_DECL(GENTYPE##8, INTTYPE##8)  \
-  _CLC_POWN_DECL(GENTYPE##16, INTTYPE##16)
-
-_CLC_OVERLOAD float pown(float x, int y) __asm(_CLC_POWN_INTRINSIC ".f32");
-
-_CLC_VECTOR_POWN_DECL(float, int)
-
-#ifdef cl_khr_fp64
-_CLC_OVERLOAD double pown(double x, int y) __asm(_CLC_POWN_INTRINSIC ".f64");
-_CLC_VECTOR_POWN_DECL(double, int)
-#endif
-
-#undef _CLC_POWN_INTRINSIC
-#undef _CLC_POWN_DECL
-#undef _CLC_VECTOR_POWN_DECL
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/clc/math/pown.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/pown.inc?rev=322761=auto
==
--- libclc/trunk/generic/include/clc/math/pown.inc (added)
+++ libclc/trunk/generic/include/clc/math/pown.inc Wed Jan 17 13:22:03 2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE pown(__CLC_GENTYPE a, __CLC_INTN b);

Added: libclc/trunk/generic/include/math/clc_pown.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_pown.h?rev=322761=auto
==
--- libclc/trunk/generic/include/math/clc_pown.h (added)
+++ libclc/trunk/generic/include/math/clc_pown.h Wed Jan 17 13:22:03 2018
@@ -0,0 +1,3 @@
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY

Added: libclc/trunk/generic/include/math/clc_pown.inc
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_pown.inc?rev=322761=auto
==
--- libclc/trunk/generic/include/math/clc_pown.inc (added)
+++ libclc/trunk/generic/include/math/clc_pown.inc Wed Jan 17 13:22:03 2018
@@ -0,0 +1 @@
+_CLC_OVERLOAD _CLC_DECL __CLC_GENTYPE __clc_pown(__CLC_GENTYPE a, __CLC_INTN 
b);

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322761=322760=322761=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jan 17 13:22:03 2018
@@ -140,6 +140,7 @@ math/clc_nextafter.cl
 math/nextafter.cl
 math/clc_pow.cl
 math/pow.cl
+math/clc_pown.cl
 math/pown.cl
 math/sin.cl
 math/sincos.cl

Added: libclc/trunk/generic/lib/math/clc_pown.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_pown.cl?rev=322761=auto
==
--- libclc/trunk/generic/lib/math/clc_pown.cl (added)
+++ libclc/trunk/generic/lib/math/clc_pown.cl Wed Jan 17 13:22:03 2018
@@ -0,0 +1,380 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT 

[libclc] r322762 - powr: Port from amd_builtins

2018-01-17 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Jan 17 13:22:06 2018
New Revision: 322762

URL: http://llvm.org/viewvc/llvm-project?rev=322762=rev
Log:
powr: Port from amd_builtins

Passes piglit on turks and carrizo
fp64 passes cts on carrizo

v2: fix formatting
check fp32 denormal support at runtime

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/clc/math/powr.h
libclc/trunk/generic/include/math/clc_powr.h
libclc/trunk/generic/lib/math/clc_powr.cl
libclc/trunk/generic/lib/math/powr.cl
Modified:
libclc/trunk/generic/include/clc/clc.h
libclc/trunk/generic/lib/SOURCES

Modified: libclc/trunk/generic/include/clc/clc.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/clc.h?rev=322762=322761=322762=diff
==
--- libclc/trunk/generic/include/clc/clc.h (original)
+++ libclc/trunk/generic/include/clc/clc.h Wed Jan 17 13:22:06 2018
@@ -89,6 +89,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 

Added: libclc/trunk/generic/include/clc/math/powr.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/powr.h?rev=322762=auto
==
--- libclc/trunk/generic/include/clc/math/powr.h (added)
+++ libclc/trunk/generic/include/clc/math/powr.h Wed Jan 17 13:22:06 2018
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION powr
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Added: libclc/trunk/generic/include/math/clc_powr.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_powr.h?rev=322762=auto
==
--- libclc/trunk/generic/include/math/clc_powr.h (added)
+++ libclc/trunk/generic/include/math/clc_powr.h Wed Jan 17 13:22:06 2018
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION __clc_powr
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322762=322761=322762=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jan 17 13:22:06 2018
@@ -142,6 +142,8 @@ math/clc_pow.cl
 math/pow.cl
 math/clc_pown.cl
 math/pown.cl
+math/clc_powr.cl
+math/powr.cl
 math/sin.cl
 math/sincos.cl
 math/sincos_helpers.cl

Added: libclc/trunk/generic/lib/math/clc_powr.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_powr.cl?rev=322762=auto
==
--- libclc/trunk/generic/lib/math/clc_powr.cl (added)
+++ libclc/trunk/generic/lib/math/clc_powr.cl Wed Jan 17 13:22:06 2018
@@ -0,0 +1,391 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+
+#include "config.h"
+#include "math.h"
+#include "tables.h"
+#include "../clcmacro.h"
+
+// compute pow using log and exp
+// x^y = exp(y * log(x))
+//
+// we take care not to lose precision in the intermediate steps
+//
+// When computing log, calculate it in splits,
+//
+// r = f * (p_invead + p_inv_tail)
+// r = rh + rt
+//
+// calculate log polynomial using r, in end addition, do
+// poly = poly + ((rh-r) + rt)
+//
+// lth = -r
+// ltt = ((xexp * log2_t) - poly) + logT
+// lt = lth + ltt
+//
+// lh = (xexp * log2_h) + logH
+// l = lh + lt
+//
+// Calculate final log answer as gh and gt,
+// gh = l & higher-half bits
+// gt = (((ltt - (lt - lth)) + ((lh - l) + lt)) + (l - gh))
+//
+// yh = y & higher-half bits
+// yt = y - yh
+//
+// Before entering computation of exp,
+// vs = ((yt*gt + yt*gh) + yh*gt)
+// v = vs + yh*gh
+// vt = 

[libclc] r322760 - pow: Port from amd_builtins

2018-01-17 Thread Jan Vesely via cfe-commits
Author: jvesely
Date: Wed Jan 17 13:21:35 2018
New Revision: 322760

URL: http://llvm.org/viewvc/llvm-project?rev=322760=rev
Log:
pow: Port from amd_builtins

Passes piglit on turks and carrizo
fp64 passes CTS on carrizo

v2: fix formatting
check fp32 denormal support at runtime

Reviewer: Jeroen Ketema 
Signed-off-by: Jan Vesely 

Added:
libclc/trunk/generic/include/math/clc_pow.h
libclc/trunk/generic/lib/math/clc_pow.cl
libclc/trunk/generic/lib/math/clc_sw_binary.inc
libclc/trunk/generic/lib/math/pow.cl
Modified:
libclc/trunk/generic/include/clc/math/pow.h
libclc/trunk/generic/lib/SOURCES
libclc/trunk/generic/lib/math/tables.cl
libclc/trunk/generic/lib/math/tables.h

Modified: libclc/trunk/generic/include/clc/math/pow.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/math/pow.h?rev=322760=322759=322760=diff
==
--- libclc/trunk/generic/include/clc/math/pow.h (original)
+++ libclc/trunk/generic/include/clc/math/pow.h Wed Jan 17 13:21:35 2018
@@ -1,6 +1,5 @@
-#undef pow
-#define pow __clc_pow
-
-#define __CLC_FUNCTION __clc_pow
-#define __CLC_INTRINSIC "llvm.pow"
-#include 
+#define __CLC_FUNCTION pow
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Added: libclc/trunk/generic/include/math/clc_pow.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/math/clc_pow.h?rev=322760=auto
==
--- libclc/trunk/generic/include/math/clc_pow.h (added)
+++ libclc/trunk/generic/include/math/clc_pow.h Wed Jan 17 13:21:35 2018
@@ -0,0 +1,5 @@
+#define __CLC_FUNCTION __clc_pow
+#define __CLC_BODY 
+#include 
+#undef __CLC_BODY
+#undef __CLC_FUNCTION

Modified: libclc/trunk/generic/lib/SOURCES
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/SOURCES?rev=322760=322759=322760=diff
==
--- libclc/trunk/generic/lib/SOURCES (original)
+++ libclc/trunk/generic/lib/SOURCES Wed Jan 17 13:21:35 2018
@@ -138,6 +138,8 @@ math/native_tan.cl
 math/tables.cl
 math/clc_nextafter.cl
 math/nextafter.cl
+math/clc_pow.cl
+math/pow.cl
 math/pown.cl
 math/sin.cl
 math/sincos.cl

Added: libclc/trunk/generic/lib/math/clc_pow.cl
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/lib/math/clc_pow.cl?rev=322760=auto
==
--- libclc/trunk/generic/lib/math/clc_pow.cl (added)
+++ libclc/trunk/generic/lib/math/clc_pow.cl Wed Jan 17 13:21:35 2018
@@ -0,0 +1,408 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to 
deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include 
+
+#include "config.h"
+#include "math.h"
+#include "tables.h"
+#include "../clcmacro.h"
+
+/*
+ compute pow using log and exp
+ x^y = exp(y * log(x))
+
+ we take care not to lose precision in the intermediate steps
+
+ When computing log, calculate it in splits,
+
+ r = f * (p_invead + p_inv_tail)
+ r = rh + rt
+
+ calculate log polynomial using r, in end addition, do
+ poly = poly + ((rh-r) + rt)
+
+ lth = -r
+ ltt = ((xexp * log2_t) - poly) + logT
+ lt = lth + ltt
+
+ lh = (xexp * log2_h) + logH
+ l = lh + lt
+
+ Calculate final log answer as gh and gt,
+ gh = l & higher-half bits
+ gt = (((ltt - (lt - lth)) + ((lh - l) + lt)) + (l - gh))
+
+ yh = y & higher-half bits
+ yt = y - yh
+
+ Before entering computation of exp,
+ vs = ((yt*gt + yt*gh) + yh*gt)
+ v = vs + yh*gh
+ vt = ((yh*gh - v) + vs)
+
+ In calculation of exp, add vt to r that is used for poly
+ At the end of exp, do
+ expT * poly) + expT) + expH*poly) + expH)
+*/
+
+_CLC_DEF _CLC_OVERLOAD float __clc_pow(float x, float y)
+{
+
+int ix = as_int(x);
+int ax = ix & EXSIGNBIT_SP32;
+int xpos = ix 

[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE322759: [clang-tidy] Adding Fuchsia checker for trailing 
returns (authored by juliehockett, committed by ).

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D42116

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/TrailingReturnCheck.cpp
  clang-tidy/fuchsia/TrailingReturnCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-trailing-return.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-trailing-return.cpp

Index: test/clang-tidy/fuchsia-trailing-return.cpp
===
--- test/clang-tidy/fuchsia-trailing-return.cpp
+++ test/clang-tidy/fuchsia-trailing-return.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s fuchsia-trailing-return %t
+
+int add_one(const int arg) { return arg; }
+
+auto get_add_one() -> int (*)(const int) {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this type of declaration
+  // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
+  return add_one;
+}
+
+auto lambda = [](double x, double y) {return x + y;};
+
+auto lambda2 = [](double x, double y) -> double {return x + y;};
+
+int main() {
+  get_add_one()(5);
+  return 0;
+}
+
+template 
+auto fn(const T1 , const T2 ) -> decltype(lhs + rhs) {
+  return lhs + rhs;
+}
Index: clang-tidy/fuchsia/TrailingReturnCheck.cpp
===
--- clang-tidy/fuchsia/TrailingReturnCheck.cpp
+++ clang-tidy/fuchsia/TrailingReturnCheck.cpp
@@ -0,0 +1,56 @@
+//===--- TrailingReturnCheck.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 "TrailingReturnCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace ast_matchers {
+
+const internal::VariadicDynCastAllOfMatcher decltypeType;
+
+} // namespace ast_matchers
+
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+  return Node.getType()->castAs()->hasTrailingReturn();
+}
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+
+  // Requires C++11 or later.
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  // Functions that have trailing returns are disallowed, except for those
+  // using decltype specifiers and lambda with otherwise unutterable
+  // return types.
+  Finder->addMatcher(
+  functionDecl(allOf(hasTrailingReturn(),
+ unless(anyOf(returns(decltypeType()),
+  hasParent(cxxRecordDecl(isLambda()))
+  .bind("decl"),
+  this);
+}
+
+void TrailingReturnCheck::check(const MatchFinder::MatchResult ) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(),
+ "a trailing return type is disallowed for this type of declaration");
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
Index: clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "DefaultArgumentsCheck.h"
 #include "OverloadedOperatorCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
+#include "TrailingReturnCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -31,6 +32,8 @@
 "fuchsia-overloaded-operator");
 CheckFactories.registerCheck(
 "fuchsia-statically-constructed-objects");
+CheckFactories.registerCheck(
+"fuchsia-trailing-return");
 CheckFactories.registerCheck(
 "fuchsia-virtual-inheritance");
   }
Index: clang-tidy/fuchsia/TrailingReturnCheck.h
===
--- clang-tidy/fuchsia/TrailingReturnCheck.h
+++ clang-tidy/fuchsia/TrailingReturnCheck.h
@@ -0,0 +1,37 @@
+//===--- TrailingReturnCheck.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_FUCHSIA_TRAILING_RETURN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// 

[clang-tools-extra] r322759 - [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Julie Hockett via cfe-commits
Author: juliehockett
Date: Wed Jan 17 13:18:15 2018
New Revision: 322759

URL: http://llvm.org/viewvc/llvm-project?rev=322759=rev
Log:
[clang-tidy] Adding Fuchsia checker for trailing returns

Adds a check to the Fuchsia module to warn if a function has a trailing
return.

See https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md for
reference.

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

Added:
clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-trailing-return.rst
clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt?rev=322759=322758=322759=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt Wed Jan 17 
13:18:15 2018
@@ -5,6 +5,7 @@ add_clang_library(clangTidyFuchsiaModule
   FuchsiaTidyModule.cpp
   OverloadedOperatorCheck.cpp
   StaticallyConstructedObjectsCheck.cpp
+  TrailingReturnCheck.cpp
   VirtualInheritanceCheck.cpp
 
   LINK_LIBS

Modified: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp?rev=322759=322758=322759=diff
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp Wed Jan 17 
13:18:15 2018
@@ -13,6 +13,7 @@
 #include "DefaultArgumentsCheck.h"
 #include "OverloadedOperatorCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
+#include "TrailingReturnCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -31,6 +32,8 @@ public:
 "fuchsia-overloaded-operator");
 CheckFactories.registerCheck(
 "fuchsia-statically-constructed-objects");
+CheckFactories.registerCheck(
+"fuchsia-trailing-return");
 CheckFactories.registerCheck(
 "fuchsia-virtual-inheritance");
   }

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp?rev=322759=auto
==
--- clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp Wed Jan 
17 13:18:15 2018
@@ -0,0 +1,56 @@
+//===--- TrailingReturnCheck.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 "TrailingReturnCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace ast_matchers {
+
+const internal::VariadicDynCastAllOfMatcher decltypeType;
+
+} // namespace ast_matchers
+
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+  return Node.getType()->castAs()->hasTrailingReturn();
+}
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+
+  // Requires C++11 or later.
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  // Functions that have trailing returns are disallowed, except for those
+  // using decltype specifiers and lambda with otherwise unutterable
+  // return types.
+  Finder->addMatcher(
+  functionDecl(allOf(hasTrailingReturn(),
+ unless(anyOf(returns(decltypeType()),
+  hasParent(cxxRecordDecl(isLambda()))
+  .bind("decl"),
+  this);
+}
+
+void TrailingReturnCheck::check(const MatchFinder::MatchResult ) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(),
+ "a trailing return type is disallowed for this type of declaration");
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang

Added: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
URL: 

[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322759: [clang-tidy] Adding Fuchsia checker for trailing 
returns (authored by juliehockett, committed by ).
Herald added subscribers: llvm-commits, klimek.

Changed prior to commit:
  https://reviews.llvm.org/D42116?vs=130242=130261#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42116

Files:
  clang-tools-extra/trunk/clang-tidy/fuchsia/CMakeLists.txt
  clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
  clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/fuchsia-trailing-return.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst
  clang-tools-extra/trunk/test/clang-tidy/fuchsia-trailing-return.cpp

Index: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.cpp
@@ -0,0 +1,56 @@
+//===--- TrailingReturnCheck.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 "TrailingReturnCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace ast_matchers {
+
+const internal::VariadicDynCastAllOfMatcher decltypeType;
+
+} // namespace ast_matchers
+
+namespace tidy {
+namespace fuchsia {
+
+AST_MATCHER(FunctionDecl, hasTrailingReturn) {
+  return Node.getType()->castAs()->hasTrailingReturn();
+}
+
+void TrailingReturnCheck::registerMatchers(MatchFinder *Finder) {
+
+  // Requires C++11 or later.
+  if (!getLangOpts().CPlusPlus11)
+return;
+
+  // Functions that have trailing returns are disallowed, except for those
+  // using decltype specifiers and lambda with otherwise unutterable
+  // return types.
+  Finder->addMatcher(
+  functionDecl(allOf(hasTrailingReturn(),
+ unless(anyOf(returns(decltypeType()),
+  hasParent(cxxRecordDecl(isLambda()))
+  .bind("decl"),
+  this);
+}
+
+void TrailingReturnCheck::check(const MatchFinder::MatchResult ) {
+  if (const auto *D = Result.Nodes.getNodeAs("decl"))
+diag(D->getLocStart(),
+ "a trailing return type is disallowed for this type of declaration");
+}
+
+} // namespace fuchsia
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/FuchsiaTidyModule.cpp
@@ -13,6 +13,7 @@
 #include "DefaultArgumentsCheck.h"
 #include "OverloadedOperatorCheck.h"
 #include "StaticallyConstructedObjectsCheck.h"
+#include "TrailingReturnCheck.h"
 #include "VirtualInheritanceCheck.h"
 
 using namespace clang::ast_matchers;
@@ -31,6 +32,8 @@
 "fuchsia-overloaded-operator");
 CheckFactories.registerCheck(
 "fuchsia-statically-constructed-objects");
+CheckFactories.registerCheck(
+"fuchsia-trailing-return");
 CheckFactories.registerCheck(
 "fuchsia-virtual-inheritance");
   }
Index: clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
+++ clang-tools-extra/trunk/clang-tidy/fuchsia/TrailingReturnCheck.h
@@ -0,0 +1,37 @@
+//===--- TrailingReturnCheck.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_FUCHSIA_TRAILING_RETURN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Functions that have trailing returns are disallowed, except for those 
+/// using decltype specifiers and lambda with otherwise unutterable 
+/// return types.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-trailing-return.html
+class TrailingReturnCheck : public 

[PATCH] D42155: [analyzer] introduce getSVal(Stmt *) helper on ExplodedNode, make sure the helper is used consistently

2018-01-17 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322753: [analyzer] introduce getSVal(Stmt *) helper on 
ExplodedNode, make sure the… (authored by george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42155?vs=130079=130252#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42155

Files:
  examples/analyzer-plugin/MainCallChecker.cpp
  include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
  lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
  lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
  lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
  lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
  lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
  lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
  lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
  lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
  lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
  lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
  lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
  lib/StaticAnalyzer/Checkers/MallocChecker.cpp
  lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
  lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp
  lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
  lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
  lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
  lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
  lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
  lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
  lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
  lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
  lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  lib/StaticAnalyzer/Checkers/ValistChecker.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/CheckerContext.cpp
  lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Index: lib/StaticAnalyzer/Core/CheckerContext.cpp
===
--- lib/StaticAnalyzer/Core/CheckerContext.cpp
+++ lib/StaticAnalyzer/Core/CheckerContext.cpp
@@ -20,9 +20,8 @@
 using namespace ento;
 
 const FunctionDecl *CheckerContext::getCalleeDecl(const CallExpr *CE) const {
-  ProgramStateRef State = getState();
   const Expr *Callee = CE->getCallee();
-  SVal L = State->getSVal(Callee, Pred->getLocationContext());
+  SVal L = Pred->getSVal(Callee);
   return L.getAsFunctionDecl();
 }
 
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -235,7 +235,7 @@
 
 // Check the return value.
 ProgramStateRef State = Node->getState();
-SVal RetVal = State->getSVal(S, Node->getLocationContext());
+SVal RetVal = Node->getSVal(S);
 
 // Handle cases where a reference is returned and then immediately used.
 if (cast(S)->isGLValue())
@@ -717,7 +717,7 @@
   if (VR) {
 // See if we can get the BlockVarRegion.
 ProgramStateRef State = StoreSite->getState();
-SVal V = State->getSVal(S, PS->getLocationContext());
+SVal V = StoreSite->getSVal(S);
 if (const BlockDataRegion *BDR =
   dyn_cast_or_null(V.getAsRegion())) {
   if (const VarRegion *OriginalR = BDR->getOriginalRegion(VR)) {
@@ -1104,7 +1104,7 @@
   if (Inner && ExplodedGraph::isInterestingLValueExpr(Inner)) {
 const ExplodedNode *LVNode = findNodeForExpression(N, Inner);
 ProgramStateRef LVState = LVNode->getState();
-SVal LVal = LVState->getSVal(Inner, LVNode->getLocationContext());
+SVal LVal = LVNode->getSVal(Inner);
 
 const MemRegion *RR = getLocationRegionIfReference(Inner, N);
 bool LVIsNull = LVState->isNull(LVal).isConstrainedTrue();
@@ -1123,7 +1123,7 @@
 // If the LVal is null, check if we are dealing with null reference.
 // For those, we want to track the location of the reference.
 const MemRegion *R = (RR && LVIsNull) ? RR :
-LVState->getSVal(Inner, LVNode->getLocationContext()).getAsRegion();
+LVNode->getSVal(Inner).getAsRegion();
 
 if (R) {
   // Mark both the variable region and its contents as interesting.
@@ -1203,7 +1203,7 @@
 return nullptr;
   if (const Expr *Receiver = ME->getInstanceReceiver()) 

r322753 - [analyzer] introduce getSVal(Stmt *) helper on ExplodedNode, make sure the helper is used consistently

2018-01-17 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Jan 17 12:27:29 2018
New Revision: 322753

URL: http://llvm.org/viewvc/llvm-project?rev=322753=rev
Log:
[analyzer] introduce getSVal(Stmt *) helper on ExplodedNode, make sure the 
helper is used consistently

In most cases using
`N->getState()->getSVal(E, N->getLocationContext())`
is ugly, verbose, and also opens up more surface area for bugs if an
inconsistent location context is used.

This patch introduces a helper on an exploded node, and ensures
consistent usage of either `ExplodedNode::getSVal` or
`CheckContext::getSVal` across the codebase.
As a result, a large number of redundant lines is removed.

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

Modified:
cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h
cfe/trunk/lib/StaticAnalyzer/Checkers/BasicObjCFoundationChecks.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DeleteWithNonVirtualDtorChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DivZeroChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/FixedAddressChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/IteratorChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MacOSKeychainAPIChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/NullabilityChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCAtSyncChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCContainersChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ObjCSelfInitChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PointerArithChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PointerSubChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/PthreadLockChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UndefBranchChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UndefCapturedBlockVarChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UndefResultChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ValistChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp

Modified: cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp?rev=322753=322752=322753=diff
==
--- cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp (original)
+++ cfe/trunk/examples/analyzer-plugin/MainCallChecker.cpp Wed Jan 17 12:27:29 
2018
@@ -16,10 +16,8 @@ public:
 } // end anonymous namespace
 
 void MainCallChecker::checkPreStmt(const CallExpr *CE, CheckerContext ) 
const {
-  const ProgramStateRef state = C.getState();
-  const LocationContext *LC = C.getLocationContext();
   const Expr *Callee = CE->getCallee();
-  const FunctionDecl *FD = state->getSVal(Callee, LC).getAsFunctionDecl();
+  const FunctionDecl *FD = C.getSVal(Callee).getAsFunctionDecl();
 
   if (!FD)
 return;

Modified: 
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h?rev=322753=322752=322753=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h 
Wed Jan 17 12:27:29 2018
@@ -193,7 +193,7 @@ public:
 
   /// \brief Get the value of arbitrary expressions at this point in the path.
   SVal getSVal(const Stmt *S) const {
-return getState()->getSVal(S, getLocationContext());
+return Pred->getSVal(S);
   }
 
   /// \brief Returns true if the value of \p E is greater than or equal to \p


[PATCH] D42140: [analyzer] Make isSubRegionOf reflexive

2018-01-17 Thread George Karpenkov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC322752: [analyzer] Make isSubRegionOf reflexive (authored by 
george.karpenkov, committed by ).
Herald added a subscriber: cfe-commits.

Repository:
  rC Clang

https://reviews.llvm.org/D42140

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
  lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/StaticAnalyzer/Core/ProgramState.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp


Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -103,6 +103,7 @@
   const MemRegion *getBaseRegion() const;
 
   /// Check if the region is a subregion of the given region.
+  /// Each region is a subregion of itself.
   virtual bool isSubRegionOf(const MemRegion *R) const;
 
   const MemRegion *StripCasts(bool StripBaseCasts = true) const;
Index: lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -1838,7 +1838,7 @@
 const MemRegion *ArgReg = Call->getArgSVal(Idx).getAsRegion();
 
 // Are we tracking the argument or its subregion?
-if ( !ArgReg || (ArgReg != R && !R->isSubRegionOf(ArgReg->StripCasts(
+if ( !ArgReg || !R->isSubRegionOf(ArgReg->StripCasts()))
   continue;
 
 // Check the function parameter type.
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -871,7 +871,7 @@
 
 } else if (NextKey.hasSymbolicOffset()) {
   const MemRegion *Base = NextKey.getConcreteOffsetRegion();
-  if (Top->isSubRegionOf(Base)) {
+  if (Top->isSubRegionOf(Base) && Top != Base) {
 // Case 3: The next key is symbolic and we just changed something 
within
 // its concrete region. We don't know if the binding is still valid, so
 // we'll be conservative and include it.
@@ -881,7 +881,7 @@
   } else if (const SubRegion *BaseSR = dyn_cast(Base)) {
 // Case 4: The next key is symbolic, but we changed a known
 // super-region. In this case the binding is certainly included.
-if (Top == Base || BaseSR->isSubRegionOf(Top))
+if (BaseSR->isSubRegionOf(Top))
   if (isCompatibleWithFields(NextKey, FieldsInSymbolicSubregions))
 Bindings.push_back(*I);
   }
Index: lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- lib/StaticAnalyzer/Core/MemRegion.cpp
+++ lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -103,15 +103,15 @@
 
//===--===//
 
 bool SubRegion::isSubRegionOf(const MemRegion* R) const {
-  const MemRegion* r = getSuperRegion();
-  while (r != nullptr) {
+  const MemRegion* r = this;
+  do {
 if (r == R)
   return true;
 if (const SubRegion* sr = dyn_cast(r))
   r = sr->getSuperRegion();
 else
   break;
-  }
+  } while (r != nullptr);
   return false;
 }
 
Index: lib/StaticAnalyzer/Core/ProgramState.cpp
===
--- lib/StaticAnalyzer/Core/ProgramState.cpp
+++ lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -781,8 +781,7 @@
   // complete. For example, this would not currently identify
   // overlapping fields in a union as tainted. To identify this we can
   // check for overlapping/nested byte offsets.
-  if (Kind == I.second &&
-  (R == I.first || R->isSubRegionOf(I.first)))
+  if (Kind == I.second && R->isSubRegionOf(I.first))
 return true;
 }
   }
Index: lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
@@ -101,8 +101,6 @@
const MemRegion *Region) {
   if (!Region)
 return State;
-  // Note: The isSubRegionOf function is not reflexive.
-  State = State->remove(Region);
   for (auto  : State->get()) {
 if (E.first->isSubRegionOf(Region))
   State = State->remove(E.first);


Index: include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
===
--- include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
@@ -103,6 +103,7 @@
   const 

[PATCH] D40560: [analyzer] Get construction into `operator new` running in simple cases.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 130249.
NoQ added a comment.

Remove pointer casts from the newly added symbolic index test, because once we 
properly perform the cast of the allocated value (as in 
https://reviews.llvm.org/D41250), our solver would blow up.


https://reviews.llvm.org/D40560

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/inline.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-inlined.cpp
  test/Analysis/new-ctor-recursive.cpp
  test/Analysis/new-ctor-symbolic.cpp

Index: test/Analysis/new-ctor-symbolic.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-symbolic.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+void clang_analyzer_warnOnDeadSymbol(int);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+int conjure();
+void exit(int);
+
+struct S {
+  S() {}
+  ~S() {}
+
+  static S buffer[1000];
+
+  // This operator allocates stuff within the buffer. Additionally, it never
+  // places anything at the beginning of the buffer.
+  void *operator new(size_t size) {
+int i = conjure();
+if (i == 0)
+  exit(1);
+// Let's see if the symbol dies before new-expression is evaluated.
+// It shouldn't.
+clang_analyzer_warnOnDeadSymbol(i);
+return buffer + i;
+  }
+};
+
+void testIndexLiveness() {
+  S *s = new S();
+  clang_analyzer_eval(s == S::buffer); // expected-warning{{FALSE}}
+} // expected-warning{{SYMBOL DEAD}}
Index: test/Analysis/new-ctor-recursive.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-recursive.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+void clang_analyzer_dump(int);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *conjure();
+void exit(int);
+
+struct S;
+
+S *global_s;
+
+// Recursive operator kinda placement new.
+void *operator new(size_t size, S *place);
+
+enum class ConstructionKind : char {
+  Garbage,
+  Recursive
+};
+
+struct S {
+public:
+  int x;
+  S(): x(1) {}
+  S(int y): x(y) {}
+
+  S(ConstructionKind k) {
+switch (k) {
+case ConstructionKind::Recursive: { // Call one more operator new 'r'ecursively.
+  S *s = new (nullptr) S(5);
+  x = s->x + 1;
+  global_s = s;
+  return;
+}
+case ConstructionKind::Garbage: {
+  // Leaves garbage in 'x'.
+}
+}
+  }
+  ~S() {}
+};
+
+// Do not try this at home!
+void *operator new(size_t size, S *place) {
+  if (!place)
+return new S();
+  return place;
+}
+
+void testThatCharConstructorIndeedYieldsGarbage() {
+  S *s = new S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(s->x == 1); // expected-warning{{UNKNOWN}}
+  // FIXME: This should warn, but MallocChecker doesn't default-bind regions
+  // returned by standard operator new to garbage.
+  s->x += 1; // no-warning
+  delete s;
+}
+
+
+void testChainedOperatorNew() {
+  S *s;
+  // * Evaluate standard new.
+  // * Evaluate constructor S(3).
+  // * Bind value for standard new.
+  // * Evaluate our custom new.
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for our custom new.
+  s = new (new S(3)) S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 3); // expected-warning{{TRUE}}
+  // expected-warning@+9{{Potential leak of memory pointed to by 's'}}
+
+  // * Evaluate standard new.
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for standard new.
+  // * Evaluate our custom new.
+  // * Evaluate constructor S(4).
+  // * Bind value for our custom new.
+  s = new (new S(ConstructionKind::Garbage)) S(4);
+  clang_analyzer_eval(s->x == 4); // expected-warning{{TRUE}}
+  delete s;
+
+  // -> Enter our custom new (nullptr).
+  //   * Evaluate standard new.
+  //   * Inline constructor S().
+  //   * Bind value for standard new.
+  // <- Exit our custom new (nullptr).
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for our custom new.
+  s = new (nullptr) S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
+  delete s;
+
+  // -> Enter our custom new (nullptr).
+  //   * Evaluate standard new.
+  //   * Inline constructor S().
+  //   * Bind value for standard new.
+  // <- Exit our custom new (nullptr).
+  // -> Enter constructor S(Recursive).
+  //   -> Enter our custom new (nullptr).
+  // * Evaluate standard new.
+  // * Inline constructor S().
+  // * Bind 

r322752 - [analyzer] Make isSubRegionOf reflexive

2018-01-17 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Jan 17 12:27:26 2018
New Revision: 322752

URL: http://llvm.org/viewvc/llvm-project?rev=322752=rev
Log:
[analyzer] Make isSubRegionOf reflexive

All usages of isSubRegionOf separately check for reflexive case, and in
any case, set theory tells us that each set is a subset of itself.

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h?rev=322752=322751=322752=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h 
(original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h Wed 
Jan 17 12:27:26 2018
@@ -103,6 +103,7 @@ public:
   const MemRegion *getBaseRegion() const;
 
   /// Check if the region is a subregion of the given region.
+  /// Each region is a subregion of itself.
   virtual bool isSubRegionOf(const MemRegion *R) const;
 
   const MemRegion *StripCasts(bool StripBaseCasts = true) const;

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp?rev=322752=322751=322752=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp 
(original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MisusedMovedObjectChecker.cpp Wed Jan 
17 12:27:26 2018
@@ -101,8 +101,6 @@ static ProgramStateRef removeFromState(P
const MemRegion *Region) {
   if (!Region)
 return State;
-  // Note: The isSubRegionOf function is not reflexive.
-  State = State->remove(Region);
   for (auto  : State->get()) {
 if (E.first->isSubRegionOf(Region))
   State = State->remove(E.first);

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=322752=322751=322752=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Wed Jan 17 
12:27:26 2018
@@ -1838,7 +1838,7 @@ UndefOrNullArgVisitor::VisitNode(const E
 const MemRegion *ArgReg = Call->getArgSVal(Idx).getAsRegion();
 
 // Are we tracking the argument or its subregion?
-if ( !ArgReg || (ArgReg != R && !R->isSubRegionOf(ArgReg->StripCasts(
+if ( !ArgReg || !R->isSubRegionOf(ArgReg->StripCasts()))
   continue;
 
 // Check the function parameter type.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp?rev=322752=322751=322752=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/MemRegion.cpp Wed Jan 17 12:27:26 2018
@@ -103,15 +103,15 @@ MemRegionManager::~MemRegionManager() {
 
//===--===//
 
 bool SubRegion::isSubRegionOf(const MemRegion* R) const {
-  const MemRegion* r = getSuperRegion();
-  while (r != nullptr) {
+  const MemRegion* r = this;
+  do {
 if (r == R)
   return true;
 if (const SubRegion* sr = dyn_cast(r))
   r = sr->getSuperRegion();
 else
   break;
-  }
+  } while (r != nullptr);
   return false;
 }
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp?rev=322752=322751=322752=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ProgramState.cpp Wed Jan 17 12:27:26 2018
@@ -781,8 +781,7 @@ bool ProgramState::isTainted(SymbolRef S
   // complete. For example, this would not currently identify
   // overlapping fields in a union as tainted. To identify this we can
   // check for overlapping/nested byte offsets.
-  if (Kind == I.second &&
-  (R == I.first || R->isSubRegionOf(I.first)))
+  if (Kind == I.second && R->isSubRegionOf(I.first))
 return true;
 

r322750 - [analyzer] Better UI in html reports for displaying shortcuts help

2018-01-17 Thread George Karpenkov via cfe-commits
Author: george.karpenkov
Date: Wed Jan 17 12:06:26 2018
New Revision: 322750

URL: http://llvm.org/viewvc/llvm-project?rev=322750=rev
Log:
[analyzer] Better UI in html reports for displaying shortcuts help

Make the help window accessible, but don't show by default.
Use a different CSS class from macro.

Modified:
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=322750=322749=322750=diff
==
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Wed Jan 17 12:06:26 2018
@@ -311,6 +311,10 @@ void html::AddHeaderFooterInternalBuilti
   "  -webkit-border-radius:5px;  -webkit-box-shadow:1px 1px 7px #000; "
   "  border-radius:5px;  box-shadow:1px 1px 7px #000; "
   "position: absolute; top: -1em; left:10em; z-index: 1 } \n"
+  " #tooltiphint { position: fixed; width: 50em; margin-left: -25em;"
+ "left: 50%; padding: 10px; border: 1px solid #b0b0b0;"
+ "border-radius: 2px; box-shadow: 1px 1px 7px black; "
+ "background-color: #c0c0c0; z-index: 2; }\n"
   " .macro { color: darkmagenta; background-color:LemonChiffon;"
  // Macros are position: relative to provide base for expansions.
  " position: relative }\n"

Modified: cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp?rev=322750=322749=322750=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp Wed Jan 17 12:06:26 
2018
@@ -101,6 +101,9 @@ private:
 
   /// \return Executed lines from \p D in JSON format.
   std::string serializeExecutedLines(const PathDiagnostic );
+
+  /// \return Javascript for displaying shortcuts help;
+  std::string showHelpJavascript();
 };
 
 } // end anonymous namespace
@@ -347,6 +350,8 @@ void HTMLDiagnostics::FinalizeHTML(const
   int LineNumber = 
path.back()->getLocation().asLocation().getExpansionLineNumber();
   int ColumnNumber = 
path.back()->getLocation().asLocation().getExpansionColumnNumber();
 
+  R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), showHelpJavascript());
+
   R.InsertTextBefore(SMgr.getLocForStartOfFile(FID),
  generateKeyboardNavigationJavascript());
 
@@ -399,9 +404,17 @@ void HTMLDiagnostics::FinalizeHTML(const
 
 
 Annotated Source Code
-[?]
-  Use j/k keys for keyboard navigation
-
+Press '?'
+   to see keyboard shortcuts
+
+  Keyboard shortcuts: 
+  
+Use 'j/k' keys for keyboard navigation
+Use 'Shift+S' to show/hide relevant lines
+Use '?' to toggle this window
+  
+  Close
+
 )<<<";
 
 R.InsertTextBefore(SMgr.getLocForStartOfFile(FID), os.str());
@@ -461,6 +474,34 @@ void HTMLDiagnostics::FinalizeHTML(const
   html::AddHeaderFooterInternalBuiltinCSS(R, FID, Entry->getName());
 }
 
+std::string HTMLDiagnostics::showHelpJavascript() {
+  return R"<<<(
+
+
+var toggleHelp = function() {
+var hint = document.querySelector("#tooltiphint");
+var attributeName = "hidden";
+if (hint.hasAttribute(attributeName)) {
+  hint.removeAttribute(attributeName);
+} else {
+  hint.setAttribute("hidden", "true");
+}
+};
+window.addEventListener("keydown", function (event) {
+  if (event.defaultPrevented) {
+return;
+  }
+  if (event.key == "?") {
+toggleHelp();
+  } else {
+return;
+  }
+  event.preventDefault();
+});
+
+)<<<";
+}
+
 std::string
 HTMLDiagnostics::showRelevantLinesJavascript(const PathDiagnostic ) {
   std::string s;


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


[PATCH] D42189: [clang-format] Replace unordered_set with an array

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322749: [clang-format] Replace unordered_set with an array 
(authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42189

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


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -41,25 +41,14 @@
 #include 
 #include 
 #include 
-#include 
 
 #define DEBUG_TYPE "format-formatter"
 
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
-namespace std {
-// Allow using StringRef in std::unordered_set.
-template <> struct hash {
-public:
-  size_t operator()(const llvm::StringRef ) const {
-return llvm::hash_value(s);
-  }
-};
-} // namespace std
-
 namespace llvm {
 namespace yaml {
 template <> struct ScalarEnumerationTraits {
@@ -1432,7 +1421,8 @@
 private:
   static bool guessIsObjC(const SmallVectorImpl 
,
   const AdditionalKeywords ) {
-static const std::unordered_set FoundationIdentifiers = {
+// Keep this array sorted, since we are binary searching over it.
+static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
 "NSAffineTransform",
 "NSArray",
@@ -1490,8 +1480,9 @@
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
- FoundationIdentifiers.find(FormatTok->TokenText) !=
- FoundationIdentifiers.end()) ||
+ std::binary_search(std::begin(FoundationIdentifiers),
+std::end(FoundationIdentifiers),
+FormatTok->TokenText)) ||
 FormatTok->is(TT_ObjCStringLiteral) ||
 FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -41,25 +41,14 @@
 #include 
 #include 
 #include 
-#include 
 
 #define DEBUG_TYPE "format-formatter"
 
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
-namespace std {
-// Allow using StringRef in std::unordered_set.
-template <> struct hash {
-public:
-  size_t operator()(const llvm::StringRef ) const {
-return llvm::hash_value(s);
-  }
-};
-} // namespace std
-
 namespace llvm {
 namespace yaml {
 template <> struct ScalarEnumerationTraits {
@@ -1432,7 +1421,8 @@
 private:
   static bool guessIsObjC(const SmallVectorImpl ,
   const AdditionalKeywords ) {
-static const std::unordered_set FoundationIdentifiers = {
+// Keep this array sorted, since we are binary searching over it.
+static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
 "NSAffineTransform",
 "NSArray",
@@ -1490,8 +1480,9 @@
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
- FoundationIdentifiers.find(FormatTok->TokenText) !=
- FoundationIdentifiers.end()) ||
+ std::binary_search(std::begin(FoundationIdentifiers),
+std::end(FoundationIdentifiers),
+FormatTok->TokenText)) ||
 FormatTok->is(TT_ObjCStringLiteral) ||
 FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! If you felt so inclined, I would say those two AST matchers would both be 
reasonable candidates to add to ASTMatchers.h if you wanted to do that in a 
follow-up patch.


https://reviews.llvm.org/D42116



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


r322749 - [clang-format] Replace unordered_set with an array

2018-01-17 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Wed Jan 17 12:01:02 2018
New Revision: 322749

URL: http://llvm.org/viewvc/llvm-project?rev=322749=rev
Log:
[clang-format] Replace unordered_set with an array

Summary: This replaces an unordered_set from r322690 with an array and binary 
search.

Reviewers: bkramer, benhamilton

Reviewed By: bkramer, benhamilton

Subscribers: jolesiak, benhamilton, klimek, cfe-commits

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

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

Modified: cfe/trunk/lib/Format/Format.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=322749=322748=322749=diff
==
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 17 12:01:02 2018
@@ -41,7 +41,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #define DEBUG_TYPE "format-formatter"
 
@@ -50,16 +49,6 @@ using clang::format::FormatStyle;
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
-namespace std {
-// Allow using StringRef in std::unordered_set.
-template <> struct hash {
-public:
-  size_t operator()(const llvm::StringRef ) const {
-return llvm::hash_value(s);
-  }
-};
-} // namespace std
-
 namespace llvm {
 namespace yaml {
 template <> struct ScalarEnumerationTraits {
@@ -1432,7 +1421,8 @@ public:
 private:
   static bool guessIsObjC(const SmallVectorImpl 
,
   const AdditionalKeywords ) {
-static const std::unordered_set FoundationIdentifiers = {
+// Keep this array sorted, since we are binary searching over it.
+static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
 "NSAffineTransform",
 "NSArray",
@@ -1490,8 +1480,9 @@ private:
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
- FoundationIdentifiers.find(FormatTok->TokenText) !=
- FoundationIdentifiers.end()) ||
+ std::binary_search(std::begin(FoundationIdentifiers),
+std::end(FoundationIdentifiers),
+FormatTok->TokenText)) ||
 FormatTok->is(TT_ObjCStringLiteral) ||
 FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,


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


[PATCH] D40560: [analyzer] Get construction into `operator new` running in simple cases.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngine.cpp:487
+if (const MemRegion *MR = I.second.getAsRegion())
+  SymReaper.markElementIndicesLive(MR);
+  }

dcoughlin wrote:
> Do we have a test for the MemRegion case? Commenting it out doesn't seem to 
> affect the tests.
Right, added one (`new-ctor-symbolic.cpp`).


https://reviews.llvm.org/D40560



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


[PATCH] D40560: [analyzer] Get construction into `operator new` running in simple cases.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ updated this revision to Diff 130243.
NoQ marked 2 inline comments as done.
NoQ added a comment.

Address the final comments.


https://reviews.llvm.org/D40560

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  lib/StaticAnalyzer/Core/ExprEngineCallAndReturn.cpp
  test/Analysis/inline.cpp
  test/Analysis/new-ctor-conservative.cpp
  test/Analysis/new-ctor-inlined.cpp
  test/Analysis/new-ctor-recursive.cpp
  test/Analysis/new-ctor-symbolic.cpp

Index: test/Analysis/new-ctor-symbolic.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-symbolic.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+void clang_analyzer_warnOnDeadSymbol(int);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+int conjure();
+void exit(int);
+
+char buffer[1000];
+
+// This operator allocates stuff within the buffer. Additionally, it never
+// places anything at the beginning of the buffer.
+void *operator new(size_t size) {
+  int i = conjure();
+  if (i == 0)
+exit(1);
+  // Let's see if the symbol dies before new-expression is evaluated.
+  // It shouldn't.
+  clang_analyzer_warnOnDeadSymbol(i);
+  return buffer + i;
+}
+
+struct S {
+S() {}
+~S() {}
+};
+
+void testIndexLiveness() {
+  S *s = new S();
+  clang_analyzer_eval((void *)s == (void *)buffer); // expected-warning{{FALSE}}
+} // expected-warning{{SYMBOL DEAD}}
Index: test/Analysis/new-ctor-recursive.cpp
===
--- /dev/null
+++ test/Analysis/new-ctor-recursive.cpp
@@ -0,0 +1,118 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core,cplusplus.NewDelete,cplusplus.NewDeleteLeaks,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify %s
+
+void clang_analyzer_eval(bool);
+void clang_analyzer_dump(int);
+
+typedef __typeof__(sizeof(int)) size_t;
+
+void *conjure();
+void exit(int);
+
+struct S;
+
+S *global_s;
+
+// Recursive operator kinda placement new.
+void *operator new(size_t size, S *place);
+
+enum class ConstructionKind : char {
+  Garbage,
+  Recursive
+};
+
+struct S {
+public:
+  int x;
+  S(): x(1) {}
+  S(int y): x(y) {}
+
+  S(ConstructionKind k) {
+switch (k) {
+case ConstructionKind::Recursive: { // Call one more operator new 'r'ecursively.
+  S *s = new (nullptr) S(5);
+  x = s->x + 1;
+  global_s = s;
+  return;
+}
+case ConstructionKind::Garbage: {
+  // Leaves garbage in 'x'.
+}
+}
+  }
+  ~S() {}
+};
+
+// Do not try this at home!
+void *operator new(size_t size, S *place) {
+  if (!place)
+return new S();
+  return place;
+}
+
+void testThatCharConstructorIndeedYieldsGarbage() {
+  S *s = new S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(s->x == 1); // expected-warning{{UNKNOWN}}
+  // FIXME: This should warn, but MallocChecker doesn't default-bind regions
+  // returned by standard operator new to garbage.
+  s->x += 1; // no-warning
+  delete s;
+}
+
+
+void testChainedOperatorNew() {
+  S *s;
+  // * Evaluate standard new.
+  // * Evaluate constructor S(3).
+  // * Bind value for standard new.
+  // * Evaluate our custom new.
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for our custom new.
+  s = new (new S(3)) S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 3); // expected-warning{{TRUE}}
+  // expected-warning@+9{{Potential leak of memory pointed to by 's'}}
+
+  // * Evaluate standard new.
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for standard new.
+  // * Evaluate our custom new.
+  // * Evaluate constructor S(4).
+  // * Bind value for our custom new.
+  s = new (new S(ConstructionKind::Garbage)) S(4);
+  clang_analyzer_eval(s->x == 4); // expected-warning{{TRUE}}
+  delete s;
+
+  // -> Enter our custom new (nullptr).
+  //   * Evaluate standard new.
+  //   * Inline constructor S().
+  //   * Bind value for standard new.
+  // <- Exit our custom new (nullptr).
+  // * Evaluate constructor S(Garbage).
+  // * Bind value for our custom new.
+  s = new (nullptr) S(ConstructionKind::Garbage);
+  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}
+  delete s;
+
+  // -> Enter our custom new (nullptr).
+  //   * Evaluate standard new.
+  //   * Inline constructor S().
+  //   * Bind value for standard new.
+  // <- Exit our custom new (nullptr).
+  // -> Enter constructor S(Recursive).
+  //   -> Enter our custom new (nullptr).
+  // * Evaluate standard new.
+  // * Inline constructor S().
+  // * Bind value for standard new.
+  //   <- Exit our custom new (nullptr).
+  //   * Evaluate constructor S(5).
+  //   * Bind value for our custom new (nullptr).

[PATCH] D42189: [clang-format] Replace unordered_set with an array

2018-01-17 Thread Benjamin Kramer via Phabricator via cfe-commits
bkramer accepted this revision.
bkramer added a comment.

lgtm


Repository:
  rC Clang

https://reviews.llvm.org/D42189



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


[PATCH] D42192: [analyzer] Assume that the allocated value is non-null before construction, not after.

2018-01-17 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Forgot to mention that this patch follows the tradition of duplicating code 
from `VisitCXXNewExpr()` to `VisitCXXNewAllocatorCall()` - until we enable 
`c++-allocator-inlining` by default and clean away the old mode support from 
`VisitCXXNewExpr()` (which would become pretty trivial).


Repository:
  rC Clang

https://reviews.llvm.org/D42192



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


[PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-17 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

I think I've addressed all the review comments. Any other comments from anyone?


https://reviews.llvm.org/D41039



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


[PATCH] D42192: [analyzer] Assume that the allocated value is non-null before construction, not after.

2018-01-17 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added inline comments.



Comment at: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:514
+  QualType Ty = FD->getType();
+  if (const FunctionProtoType *ProtoType = Ty->getAs())
+if (!ProtoType->isNothrow(getContext()))

auto?



Comment at: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:516
+if (!ProtoType->isNothrow(getContext()))
+  State = State->assume(RetVal.castAs(), true);
+}

This is neither here nor there, but for this and many other cases I think we 
could be considerably more readable by defining helpers `State->assumeIsTrue` 
and `State->assumeIsFalse` (or `assumeNonNull`, or whatever is most descriptive)


Repository:
  rC Clang

https://reviews.llvm.org/D42192



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


[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 130242.
juliehockett added a comment.

Rebasing and updating decltypeType matcher


https://reviews.llvm.org/D42116

Files:
  clang-tidy/fuchsia/CMakeLists.txt
  clang-tidy/fuchsia/FuchsiaTidyModule.cpp
  clang-tidy/fuchsia/TrailingReturnCheck.cpp
  clang-tidy/fuchsia/TrailingReturnCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/fuchsia-trailing-return.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/fuchsia-trailing-return.cpp

Index: test/clang-tidy/fuchsia-trailing-return.cpp
===
--- /dev/null
+++ test/clang-tidy/fuchsia-trailing-return.cpp
@@ -0,0 +1,23 @@
+// RUN: %check_clang_tidy %s fuchsia-trailing-return %t
+
+int add_one(const int arg) { return arg; }
+
+auto get_add_one() -> int (*)(const int) {
+  // CHECK-MESSAGES: [[@LINE-1]]:1: warning: a trailing return type is disallowed for this type of declaration
+  // CHECK-NEXT: auto get_add_one() -> int (*)(const int) {
+  return add_one;
+}
+
+auto lambda = [](double x, double y) {return x + y;};
+
+auto lambda2 = [](double x, double y) -> double {return x + y;};
+
+int main() {
+  get_add_one()(5);
+  return 0;
+}
+
+template 
+auto fn(const T1 , const T2 ) -> decltype(lhs + rhs) {
+  return lhs + rhs;
+}
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -72,6 +72,7 @@
fuchsia-default-arguments
fuchsia-overloaded-operator
fuchsia-statically-constructed-objects
+   fuchsia-trailing-return
fuchsia-virtual-inheritance
google-build-explicit-make-pair
google-build-namespaces
Index: docs/clang-tidy/checks/fuchsia-trailing-return.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/fuchsia-trailing-return.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - fuchsia-trailing-return
+
+fuchsia-trailing-return
+===
+
+Functions that have trailing returns are disallowed, except for those using 
+decltype specifiers and lambda with otherwise unutterable return types.
+
+For example:
+
+.. code-block:: c++
+
+  // No warning
+  int add_one(const int arg) { return arg; }
+
+  // Warning
+  auto get_add_one() -> int (*)(const int) {
+return add_one;
+  }
+
+Exceptions are made for lambdas and decltype specifiers:
+
+.. code-block:: c++
+  
+  // No warning
+  auto lambda = [](double x, double y) -> double {return x + y;};
+  
+  // No warning
+  template 
+  auto fn(const T1 , const T2 ) -> decltype(lhs + rhs) {
+return lhs + rhs;
+  }
+
+
+See the features disallowed in Fuchsia at https://fuchsia.googlesource.com/zircon/+/master/docs/cxx.md
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -70,7 +70,14 @@
   Warns if global, non-trivial objects with static storage are constructed, unless the 
   object is statically initialized with a ``constexpr`` constructor or has no 
   explicit constructor.
-
+  
+- New `fuchsia-trailing-return
+  `_ check
+
+  Functions that have trailing returns are disallowed, except for those 
+  using decltype specifiers and lambda with otherwise unutterable 
+  return types.
+
 - New alias `hicpp-avoid-goto
   `_ to 
   `cppcoreguidelines-avoid-goto `_
Index: clang-tidy/fuchsia/TrailingReturnCheck.h
===
--- /dev/null
+++ clang-tidy/fuchsia/TrailingReturnCheck.h
@@ -0,0 +1,37 @@
+//===--- TrailingReturnCheck.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_FUCHSIA_TRAILING_RETURN_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_TRAILING_RETURN_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace fuchsia {
+
+/// Functions that have trailing returns are disallowed, except for those 
+/// using decltype specifiers and lambda with otherwise unutterable 
+/// return types.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-trailing-return.html
+class TrailingReturnCheck : public ClangTidyCheck {
+public:
+  TrailingReturnCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const 

[PATCH] D41455: [ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarations

2018-01-17 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322746: [ASTMatchers] Add isNoReturn() match narrower for 
FunctionDeclarations (authored by lebedevri, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41455?vs=130228=130240#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41455

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

Index: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -354,6 +354,7 @@
   REGISTER_MATCHER(isMemberInitializer);
   REGISTER_MATCHER(isMoveAssignmentOperator);
   REGISTER_MATCHER(isMoveConstructor);
+  REGISTER_MATCHER(isNoReturn);
   REGISTER_MATCHER(isNoThrow);
   REGISTER_MATCHER(isOverride);
   REGISTER_MATCHER(isPrivate);
Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1770,6 +1770,84 @@
 functionDecl(isExplicitTemplateSpecialization(;
 }
 
+TEST(TypeMatching, MatchesNoReturn) {
+  EXPECT_TRUE(notMatches("void func();", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("void func() {}", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatchesC("void func();", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatchesC("void func() {}", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(
+  notMatches("struct S { void func(); };", functionDecl(isNoReturn(;
+  EXPECT_TRUE(
+  notMatches("struct S { void func() {} };", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatches("struct S { static void func(); };",
+ functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("struct S { static void func() {} };",
+ functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatches("struct S { S(); };", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("struct S { S() {} };", functionDecl(isNoReturn(;
+
+  // ---
+
+  EXPECT_TRUE(matches("[[noreturn]] void func();", functionDecl(isNoReturn(;
+  EXPECT_TRUE(
+  matches("[[noreturn]] void func() {}", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(matches("struct S { [[noreturn]] void func(); };",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("struct S { [[noreturn]] void func() {} };",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(matches("struct S { [[noreturn]] static void func(); };",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("struct S { [[noreturn]] static void func() {} };",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(
+  matches("struct S { [[noreturn]] S(); };", functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("struct S { [[noreturn]] S() {} };",
+  functionDecl(isNoReturn(;
+
+  // ---
+
+  EXPECT_TRUE(matches("__attribute__((noreturn)) void func();",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("__attribute__((noreturn)) void func() {}",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(matches("struct S { __attribute__((noreturn)) void func(); };",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("struct S { __attribute__((noreturn)) void func() {} };",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(
+  matches("struct S { __attribute__((noreturn)) static void func(); };",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(
+  matches("struct S { __attribute__((noreturn)) static void func() {} };",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(matches("struct S { __attribute__((noreturn)) S(); };",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matches("struct S { __attribute__((noreturn)) S() {} };",
+  functionDecl(isNoReturn(;
+
+  // ---
+
+  EXPECT_TRUE(matchesC("__attribute__((noreturn)) void func();",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matchesC("__attribute__((noreturn)) void func() {}",
+  functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(matchesC("_Noreturn void func();",
+  functionDecl(isNoReturn(;
+  EXPECT_TRUE(matchesC("_Noreturn void func() {}",
+  functionDecl(isNoReturn(;
+}
+
 TEST(TypeMatching, MatchesBool) {
   EXPECT_TRUE(matches("struct S { bool func(); };",
   cxxMethodDecl(returns(booleanType();
Index: 

r322746 - [ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarations

2018-01-17 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Wed Jan 17 11:40:55 2018
New Revision: 322746

URL: http://llvm.org/viewvc/llvm-project?rev=322746=rev
Log:
[ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarations

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: dblaikie, klimek, cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=322746=322745=322746=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Wed Jan 17 11:40:55 2018
@@ -2843,6 +2843,20 @@ namespaceDecl(isInline()) will match n::
 
 
 
+Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisNoReturn
+Matches FunctionDecls 
that have a noreturn attribute.
+
+Given
+  void nope();
+  [[noreturn]] void a();
+  __attribute__((noreturn)) void b();
+  struct c { [[noreturn]] c(); };
+functionDecl(isNoReturn())
+  matches all of those except
+  void nope();
+
+
+
 Matcherhttp://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclisNoThrow
 Matches functions that 
have a non-throwing exception specification.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=322746=322745=322746=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Wed Jan 17 11:40:55 2018
@@ -3567,6 +3567,24 @@ AST_POLYMORPHIC_MATCHER_P(parameterCount
   return Node.getNumParams() == N;
 }
 
+/// \brief Matches \c FunctionDecls that have a noreturn attribute.
+///
+/// Given
+/// \code
+///   void nope();
+///   [[noreturn]] void a();
+///   __attribute__((noreturn)) void b();
+///   struct c { [[noreturn]] c(); };
+/// \endcode
+/// functionDecl(isNoReturn())
+///   matches all of those except
+/// \code
+///   void nope();
+/// \endcode
+AST_MATCHER(FunctionDecl, isNoReturn) {
+  return Node.isNoReturn();
+}
+
 /// \brief Matches the return type of a function declaration.
 ///
 /// Given:

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=322746=322745=322746=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Wed Jan 17 11:40:55 2018
@@ -354,6 +354,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(isMemberInitializer);
   REGISTER_MATCHER(isMoveAssignmentOperator);
   REGISTER_MATCHER(isMoveConstructor);
+  REGISTER_MATCHER(isNoReturn);
   REGISTER_MATCHER(isNoThrow);
   REGISTER_MATCHER(isOverride);
   REGISTER_MATCHER(isPrivate);

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp?rev=322746=322745=322746=diff
==
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp Wed Jan 17 
11:40:55 2018
@@ -1770,6 +1770,84 @@ TEST(IsExplicitTemplateSpecialization,
 functionDecl(isExplicitTemplateSpecialization(;
 }
 
+TEST(TypeMatching, MatchesNoReturn) {
+  EXPECT_TRUE(notMatches("void func();", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("void func() {}", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatchesC("void func();", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatchesC("void func() {}", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(
+  notMatches("struct S { void func(); };", functionDecl(isNoReturn(;
+  EXPECT_TRUE(
+  notMatches("struct S { void func() {} };", functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatches("struct S { static void func(); };",
+ functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("struct S { static void func() {} };",
+ functionDecl(isNoReturn(;
+
+  EXPECT_TRUE(notMatches("struct S { S(); };", functionDecl(isNoReturn(;
+  EXPECT_TRUE(notMatches("struct S { S() {} };", functionDecl(isNoReturn(;
+
+  // ---
+
+  EXPECT_TRUE(matches("[[noreturn]] void func();", 
functionDecl(isNoReturn(;
+  EXPECT_TRUE(
+  matches("[[noreturn]] void func() {}", functionDecl(isNoReturn(;
+
+  

[PATCH] D42146: libcxx: Disable CFI in function std::get_temporary_buffer.

2018-01-17 Thread Peter Collingbourne via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX322744: libcxx: Disable CFI in function 
std::get_temporary_buffer. (authored by pcc, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42146?vs=130063=130238#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D42146

Files:
  include/memory


Index: include/memory
===
--- include/memory
+++ include/memory
@@ -1992,6 +1992,7 @@
 };
 
 template 
+_LIBCPP_NO_CFI
 pair<_Tp*, ptrdiff_t>
 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
 {


Index: include/memory
===
--- include/memory
+++ include/memory
@@ -1992,6 +1992,7 @@
 };
 
 template 
+_LIBCPP_NO_CFI
 pair<_Tp*, ptrdiff_t>
 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
 {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r322744 - libcxx: Disable CFI in function std::get_temporary_buffer.

2018-01-17 Thread Peter Collingbourne via cfe-commits
Author: pcc
Date: Wed Jan 17 11:32:35 2018
New Revision: 322744

URL: http://llvm.org/viewvc/llvm-project?rev=322744=rev
Log:
libcxx: Disable CFI in function std::get_temporary_buffer.

The specification of this function mandates a cast to uninitialized
T*, which is forbidden under CFI.

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

Modified:
libcxx/trunk/include/memory

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=322744=322743=322744=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Wed Jan 17 11:32:35 2018
@@ -1992,6 +1992,7 @@ public:
 };
 
 template 
+_LIBCPP_NO_CFI
 pair<_Tp*, ptrdiff_t>
 get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
 {


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


[PATCH] D41788: [DeclPrinter] Fix two cases that crash clang -ast-print.

2018-01-17 Thread Artem Belevich via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL322742: [DeclPrinter] Fix two cases that crash clang 
-ast-print. (authored by tra, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D41788?vs=128813=130233#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D41788

Files:
  cfe/trunk/lib/AST/DeclPrinter.cpp
  cfe/trunk/test/Sema/ast-print.c
  cfe/trunk/test/SemaCXX/ast-print-crash.cpp


Index: cfe/trunk/lib/AST/DeclPrinter.cpp
===
--- cfe/trunk/lib/AST/DeclPrinter.cpp
+++ cfe/trunk/lib/AST/DeclPrinter.cpp
@@ -128,9 +128,7 @@
   // FIXME: This should be on the Type class!
   QualType BaseType = T;
   while (!BaseType->isSpecifierType()) {
-if (isa(BaseType))
-  break;
-else if (const PointerType* PTy = BaseType->getAs())
+if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
@@ -144,8 +142,11 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (const ParenType *PTy = BaseType->getAs())
+  BaseType = PTy->desugar();
 else
-  llvm_unreachable("Unknown declarator!");
+  // This must be a syntax error.
+  break;
   }
   return BaseType;
 }
Index: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
===
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \
+// RUN: | FileCheck %s
+
+// The test compiles a file with a syntax error which used to cause a crash 
with
+// -ast-print. Compilation fails due to the syntax error, but compiler should
+// not crash and print out whatever it manager to parse.
+
+// CHECK:  struct {
+// CHECK-NEXT: } dont_crash_on_syntax_error;
+// CHECK-NEXT: decltype(nullptr) p;
+struct {
+} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
Index: cfe/trunk/test/Sema/ast-print.c
===
--- cfe/trunk/test/Sema/ast-print.c
+++ cfe/trunk/test/Sema/ast-print.c
@@ -15,6 +15,10 @@
   };
 };
 
+// This used to crash clang.
+struct {
+}(s1);
+
 int foo(const struct blah *b) {
   // CHECK: return b->b;
   return b->b;


Index: cfe/trunk/lib/AST/DeclPrinter.cpp
===
--- cfe/trunk/lib/AST/DeclPrinter.cpp
+++ cfe/trunk/lib/AST/DeclPrinter.cpp
@@ -128,9 +128,7 @@
   // FIXME: This should be on the Type class!
   QualType BaseType = T;
   while (!BaseType->isSpecifierType()) {
-if (isa(BaseType))
-  break;
-else if (const PointerType* PTy = BaseType->getAs())
+if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
@@ -144,8 +142,11 @@
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (const ParenType *PTy = BaseType->getAs())
+  BaseType = PTy->desugar();
 else
-  llvm_unreachable("Unknown declarator!");
+  // This must be a syntax error.
+  break;
   }
   return BaseType;
 }
Index: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
===
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \
+// RUN: | FileCheck %s
+
+// The test compiles a file with a syntax error which used to cause a crash with
+// -ast-print. Compilation fails due to the syntax error, but compiler should
+// not crash and print out whatever it manager to parse.
+
+// CHECK:  struct {
+// CHECK-NEXT: } dont_crash_on_syntax_error;
+// CHECK-NEXT: decltype(nullptr) p;
+struct {
+} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;
Index: cfe/trunk/test/Sema/ast-print.c
===
--- cfe/trunk/test/Sema/ast-print.c
+++ cfe/trunk/test/Sema/ast-print.c
@@ -15,6 +15,10 @@
   };
 };
 
+// This used to crash clang.
+struct {
+}(s1);
+
 int foo(const struct blah *b) {
   // CHECK: return b->b;
   return b->b;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42189: [clang-format] Replace unordered_set with an array

2018-01-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 130232.
krasimir added a comment.

- Add comment


Repository:
  rC Clang

https://reviews.llvm.org/D42189

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -41,25 +41,14 @@
 #include 
 #include 
 #include 
-#include 
 
 #define DEBUG_TYPE "format-formatter"
 
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
-namespace std {
-// Allow using StringRef in std::unordered_set.
-template <> struct hash {
-public:
-  size_t operator()(const llvm::StringRef ) const {
-return llvm::hash_value(s);
-  }
-};
-} // namespace std
-
 namespace llvm {
 namespace yaml {
 template <> struct ScalarEnumerationTraits {
@@ -1432,7 +1421,8 @@
 private:
   static bool guessIsObjC(const SmallVectorImpl 
,
   const AdditionalKeywords ) {
-static const std::unordered_set FoundationIdentifiers = {
+// Keep this array sorted, since we are binary searching over it.
+static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
 "NSAffineTransform",
 "NSArray",
@@ -1490,8 +1480,9 @@
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
- FoundationIdentifiers.find(FormatTok->TokenText) !=
- FoundationIdentifiers.end()) ||
+ std::binary_search(std::begin(FoundationIdentifiers),
+std::end(FoundationIdentifiers),
+FormatTok->TokenText)) ||
 FormatTok->is(TT_ObjCStringLiteral) ||
 FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -41,25 +41,14 @@
 #include 
 #include 
 #include 
-#include 
 
 #define DEBUG_TYPE "format-formatter"
 
 using clang::format::FormatStyle;
 
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::IncludeCategory)
 LLVM_YAML_IS_SEQUENCE_VECTOR(clang::format::FormatStyle::RawStringFormat)
 
-namespace std {
-// Allow using StringRef in std::unordered_set.
-template <> struct hash {
-public:
-  size_t operator()(const llvm::StringRef ) const {
-return llvm::hash_value(s);
-  }
-};
-} // namespace std
-
 namespace llvm {
 namespace yaml {
 template <> struct ScalarEnumerationTraits {
@@ -1432,7 +1421,8 @@
 private:
   static bool guessIsObjC(const SmallVectorImpl ,
   const AdditionalKeywords ) {
-static const std::unordered_set FoundationIdentifiers = {
+// Keep this array sorted, since we are binary searching over it.
+static constexpr llvm::StringLiteral FoundationIdentifiers[] = {
 "CGFloat",
 "NSAffineTransform",
 "NSArray",
@@ -1490,8 +1480,9 @@
   FormatTok->isOneOf(tok::numeric_constant, tok::l_square,
  tok::l_brace))) ||
 (FormatTok->Tok.isAnyIdentifier() &&
- FoundationIdentifiers.find(FormatTok->TokenText) !=
- FoundationIdentifiers.end()) ||
+ std::binary_search(std::begin(FoundationIdentifiers),
+std::end(FoundationIdentifiers),
+FormatTok->TokenText)) ||
 FormatTok->is(TT_ObjCStringLiteral) ||
 FormatTok->isOneOf(Keywords.kw_NS_ENUM, Keywords.kw_NS_OPTIONS,
TT_ObjCBlockLBrace, TT_ObjCBlockLParen,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r322742 - [DeclPrinter] Fix two cases that crash clang -ast-print.

2018-01-17 Thread Artem Belevich via cfe-commits
Author: tra
Date: Wed Jan 17 11:29:39 2018
New Revision: 322742

URL: http://llvm.org/viewvc/llvm-project?rev=322742=rev
Log:
[DeclPrinter] Fix two cases that crash clang -ast-print.

Both are related to handling anonymous structures.
* clang didn't handle () around an anonymous struct variable.
* clang also crashed on syntax errors that could lead to other
  syntactic constructs following the declaration of an
  anonymous struct. While the code is invalid, that's not
  a good reason to panic compiler.

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

Added:
cfe/trunk/test/SemaCXX/ast-print-crash.cpp
Modified:
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/test/Sema/ast-print.c

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=322742=322741=322742=diff
==
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Wed Jan 17 11:29:39 2018
@@ -128,9 +128,7 @@ static QualType GetBaseType(QualType T)
   // FIXME: This should be on the Type class!
   QualType BaseType = T;
   while (!BaseType->isSpecifierType()) {
-if (isa(BaseType))
-  break;
-else if (const PointerType* PTy = BaseType->getAs())
+if (const PointerType *PTy = BaseType->getAs())
   BaseType = PTy->getPointeeType();
 else if (const BlockPointerType *BPy = BaseType->getAs())
   BaseType = BPy->getPointeeType();
@@ -144,8 +142,11 @@ static QualType GetBaseType(QualType T)
   BaseType = RTy->getPointeeType();
 else if (const AutoType *ATy = BaseType->getAs())
   BaseType = ATy->getDeducedType();
+else if (const ParenType *PTy = BaseType->getAs())
+  BaseType = PTy->desugar();
 else
-  llvm_unreachable("Unknown declarator!");
+  // This must be a syntax error.
+  break;
   }
   return BaseType;
 }

Modified: cfe/trunk/test/Sema/ast-print.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ast-print.c?rev=322742=322741=322742=diff
==
--- cfe/trunk/test/Sema/ast-print.c (original)
+++ cfe/trunk/test/Sema/ast-print.c Wed Jan 17 11:29:39 2018
@@ -15,6 +15,10 @@ struct blah {
   };
 };
 
+// This used to crash clang.
+struct {
+}(s1);
+
 int foo(const struct blah *b) {
   // CHECK: return b->b;
   return b->b;

Added: cfe/trunk/test/SemaCXX/ast-print-crash.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ast-print-crash.cpp?rev=322742=auto
==
--- cfe/trunk/test/SemaCXX/ast-print-crash.cpp (added)
+++ cfe/trunk/test/SemaCXX/ast-print-crash.cpp Wed Jan 17 11:29:39 2018
@@ -0,0 +1,12 @@
+// RUN: not %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 \
+// RUN: | FileCheck %s
+
+// The test compiles a file with a syntax error which used to cause a crash 
with
+// -ast-print. Compilation fails due to the syntax error, but compiler should
+// not crash and print out whatever it manager to parse.
+
+// CHECK:  struct {
+// CHECK-NEXT: } dont_crash_on_syntax_error;
+// CHECK-NEXT: decltype(nullptr) p;
+struct {
+} dont_crash_on_syntax_error /* missing ; */ decltype(nullptr) p;


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


[PATCH] D42116: [clang-tidy] Adding Fuchsia checker for trailing returns

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/fuchsia/TrailingReturnCheck.cpp:25
+
+AST_TYPE_MATCHER(DecltypeType, decltypeType);
+

Good try, but if you rebase, you'll find that this macro has gone away entirely 
in r322687. I believe this macro was causing issues with ODR violations from 
its use in header files. I'd expand the macro manually.


https://reviews.llvm.org/D42116



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


[PATCH] D41455: [ASTMatchers] Add isNoReturn() match narrower for FunctionDeclarations

2018-01-17 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Great, looks good to commit. Thanks, Roman!


Repository:
  rC Clang

https://reviews.llvm.org/D41455



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


  1   2   3   >