[clang-tools-extra] r284332 - [clang-tidy] Use ignoreImplicit in cert-err58-cpp check

2016-10-16 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Sun Oct 16 04:47:10 2016
New Revision: 284332

URL: http://llvm.org/viewvc/llvm-project?rev=284332&view=rev
Log:
[clang-tidy] Use ignoreImplicit in cert-err58-cpp check

Summary:
Fix a false negative in cert-err58-cpp check when calling a constructor
creates objects that require cleanup.

Reviewers: aaron.ballman

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Modified: clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp?rev=284332&r1=284331&r2=284332&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp Sun 
Oct 16 04:47:10 2016
@@ -27,8 +27,8 @@ void StaticObjectExceptionCheck::registe
   Finder->addMatcher(
   varDecl(anyOf(hasThreadStorageDuration(), hasStaticStorageDuration()),
   unless(hasAncestor(functionDecl())),
-  hasInitializer(cxxConstructExpr(hasDeclaration(
-  cxxConstructorDecl(unless(isNoThrow())).bind("ctor")
+  hasInitializer(ignoringImplicit(cxxConstructExpr(hasDeclaration(
+  cxxConstructorDecl(unless(isNoThrow())).bind("ctor"))
   .bind("var"),
   this);
 }

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp?rev=284332&r1=284331&r2=284332&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp 
Sun Oct 16 04:47:10 2016
@@ -16,6 +16,15 @@ struct V {
   explicit V(const char *) {} // Can throw
 };
 
+struct Cleanup
+{
+  ~Cleanup() {}
+};
+
+struct W {
+  W(Cleanup c = {}) noexcept(false);
+};
+
 
 S s;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static 
storage duration may throw an exception that cannot be caught [cert-err58-cpp]
@@ -27,6 +36,9 @@ U u;
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static 
storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static 
storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with 
thread_local storage duration may throw an exception that cannot be caught
@@ -35,22 +47,27 @@ thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with 
thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with 
thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with 
thread_local storage duration may throw an exception that cannot be caught
 
-void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
   S s2; // ok
   T t2; // ok
   U u2; // ok
   V v2("v"); // ok
+  W w2; // ok
 
   thread_local S s3; // ok
   thread_local T t3; // ok
   thread_local U u3; // ok
   thread_local V v3("v"); // ok
+  thread_local W w3; // ok
 
   static S s4; // ok
   static T t4; // ok
   static U u4; // ok
   static V v4("v"); // ok
+  static W w4; // ok
 }
 
 namespace {
@@ -64,6 +81,9 @@ U u;
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static 
storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static 
storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with 
thread_local storage duration may throw an exception that cannot be caught
@@ -72,6 +92,8 @@ thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with 
thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");

[PATCH] D25642: [clang-tidy] Use ignoreImplicit in cert-err58-cpp check

2016-10-16 Thread Malcolm Parsons via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL284332: [clang-tidy] Use ignoreImplicit in cert-err58-cpp 
check (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D25642?vs=74770&id=74787#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25642

Files:
  clang-tools-extra/trunk/clang-tidy/cert/StaticObjectExceptionCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp

Index: clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/cert-static-object-exception.cpp
@@ -16,6 +16,15 @@
   explicit V(const char *) {} // Can throw
 };
 
+struct Cleanup
+{
+  ~Cleanup() {}
+};
+
+struct W {
+  W(Cleanup c = {}) noexcept(false);
+};
+
 
 S s;
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 's' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
@@ -27,30 +36,38 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 
-void f(S s1, T t1, U u1, V v1) { // ok, ok, ok, ok
+void f(S s1, T t1, U u1, V v1, W w1) { // ok, ok, ok, ok, ok
   S s2; // ok
   T t2; // ok
   U u2; // ok
   V v2("v"); // ok
+  W w2; // ok
 
   thread_local S s3; // ok
   thread_local T t3; // ok
   thread_local U u3; // ok
   thread_local V v3("v"); // ok
+  thread_local W w3; // ok
 
   static S s4; // ok
   static T t4; // ok
   static U u4; // ok
   static V v4("v"); // ok
+  static W w4; // ok
 }
 
 namespace {
@@ -64,14 +81,19 @@
 V v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
 // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+W w;
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+// CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
 thread_local S s3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 's3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local T t3; // ok
 thread_local U u3;
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'u3' with thread_local storage duration may throw an exception that cannot be caught
 thread_local V v3("v");
 // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'v3' with thread_local storage duration may throw an exception that cannot be caught
+thread_local W w3;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: construction of 'w3' with thread_local storage duration may throw an exception that cannot be caught
 };
 
 class Statics {
@@ -85,22 +107,28 @@
   static V v;
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'v' with static storage duration may throw an exception that cannot be caught
   // CHECK-MESSAGES: 16:12: note: possibly throwing constructor declared here
+  static W w;
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: construction of 'w' with static storage duration may throw an exception that cannot be caught
+  // CHECK-MESSAGES: 25:3: note: possibly throwing constructor declared here
 
   void f(S s, T t, U u, V v) {
 S s2;  // ok
 T t2;  // ok
 U u2;  // ok
 V v2("v"); // ok
+W w2;  // ok
 
 thread_local S s3;  // ok
 thread_local T t3;  // ok
 thread_local U u3;  // ok
 thread_local V v3("v"); // ok
+thread_local W w3;  // ok
 
 static S s4;  // ok
 static T t4;  // ok
 static U u4;  // ok
 static V v4("v"); // ok
+static W w4;  // ok
   }
 };
 
@@ -114,3 +142,6 @@
 V Statics::v("v");
 // CHECK-MESSAGES: :[[@LINE-1]]

[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

2016-10-16 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added a reviewer: rsmith.
EricWF added a subscriber: cfe-commits.

The C++17 rules for aggregate initialization changed to disallow types with 
explicit constructors [dcl.init.aggr]p1. This patch implements that new rule.


https://reviews.llvm.org/D25654

Files:
  lib/AST/DeclCXX.cpp
  test/SemaCXX/aggregate-initialization.cpp


Index: test/SemaCXX/aggregate-initialization.cpp
===
--- test/SemaCXX/aggregate-initialization.cpp
+++ test/SemaCXX/aggregate-initialization.cpp
@@ -146,3 +146,12 @@
   // expected-error@-5 {{protected constructor}}
   // expected-note@-30 {{here}}
 }
+
+namespace diff_cpp1z_dcl_init_aggr_example {
+  struct ExplicitDefault { explicit ExplicitDefault() = default; };
+  ExplicitDefault d = {};
+#if __cplusplus > 201402L
+  // expected-error@-2 {{explicit in copy-initialization}}
+  // expected-note@-4 {{here}}
+#endif
+}
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -560,6 +560,10 @@
 ? Constructor->isUserProvided()
 : !Constructor->isImplicit())
   data().Aggregate = false;
+// C++1z [dcl.init.aggr]p1:
+//  - no user-provided, explicit, or inherited constructors,
+if (getASTContext().getLangOpts().CPlusPlus1z && Constructor->isExplicit())
+  data().Aggregate = false;
   }
 
   // Handle destructors.


Index: test/SemaCXX/aggregate-initialization.cpp
===
--- test/SemaCXX/aggregate-initialization.cpp
+++ test/SemaCXX/aggregate-initialization.cpp
@@ -146,3 +146,12 @@
   // expected-error@-5 {{protected constructor}}
   // expected-note@-30 {{here}}
 }
+
+namespace diff_cpp1z_dcl_init_aggr_example {
+  struct ExplicitDefault { explicit ExplicitDefault() = default; };
+  ExplicitDefault d = {};
+#if __cplusplus > 201402L
+  // expected-error@-2 {{explicit in copy-initialization}}
+  // expected-note@-4 {{here}}
+#endif
+}
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -560,6 +560,10 @@
 ? Constructor->isUserProvided()
 : !Constructor->isImplicit())
   data().Aggregate = false;
+// C++1z [dcl.init.aggr]p1:
+//  - no user-provided, explicit, or inherited constructors,
+if (getASTContext().getLangOpts().CPlusPlus1z && Constructor->isExplicit())
+  data().Aggregate = false;
   }
 
   // Handle destructors.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r284333 - Make any_cast(nullptr) compile

2016-10-16 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Sun Oct 16 06:56:38 2016
New Revision: 284333

URL: http://llvm.org/viewvc/llvm-project?rev=284333&view=rev
Log:
Make any_cast(nullptr) compile

Modified:
libcxx/trunk/include/any

libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp

Modified: libcxx/trunk/include/any
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/any?rev=284333&r1=284332&r2=284333&view=diff
==
--- libcxx/trunk/include/any (original)
+++ libcxx/trunk/include/any Sun Oct 16 06:56:38 2016
@@ -622,6 +622,18 @@ any_cast(any const * __any) _NOEXCEPT
 return _VSTD::any_cast<_ValueType>(const_cast(__any));
 }
 
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+_RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept {
+  return static_cast<_RetType>(__p);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+_RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
+  return nullptr;
+}
+
 template 
 add_pointer_t<_ValueType>
 any_cast(any * __any) _NOEXCEPT
@@ -631,15 +643,15 @@ any_cast(any * __any) _NOEXCEPT
   "_ValueType may not be a reference.");
 typedef typename add_pointer<_ValueType>::type _ReturnType;
 if (__any && __any->__h) {
-return static_cast<_ReturnType>(
-__any->__call(_Action::_Get, nullptr,
+  void *__p = __any->__call(_Action::_Get, nullptr,
 #if !defined(_LIBCPP_NO_RTTI)
   &typeid(_ValueType),
 #else
   nullptr,
 #endif
-  __any_imp::__get_fallback_typeid<_ValueType>()
-));
+  __any_imp::__get_fallback_typeid<_ValueType>());
+return _VSTD::__pointer_or_func_cast<_ReturnType>(
+__p, is_function<_ValueType>{});
 }
 return nullptr;
 }

Modified: 
libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp?rev=284333&r1=284332&r2=284333&view=diff
==
--- 
libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/any/any.nonmembers/any.cast/any_cast_pointer.pass.cpp
 Sun Oct 16 06:56:38 2016
@@ -147,6 +147,18 @@ void test_cast_non_copyable_type()
 assert(std::any_cast(&ca) == nullptr);
 }
 
+void test_fn() {}
+
+void test_cast_function_pointer() {
+using T = void(*)();
+std::any a(test_fn);
+// An any can never store a function type, but we should at least be able
+// to ask.
+assert(std::any_cast(&a) == nullptr);
+T fn_ptr = std::any_cast(a);
+assert(fn_ptr == test_fn);
+}
+
 int main() {
 test_cast_is_noexcept();
 test_cast_return_type();
@@ -155,4 +167,5 @@ int main() {
 test_cast();
 test_cast();
 test_cast_non_copyable_type();
+test_cast_function_pointer();
 }


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


[PATCH] D25659: [clang-tidy] Avoid running aliased checks twice

2016-10-16 Thread Malcolm Parsons via cfe-commits
malcolm.parsons created this revision.
malcolm.parsons added reviewers: aaron.ballman, klimek, alexfh.
malcolm.parsons added a subscriber: cfe-commits.
Herald added a subscriber: nemanjai.

It is easy to configure clang-tidy with both aliased and original
checks enabled.  This causes the check to be appear under both names
in -list-checks and -dump-config, and the check is run twice.

This changeset tells the CheckFactory about aliases so that an alias
is only enabled when the original is not enabled.


https://reviews.llvm.org/D25659

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyModule.cpp
  clang-tidy/ClangTidyModule.h
  clang-tidy/cert/CERTTidyModule.cpp
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/google/GoogleTidyModule.cpp

Index: clang-tidy/google/GoogleTidyModule.cpp
===
--- clang-tidy/google/GoogleTidyModule.cpp
+++ clang-tidy/google/GoogleTidyModule.cpp
@@ -10,10 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../readability/BracesAroundStatementsCheck.h"
-#include "../readability/FunctionSizeCheck.h"
-#include "../readability/NamespaceCommentCheck.h"
-#include "../readability/RedundantSmartptrGetCheck.h"
 #include "AvoidCStyleCastsCheck.h"
 #include "DefaultArgumentsCheck.h"
 #include "ExplicitConstructorCheck.h"
@@ -61,19 +57,16 @@
 "google-readability-casting");
 CheckFactories.registerCheck(
 "google-readability-todo");
-CheckFactories
-.registerCheck(
-"google-readability-braces-around-statements");
+CheckFactories.registerAlias("google-readability-braces-around-statements",
+ "readability-braces-around-statements");
 CheckFactories.registerCheck(
 "google-global-names-in-headers");
-CheckFactories.registerCheck(
-"google-readability-function-size");
-CheckFactories
-.registerCheck(
-"google-readability-namespace-comments");
-CheckFactories
-.registerCheck(
-"google-readability-redundant-smartptr-get");
+CheckFactories.registerAlias("google-readability-function-size",
+ "readability-function-size");
+CheckFactories.registerAlias("google-readability-namespace-comments",
+ "llvm-namespace-comment");
+CheckFactories.registerAlias("google-readability-redundant-smartptr-get",
+ "readability-redundant-smartptr-get");
   }
 
   ClangTidyOptions getModuleOptions() override {
Index: clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
===
--- clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
+++ clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
@@ -10,7 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../misc/UnconventionalAssignOperatorCheck.h"
 #include "InterfacesGlobalInitCheck.h"
 #include "ProBoundsArrayToPointerDecayCheck.h"
 #include "ProBoundsConstantArrayIndexCheck.h"
@@ -33,6 +32,9 @@
 class CppCoreGuidelinesModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+CheckFactories.registerAlias(
+"cppcoreguidelines-c-copy-assignment-signature",
+"misc-unconventional-assign-operator");
 CheckFactories.registerCheck(
 "cppcoreguidelines-interfaces-global-init");
 CheckFactories.registerCheck(
@@ -59,8 +61,6 @@
 "cppcoreguidelines-special-member-functions");
 CheckFactories.registerCheck(
 "cppcoreguidelines-slicing");
-CheckFactories.registerCheck(
-"cppcoreguidelines-c-copy-assignment-signature");
   }
 };
 
Index: clang-tidy/cert/CERTTidyModule.cpp
===
--- clang-tidy/cert/CERTTidyModule.cpp
+++ clang-tidy/cert/CERTTidyModule.cpp
@@ -10,12 +10,6 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
-#include "../google/UnnamedNamespaceInHeaderCheck.h"
-#include "../misc/MoveConstructorInitCheck.h"
-#include "../misc/NewDeleteOverloadsCheck.h"
-#include "../misc/NonCopyableObjects.h"
-#include "../misc/StaticAssertCheck.h"
-#include "../misc/ThrowByValueCatchByReferenceCheck.h"
 #include "CommandProcessorCheck.h"
 #include "FloatLoopCounter.h"
 #include "SetLongJmpCheck.h"
@@ -35,36 +29,31 @@
 // DCL
 CheckFactories.registerCheck(
 "cert-dcl50-cpp");
-CheckFactories.registerCheck(
-"cert-dcl54-cpp");
-CheckFactories.registerCheck(
-"cert-dcl59-cpp");
+CheckFactories.registerAlias("cert-dcl54-cpp", "misc-new-delete-overloads");
+CheckFactories.registerAlias("cert-dcl59-cpp", "google-build-namespaces");
 // O

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

2016-10-16 Thread Balogh , Ádám via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: dcoughlin.
baloghadamsoftware added subscribers: cfe-commits, xazax.hun, o.gyorgy.
Herald added subscribers: modocache, mgorny, beanz.

This checker checks for iterators dereferenced when they are equal to the end() 
of their container. Return value of any end() method is tracked if its type has 
the same properties as a typical iterator (can be incremented, dereferenced, 
and its name ends with "iterator", "iter" or "it"). STL functions that search a 
value or range are evaluated by the checker as an optimization.


https://reviews.llvm.org/D25660

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/IteratorPastEndChecker.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/iterator-past-end.cpp

Index: test/Analysis/iterator-past-end.cpp
===
--- /dev/null
+++ test/Analysis/iterator-past-end.cpp
@@ -0,0 +1,240 @@
+// RUN: %clang_cc1 -std=c++11 -analyze -analyzer-checker=core,cplusplus,alpha.cplusplus.IteratorPastEnd %s -verify
+
+template  struct __iterator {
+  typedef __iterator iterator;
+  typedef __iterator const_iterator;
+
+  __iterator(Ptr p) : ptr(p) {}
+  __iterator operator++() { return *this; }
+  __iterator operator++(int) { return *this; }
+  __iterator operator--() { return *this; }
+  __iterator operator--(int) { return *this; }
+  Ref operator*() const { return *ptr; }
+  Ptr operator->() const { return *ptr; }
+
+  bool operator==(const iterator &rhs) const { return ptr == rhs.ptr; }
+  bool operator==(const const_iterator &rhs) const { return ptr == rhs.ptr; }
+
+  bool operator!=(const iterator &rhs) const { return ptr != rhs.ptr; }
+  bool operator!=(const const_iterator &rhs) const { return ptr != rhs.ptr; }
+
+private:
+  Ptr ptr;
+};
+
+namespace std {
+
+template  struct vector {
+  typedef __iterator iterator;
+  typedef __iterator const_iterator;
+
+  iterator begin();
+  const_iterator begin() const;
+  iterator end();
+  const_iterator end() const;
+};
+
+template 
+InputIterator find(InputIterator first, InputIterator last, const T &val);
+template 
+ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
+  ForwardIterator2 first2, ForwardIterator2 last2);
+template 
+ForwardIterator1 find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
+   ForwardIterator2 first2, ForwardIterator2 last2);
+template 
+InputIterator find_if(InputIterator first, InputIterator last,
+  UnaryPredicate pred);
+template 
+InputIterator find_if_not(InputIterator first, InputIterator last,
+  UnaryPredicate pred);
+template 
+InputIterator lower_bound(InputIterator first, InputIterator last,
+  const T &val);
+template 
+InputIterator upper_bound(InputIterator first, InputIterator last,
+  const T &val);
+template 
+ForwardIterator1 search(ForwardIterator1 first1, ForwardIterator1 last1,
+ForwardIterator2 first2, ForwardIterator2 last2);
+template 
+ForwardIterator1 search_n(ForwardIterator1 first1, ForwardIterator1 last1,
+  ForwardIterator2 first2, ForwardIterator2 last2);
+}
+
+void simple_good(const std::vector &v) {
+  auto i = v.end();
+  if (i != v.end())
+*i; // no-warning
+}
+
+void simple_bad(const std::vector &v) {
+  auto i = v.end();
+  *i; // expected-warning{{Iterator possibly accessed past its end}}
+}
+
+void copy(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  *i2; // expected-warning{{Iterator possibly accessed past its end}}
+}
+
+void decrease(const std::vector &v) {
+  auto i = v.end();
+  --i;
+  *i; // no-warning
+}
+
+void copy_and_decrease1(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i1; // no-warning
+}
+
+void copy_and_decrease2(const std::vector &v) {
+  auto i1 = v.end();
+  auto i2 = i1;
+  --i1;
+  *i2; // expected-warning{{Iterator possibly accessed past its end}}
+}
+
+void copy_and_increase1(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i1 == v.end())
+*i2; // no-warning
+}
+
+void copy_and_increase2(const std::vector &v) {
+  auto i1 = v.begin();
+  auto i2 = i1;
+  ++i1;
+  if (i2 == v.end())
+*i2; // expected-warning{{Iterator possibly accessed past its end}}
+}
+
+void good_find(std::vector &vec, int e) {
+  auto first = std::find(vec.begin(), vec.end(), e);
+  if (vec.end() != first)
+*first; // no-warning
+}
+
+void bad_find(std::vector &vec, int e) {
+  auto first = std::find(vec.begin(), vec.end(), e);
+  *first; // expected-warning{{Iterator possibly accessed past its end}}
+}
+
+void good_find_end(std::vector &vec, std::vector &seq) {
+  auto last = std::find_end(vec.begin(), vec.end(), seq.begin(), seq.end());

[PATCH] D25661: [Driver] Support obtaining active toolchain from gcc-config on Gentoo

2016-10-16 Thread Michał Górny via cfe-commits
mgorny created this revision.
mgorny added reviewers: rafael, chandlerc, bruno, bkramer.
mgorny added a subscriber: cfe-commits.

Support using gcc-config to determine the correct GCC toolchain location
on Gentoo. In order to do that, attempt to read gcc-config configuration
form [[sysroot]]/etc/env.d/gcc, if no custom toolchain location is
provided.


https://reviews.llvm.org/D25661

Files:
  lib/Driver/ToolChains.cpp
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
  test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/include/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/include/g++-v4.9.3/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/crtbegin.o
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5.4.0/.keep
  
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/usr/x86_64-pc-linux-gnu/lib/.keep
  test/Driver/linux-header-search.cpp


Index: test/Driver/linux-header-search.cpp
===
--- test/Driver/linux-header-search.cpp
+++ test/Driver/linux-header-search.cpp
@@ -301,6 +301,15 @@
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/include"
 // CHECK-GENTOO-4-9-3: "-internal-externc-isystem" "[[SYSROOT]]/usr/include"
 //
+// Test support for Gentoo's gcc-config -- clang should prefer the older
+// (4.9.3) version over the newer (5.4.0) due to preference specified
+// in /etc/env.d/gcc/x86_64-pc-linux-gnu.
+// RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
+// RUN: -target x86_64-unknown-linux-gnu -stdlib=libstdc++ \
+// RUN: --sysroot=%S/Inputs/gentoo_linux_gcc_multi_version_tree \
+// RUN: --gcc-toolchain="" \
+// RUN:   | FileCheck --check-prefix=CHECK-GENTOO-4-9-3 %s
+//
 // Check header search on Debian 6 / MIPS64
 // RUN: %clang -no-canonical-prefixes %s -### -fsyntax-only 2>&1 \
 // RUN: -target mips64-unknown-linux-gnuabi64 -stdlib=libstdc++ \
Index: test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
===
--- /dev/null
+++ test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/gentoo-release
@@ -0,0 +1 @@
+Gentoo Base System release 2.3
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/x86_64-pc-linux-gnu-4.9.3
@@ -0,0 +1,10 @@
+PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+ROOTPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3:/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.3/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/4.9.3/info"
+STDCXX_INCDIR="g++-v4"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib32"
Index: 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
===
--- /dev/null
+++ 
test/Driver/Inputs/gentoo_linux_gcc_multi_version_tree/etc/env.d/gcc/config-x86_64-pc-linux-gnu
@@ -0,0 +1 @@
+CURRENT=x86_64-pc-linux-gnu-4.9.3
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -1430,6 +1430,43 @@
 }
   }
 
+  // Try to respect gcc-config on Gentoo. However, do that only
+  // if --gcc-toolchain is not provided or equal to the Gentoo install
+  // in /usr. This avoids accidentally enforcing the system GCC version
+  // when using a custom toolchain.
+  if (GCCToolchainDir == "" || GCCToolchainDir == D.SysRoot + "/usr") {
+for (unsigned k = 0, ke = CandidateTripleAliases.size(); k < ke; ++k) {
+  llvm::ErrorOr> File =
+  D.getVFS().getBufferForFile(D.SysRoot + "/etc/env.d/gcc/config-" +
+  CandidateTripleAliases[k].str());
+  if (File) {
+SmallVector Lines;
+File.get()->getBuffer().split(Lines, "\n");
+for (StringRef& Line : Lines) {
+  // CURRENT=triple-version
+  if (Line.startswith("CURRENT=")) {
+const std::pair ActiveVersion =
+  Line.substr(8).rsplit('-');
+// Note: Strictly speaking, we should be reading
+// /etc/env.d/gcc/${CURRENT} now. However, t

[PATCH] D25654: [Sema] Don't perform aggregate initialization for types with explicit constructors

2016-10-16 Thread Richard Smith via cfe-commits
rsmith added a comment.

Please also add a test to test/CXX/drs/dr15xx.cpp for core issue 1518, which 
this paper was resolving.




Comment at: lib/AST/DeclCXX.cpp:564
+// C++1z [dcl.init.aggr]p1:
+//  - no user-provided, explicit, or inherited constructors,
+if (getASTContext().getLangOpts().CPlusPlus1z && Constructor->isExplicit())

Do we correctly handle the "or inherited" part? I'd also like to find out 
whether core intended for this issue to be treated as a DR or not (if so, this 
should apply all the way back to C++11).


https://reviews.llvm.org/D25654



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


r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Sun Oct 16 12:26:06 2016
New Revision: 284335

URL: http://llvm.org/viewvc/llvm-project?rev=284335&view=rev
Log:
[analyzer] Make MallocChecker more robust against custom redeclarations

Add additional checking to MallocChecker to avoid crashing when memory
routines have unexpected numbers of arguments. You wouldn't expect to see much
of this in normal code (-Wincompatible-library-redeclaration warns on this),
but, for example, CMake tests can generate these.

This is PR30616.

rdar://problem/28631974

Added:
cfe/trunk/test/Analysis/malloc-custom.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=284335&r1=284334&r2=284335&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Sun Oct 16 12:26:06 
2016
@@ -778,6 +778,8 @@ void MallocChecker::checkPostStmt(const
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State);
   }
 } else if (FunI == II_kmalloc) {
+  if (CE->getNumArgs() < 1)
+return;
   llvm::Optional MaybeState =
 performKernelMalloc(CE, C, State);
   if (MaybeState.hasValue())
@@ -807,6 +809,8 @@ void MallocChecker::checkPostStmt(const
 } else if (FunI == II_strndup) {
   State = MallocUpdateRefState(C, CE, State);
 } else if (FunI == II_alloca || FunI == II_win_alloca) {
+  if (CE->getNumArgs() < 1)
+return;
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State,
AF_Alloca);
   State = ProcessZeroAllocation(C, CE, 0, State);

Added: cfe/trunk/test/Analysis/malloc-custom.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-custom.c?rev=284335&view=auto
==
--- cfe/trunk/test/Analysis/malloc-custom.c (added)
+++ cfe/trunk/test/Analysis/malloc-custom.c Sun Oct 16 12:26:06 2016
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc 
-Wno-incompatible-library-redeclaration -verify %s
+
+// Various tests to make the the analyzer is robust against custom
+// redeclarations of memory routines.
+//
+// You wouldn't expect to see much of this in normal code, but, for example,
+// CMake tests can generate these.
+
+// expected-no-diagnostics
+
+char alloca();
+char malloc();
+char realloc();
+char kmalloc();
+char valloc();
+char calloc();
+
+char free();
+char kfree();
+
+void testCustomArgumentlessAllocation() {
+  alloca(); // no-crash
+  malloc(); // no-crash
+  realloc(); // no-crash
+  kmalloc(); // no-crash
+  valloc(); // no-crash
+  calloc(); // no-crash
+
+  free(); // no-crash
+  kfree(); // no-crash
+}
+


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


r284337 - P0012R1: Make exception specifications be part of the type system. This

2016-10-16 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Oct 16 12:54:23 2016
New Revision: 284337

URL: http://llvm.org/viewvc/llvm-project?rev=284337&view=rev
Log:
P0012R1: Make exception specifications be part of the type system. This
implements the bulk of the change (modifying the type system to include
exception specifications), but not all the details just yet.

Added:
cfe/trunk/test/CXX/conv/conv.fctptr/
cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp
cfe/trunk/test/CXX/except/except.spec/p2-places-1z.cpp

cfe/trunk/test/CXX/over/over.match/over.match.best/over.best.ics/over.ics.scs/p3.cpp
cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.conv/p5.cpp
Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExceptionSpec.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p6-0x.cpp
cfe/trunk/test/CXX/drs/dr0xx.cpp
cfe/trunk/test/CXX/drs/dr1xx.cpp
cfe/trunk/test/CXX/drs/dr2xx.cpp
cfe/trunk/test/CXX/except/except.spec/p2-places.cpp
cfe/trunk/test/CXX/expr/expr.const/p3-0x.cpp
cfe/trunk/test/CXX/expr/expr.prim/expr.prim.lambda/p6.cpp
cfe/trunk/test/CXX/over/over.over/p1.cpp
cfe/trunk/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p4.cpp
cfe/trunk/test/SemaCXX/cxx0x-defaulted-functions.cpp
cfe/trunk/test/SemaCXX/deprecated.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=284337&r1=284336&r2=284337&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Oct 16 12:54:23 2016
@@ -3364,9 +3364,15 @@ public:
 return reinterpret_cast(param_type_end())[1];
   }
   /// Determine whether this function type has a non-throwing exception
+  /// specification.
+  CanThrowResult canThrow(const ASTContext &Ctx) const;
+  /// Determine whether this function type has a non-throwing exception
   /// specification. If this depends on template arguments, returns
   /// \c ResultIfDependent.
-  bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent = false) const;
+  bool isNothrow(const ASTContext &Ctx, bool ResultIfDependent = false) const {
+return ResultIfDependent ? canThrow(Ctx) != CT_Can
+ : canThrow(Ctx) == CT_Cannot;
+  }
 
   bool isVariadic() const { return Variadic; }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=284337&r1=284336&r2=284337&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Oct 16 12:54:23 
2016
@@ -1644,7 +1644,8 @@ def err_init_conversion_failed : Error<
   "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
   "volatile and restrict|const, volatile, and restrict}5 vs "
   "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
-  "volatile and restrict|const, volatile, and restrict}6)}4">;
+  "volatile and restrict|const, volatile, and restrict}6)"
+  "|: different exception specifications}4">;
 
 def err_lvalue_to_rvalue_ref : Error<"rvalue reference %diff{to type $ cannot "
   "bind to lvalue of type $|cannot bind to incompatible lvalue}0,1">;
@@ -3278,7 +3279,8 @@ def note_ovl_candidate : Note<"candidate
 "%select{none|const|restrict|const and restrict|volatile|const and 
volatile"
 "|volatile and restrict|const, volatile, and restrict}3 but found "
 "%select{none|const|restrict|const and restrict|volatile|const and 
volatile"
-"|volatile and restrict|const, volatile, and restrict}4)}2">;
+"|volatile and restrict|const, volatile, and restrict}4)"
+"| has different exception specification}2">;
 
 def note_ovl_candidate_inherited_constructor : Note<
 "constructor from base class %0 inherited here">;
@@ -6101,7 +6103,8 @@ def note_hidden_overloaded_virtual_decla
   "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
   "volatile and restrict|const, volatile, and restrict}2 vs "
   "%select{none|const|restrict|const and restrict|volatile|const and volatile|"
-  "volatile and restrict|const, volatile, and restrict}3)}1">;
+  "volatile and restrict|const, volatile, and restrict}3)"
+  "|: different exception specifications}1">;
 

Re: r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Renato Golin via cfe-commits
On 16 October 2016 at 18:26, Devin Coughlin via cfe-commits
 wrote:
> Author: dcoughlin
> Date: Sun Oct 16 12:26:06 2016
> New Revision: 284335
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284335&view=rev
> Log:
> [analyzer] Make MallocChecker more robust against custom redeclarations
>
> Add additional checking to MallocChecker to avoid crashing when memory
> routines have unexpected numbers of arguments. You wouldn't expect to see much
> of this in normal code (-Wincompatible-library-redeclaration warns on this),
> but, for example, CMake tests can generate these.

Hi Devin,

Sounds like yours:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/11121

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


Re: r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Devin Coughlin via cfe-commits

> On Oct 16, 2016, at 12:04 PM, Renato Golin  wrote:
> 
> On 16 October 2016 at 18:26, Devin Coughlin via cfe-commits
>  wrote:
>> Author: dcoughlin
>> Date: Sun Oct 16 12:26:06 2016
>> New Revision: 284335
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=284335&view=rev
>> Log:
>> [analyzer] Make MallocChecker more robust against custom redeclarations
>> 
>> Add additional checking to MallocChecker to avoid crashing when memory
>> routines have unexpected numbers of arguments. You wouldn't expect to see 
>> much
>> of this in normal code (-Wincompatible-library-redeclaration warns on this),
>> but, for example, CMake tests can generate these.
> 
> Hi Devin,
> 
> Sounds like yours:
> 
> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/11121

I’ll speculatively revert. But I don’t understand how a static analyzer-only 
change could affect either the execution time or the compile time of a 
test-suite benchmark. There’s something very funny here.

Devin

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


r284340 - Revert "[analyzer] Make MallocChecker more robust against custom redeclarations"

2016-10-16 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Sun Oct 16 14:26:07 2016
New Revision: 284340

URL: http://llvm.org/viewvc/llvm-project?rev=284340&view=rev
Log:
Revert "[analyzer] Make MallocChecker more robust against custom redeclarations"

This reverts commit r284335.

It appears to be causing test-suite compile-time and execution-time
performance measurements to take longer than expected on several bots.
This is surprising, because r284335 is a static-analyzer-only change.

Removed:
cfe/trunk/test/Analysis/malloc-custom.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=284340&r1=284339&r2=284340&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Sun Oct 16 14:26:07 
2016
@@ -778,8 +778,6 @@ void MallocChecker::checkPostStmt(const
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State);
   }
 } else if (FunI == II_kmalloc) {
-  if (CE->getNumArgs() < 1)
-return;
   llvm::Optional MaybeState =
 performKernelMalloc(CE, C, State);
   if (MaybeState.hasValue())
@@ -809,8 +807,6 @@ void MallocChecker::checkPostStmt(const
 } else if (FunI == II_strndup) {
   State = MallocUpdateRefState(C, CE, State);
 } else if (FunI == II_alloca || FunI == II_win_alloca) {
-  if (CE->getNumArgs() < 1)
-return;
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State,
AF_Alloca);
   State = ProcessZeroAllocation(C, CE, 0, State);

Removed: cfe/trunk/test/Analysis/malloc-custom.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-custom.c?rev=284339&view=auto
==
--- cfe/trunk/test/Analysis/malloc-custom.c (original)
+++ cfe/trunk/test/Analysis/malloc-custom.c (removed)
@@ -1,32 +0,0 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc 
-Wno-incompatible-library-redeclaration -verify %s
-
-// Various tests to make the the analyzer is robust against custom
-// redeclarations of memory routines.
-//
-// You wouldn't expect to see much of this in normal code, but, for example,
-// CMake tests can generate these.
-
-// expected-no-diagnostics
-
-char alloca();
-char malloc();
-char realloc();
-char kmalloc();
-char valloc();
-char calloc();
-
-char free();
-char kfree();
-
-void testCustomArgumentlessAllocation() {
-  alloca(); // no-crash
-  malloc(); // no-crash
-  realloc(); // no-crash
-  kmalloc(); // no-crash
-  valloc(); // no-crash
-  calloc(); // no-crash
-
-  free(); // no-crash
-  kfree(); // no-crash
-}
-


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


Re: r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Devin Coughlin via cfe-commits

> On Oct 16, 2016, at 12:12 PM, Devin Coughlin via cfe-commits 
>  wrote:
> 
>> 
>> On Oct 16, 2016, at 12:04 PM, Renato Golin  wrote:
>> 
>> On 16 October 2016 at 18:26, Devin Coughlin via cfe-commits
>>  wrote:
>>> Author: dcoughlin
>>> Date: Sun Oct 16 12:26:06 2016
>>> New Revision: 284335
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=284335&view=rev
>>> Log:
>>> [analyzer] Make MallocChecker more robust against custom redeclarations
>>> 
>>> Add additional checking to MallocChecker to avoid crashing when memory
>>> routines have unexpected numbers of arguments. You wouldn't expect to see 
>>> much
>>> of this in normal code (-Wincompatible-library-redeclaration warns on this),
>>> but, for example, CMake tests can generate these.
>> 
>> Hi Devin,
>> 
>> Sounds like yours:
>> 
>> http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/11121
> 
> I’ll speculatively revert. But I don’t understand how a static analyzer-only 
> change could affect either the execution time or the compile time of a 
> test-suite benchmark. There’s something very funny here.

Reverted in r284340.

Devin

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


Re: r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Renato Golin via cfe-commits
On 16 October 2016 at 20:36, Devin Coughlin  wrote:
> Reverted in r284340.

Hi Devin,

Sometimes Clang patches break on stage 2 or test-suite, but this is
not the case. I dug deeper and found that there was another commit,
not showing on that range (it should have, but that's nothing to do
with this patch), that broke the bot.

Please, re-commit your patch, and sorry for the noise.

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


Re: r284335 - [analyzer] Make MallocChecker more robust against custom redeclarations

2016-10-16 Thread Devin Coughlin via cfe-commits

> On Oct 16, 2016, at 12:53 PM, Renato Golin  wrote:
> 
> On 16 October 2016 at 20:36, Devin Coughlin  wrote:
>> Reverted in r284340.
> 
> Hi Devin,
> 
> Sometimes Clang patches break on stage 2 or test-suite, but this is
> not the case. I dug deeper and found that there was another commit,
> not showing on that range (it should have, but that's nothing to do
> with this patch), that broke the bot.
> 
> Please, re-commit your patch, and sorry for the noise.

Will do. Thanks for looking into it!

Devin

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


r284341 - AST: Improve a couple of comments and cast unused values to void

2016-10-16 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Sun Oct 16 15:12:42 2016
New Revision: 284341

URL: http://llvm.org/viewvc/llvm-project?rev=284341&view=rev
Log:
AST: Improve a couple of comments and cast unused values to void

Make these comments a bit more explicit that they're initializing the
RawText member, and explicitly cast the unused result of getRawText to
void for clarity.

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

Modified: cfe/trunk/lib/AST/RawCommentList.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RawCommentList.cpp?rev=284341&r1=284340&r2=284341&view=diff
==
--- cfe/trunk/lib/AST/RawCommentList.cpp (original)
+++ cfe/trunk/lib/AST/RawCommentList.cpp Sun Oct 16 15:12:42 2016
@@ -175,8 +175,8 @@ StringRef RawComment::getRawTextSlow(con
 }
 
 const char *RawComment::extractBriefText(const ASTContext &Context) const {
-  // Make sure that RawText is valid.
-  getRawText(Context.getSourceManager());
+  // Lazily initialize RawText using the accessor before using it.
+  (void)getRawText(Context.getSourceManager());
 
   // Since we will be copying the resulting text, all allocations made during
   // parsing are garbage after resulting string is formed.  Thus we can use
@@ -202,8 +202,8 @@ const char *RawComment::extractBriefText
 comments::FullComment *RawComment::parse(const ASTContext &Context,
  const Preprocessor *PP,
  const Decl *D) const {
-  // Make sure that RawText is valid.
-  getRawText(Context.getSourceManager());
+  // Lazily initialize RawText using the accessor before using it.
+  (void)getRawText(Context.getSourceManager());
 
   comments::Lexer L(Context.getAllocator(), Context.getDiagnostics(),
 Context.getCommentCommandTraits(),
@@ -334,4 +334,3 @@ void RawCommentList::addDeserializedComm
  BeforeThanCompare(SourceMgr));
   std::swap(Comments, MergedComments);
 }
-


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


r284351 - Revert "Revert "[analyzer] Make MallocChecker more robust against custom redeclarations""

2016-10-16 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Sun Oct 16 17:19:03 2016
New Revision: 284351

URL: http://llvm.org/viewvc/llvm-project?rev=284351&view=rev
Log:
Revert "Revert "[analyzer] Make MallocChecker more robust against custom 
redeclarations""

This reverts commit r284340 to reapply r284335. The bot breakage was due to
an unrelated change in the polybench test suite.

Added:
cfe/trunk/test/Analysis/malloc-custom.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp?rev=284351&r1=284350&r2=284351&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/MallocChecker.cpp Sun Oct 16 17:19:03 
2016
@@ -778,6 +778,8 @@ void MallocChecker::checkPostStmt(const
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State);
   }
 } else if (FunI == II_kmalloc) {
+  if (CE->getNumArgs() < 1)
+return;
   llvm::Optional MaybeState =
 performKernelMalloc(CE, C, State);
   if (MaybeState.hasValue())
@@ -807,6 +809,8 @@ void MallocChecker::checkPostStmt(const
 } else if (FunI == II_strndup) {
   State = MallocUpdateRefState(C, CE, State);
 } else if (FunI == II_alloca || FunI == II_win_alloca) {
+  if (CE->getNumArgs() < 1)
+return;
   State = MallocMemAux(C, CE, CE->getArg(0), UndefinedVal(), State,
AF_Alloca);
   State = ProcessZeroAllocation(C, CE, 0, State);

Added: cfe/trunk/test/Analysis/malloc-custom.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/malloc-custom.c?rev=284351&view=auto
==
--- cfe/trunk/test/Analysis/malloc-custom.c (added)
+++ cfe/trunk/test/Analysis/malloc-custom.c Sun Oct 16 17:19:03 2016
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc 
-Wno-incompatible-library-redeclaration -verify %s
+
+// Various tests to make the the analyzer is robust against custom
+// redeclarations of memory routines.
+//
+// You wouldn't expect to see much of this in normal code, but, for example,
+// CMake tests can generate these.
+
+// expected-no-diagnostics
+
+char alloca();
+char malloc();
+char realloc();
+char kmalloc();
+char valloc();
+char calloc();
+
+char free();
+char kfree();
+
+void testCustomArgumentlessAllocation() {
+  alloca(); // no-crash
+  malloc(); // no-crash
+  realloc(); // no-crash
+  kmalloc(); // no-crash
+  valloc(); // no-crash
+  calloc(); // no-crash
+
+  free(); // no-crash
+  kfree(); // no-crash
+}
+


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


r284352 - clang/test/CXX/conv/conv.fctptr/p1.cpp: Appease for targeting i686-win32.

2016-10-16 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Sun Oct 16 18:00:18 2016
New Revision: 284352

URL: http://llvm.org/viewvc/llvm-project?rev=284352&view=rev
Log:
clang/test/CXX/conv/conv.fctptr/p1.cpp: Appease for targeting i686-win32.

  error: 'error' diagnostics seen but not expected:
File clang\test\CXX\conv\conv.fctptr\p1.cpp Line 16: assigning to 'void 
(S::*)() __attribute__((thiscall)) noexcept' from incompatible type 'void 
(S::*)() __attribute__((thiscall))': different exception specifications

Modified:
cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp

Modified: cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp?rev=284352&r1=284351&r2=284352&view=diff
==
--- cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp (original)
+++ cfe/trunk/test/CXX/conv/conv.fctptr/p1.cpp Sun Oct 16 18:00:18 2016
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++1z -verify %s -triple x86_64-unknown-unknown
 
 struct S;
 


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


Re: [libcxx] r284214 - XFAIL aligned allocation tests for older Clang versions

2016-10-16 Thread Nico Weber via cfe-commits
See the Mac bot here: https://codereview.chromium.org/2416293003/ ->
https://build.chromium.org/p/tryserver.chromium.mac/builders/mac_upload_clang/builds/105/steps/package%20clang/logs/stdio
I think that bot uses Xcode 8's compiler. I haven't tried again since 2
days ago.

On Sat, Oct 15, 2016 at 4:08 PM, Eric Fiselier  wrote:

> Hi Nico,
>
> Are these tests still broken for you?
>
> /Eric
>
> On Fri, Oct 14, 2016 at 3:21 PM, Eric Fiselier  wrote:
>
>> Hi Nico,
>>
>> Could you give me more information about the compiler your using?
>>
>> /Eric
>>
>> On Fri, Oct 14, 2016 at 1:21 PM, Nico Weber  wrote:
>>
>>> This is breaking tests for me:
>>>
>>> Unexpected Passing Tests (4):
>>> libc++ :: std/language.support/support.d
>>> ynamic/new.delete/new.delete.array/new_align_val_t.pass.cpp
>>> libc++ :: std/language.support/support.d
>>> ynamic/new.delete/new.delete.array/new_align_val_t_nothrow.pass.cpp
>>> libc++ :: std/language.support/support.d
>>> ynamic/new.delete/new.delete.single/new_align_val_t.pass.cpp
>>> libc++ :: std/language.support/support.d
>>> ynamic/new.delete/new.delete.single/new_align_val_t_nothrow.pass.cpp
>>>
>>> Am I holding something wrong, or are these XFAILs wrong?
>>>
>>> On Fri, Oct 14, 2016 at 4:47 AM, Eric Fiselier via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
 Author: ericwf
 Date: Fri Oct 14 03:47:09 2016
 New Revision: 284214

 URL: http://llvm.org/viewvc/llvm-project?rev=284214&view=rev
 Log:
 XFAIL aligned allocation tests for older Clang versions

 Modified:
 libcxx/trunk/test/libcxx/test/config.py
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t_nothrow.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t_nothrow_replace.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t_replace.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.single/new_align_val_t.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.single/new_align_val_t_nothrow.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.single/new_align_val_t_nothrow_replace.pass.cpp
 libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.single/new_align_val_t_replace.pass.cpp

 Modified: libcxx/trunk/test/libcxx/test/config.py
 URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx
 /test/config.py?rev=284214&r1=284213&r2=284214&view=diff
 
 ==
 --- libcxx/trunk/test/libcxx/test/config.py (original)
 +++ libcxx/trunk/test/libcxx/test/config.py Fri Oct 14 03:47:09 2016
 @@ -315,6 +315,10 @@ class Configuration(object):

  if self.cxx.hasCompileFlag('-faligned-allocation'):
  self.config.available_features.add('-faligned-allocation')
 +else:
 +# FIXME remove this once more than just clang-4.0 support
 +# C++17 aligned allocation.
 +self.config.available_features
 .add('no-aligned-allocation')

  if self.get_lit_bool('has_libatomic', False):
  self.config.available_features.add('libatomic')

 Modified: libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t.pass.cpp
 URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/la
 nguage.support/support.dynamic/new.delete/new.delete.array/n
 ew_align_val_t.pass.cpp?rev=284214&r1=284213&r2=284214&view=diff
 
 ==
 --- libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t.pass.cpp (original)
 +++ libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t.pass.cpp Fri Oct 14 03:47:09
 2016
 @@ -9,11 +9,13 @@

  // UNSUPPORTED: c++98, c++03, c++11, c++14

 -// test operator new
 -
  // asan and msan will not call the new handler.
  // UNSUPPORTED: sanitizer-new-delete

 +// XFAIL: no-aligned-allocation
 +
 +// test operator new
 +
  #include 
  #include 
  #include 

 Modified: libcxx/trunk/test/std/language.support/support.dynamic/new.d
 elete/new.delete.array/new_align_val_t_nothrow.pass.cpp
 URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/la
 nguage.support/support.dynamic/new.delete/new.delete.array/n

Re: r284137 - [ThinLTO] Update doc to include lld (now supported).

2016-10-16 Thread Sean Silva via cfe-commits
Nice to see this land!

One nit:
Currently, doesn't LLD/ELF ignore -plugin-opt? That will mean that if a
user uses the "gold syntax" then LLD will silently ignore it, which isn't
good. At the very least, can we issue an error if we see `-plugin-opt
jobs=N` and suggest the LLD spelling?

Or maybe just accept the gold syntax? Our current handling of `-plugin` and
`-plugin-opt` is intended to make LLD transparently Do The Right Thing when
LLD is invoked as if it were gold, so clearly gold compatibility is
important enough for that. This suggests it is important enough to be
compatible from a ThinLTO perspective too.

-- Sean Silva

On Thu, Oct 13, 2016 at 10:42 AM, Davide Italiano via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: davide
> Date: Thu Oct 13 12:42:38 2016
> New Revision: 284137
>
> URL: http://llvm.org/viewvc/llvm-project?rev=284137&view=rev
> Log:
> [ThinLTO] Update doc to include lld (now supported).
>
> Differential Revision:  https://reviews.llvm.org/D25537
>
> Modified:
> cfe/trunk/docs/ThinLTO.rst
>
> Modified: cfe/trunk/docs/ThinLTO.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/
> ThinLTO.rst?rev=284137&r1=284136&r2=284137&view=diff
> 
> ==
> --- cfe/trunk/docs/ThinLTO.rst (original)
> +++ cfe/trunk/docs/ThinLTO.rst Thu Oct 13 12:42:38 2016
> @@ -62,8 +62,8 @@ ThinLTO is currently supported for the f
>`_.
>  - **ld64**:
>Starting with `Xcode 8 `_.
> -
> -Additionally, support is being added to the *lld* linker.
> +- **lld**:
> +  Starting with r284050 (ELF only).
>
>  Usage
>  =
> @@ -109,6 +109,8 @@ be reduced to ``N`` via:
>``-Wl,-plugin-opt,jobs=N``
>  - ld64:
>``-Wl,-mllvm,-threads=N``
> +- lld:
> +  ``-Wl,--thinlto-jobs=N``
>
>  Incremental
>  ---
>
>
> ___
> 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


Re: r284137 - [ThinLTO] Update doc to include lld (now supported).

2016-10-16 Thread Davide Italiano via cfe-commits
On Sun, Oct 16, 2016 at 6:43 PM, Sean Silva  wrote:
> Nice to see this land!
>
> One nit:
> Currently, doesn't LLD/ELF ignore -plugin-opt? That will mean that if a user
> uses the "gold syntax" then LLD will silently ignore it, which isn't good.
> At the very least, can we issue an error if we see `-plugin-opt jobs=N` and
> suggest the LLD spelling?
>
> Or maybe just accept the gold syntax? Our current handling of `-plugin` and
> `-plugin-opt` is intended to make LLD transparently Do The Right Thing when
> LLD is invoked as if it were gold, so clearly gold compatibility is
> important enough for that. This suggests it is important enough to be
> compatible from a ThinLTO perspective too.
>

I agree with what you're suggesting.  My initial vote would be for
error'ing out on anything we can't understand that's passed via
`-plugin-opt` and see what breaks (and add incremental support for
every feature needed).
Teresa, Rafael, any opinions about it?

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r284355 - [CUDA] Fix false-positive in known-emitted handling.

2016-10-16 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Sun Oct 16 21:25:55 2016
New Revision: 284355

URL: http://llvm.org/viewvc/llvm-project?rev=284355&view=rev
Log:
[CUDA] Fix false-positive in known-emitted handling.

Previously: When compiling for host, our constructed call graph went
*through* kernel calls.  This meant that if we had

  host calls kernel calls HD

we would incorrectly mark the HD function as known-emitted on the host
side, and thus perform host-side checks on it.

Fixing this exposed another issue, wherein when marking a function as
known-emitted, we also need to traverse the callgraph of its template,
because non-dependent calls are attached to a function's template, not
its instantiation.

Added:
cfe/trunk/test/SemaCUDA/trace-through-global.cu
Modified:
cfe/trunk/lib/Sema/SemaCUDA.cpp

Modified: cfe/trunk/lib/Sema/SemaCUDA.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCUDA.cpp?rev=284355&r1=284354&r2=284355&view=diff
==
--- cfe/trunk/lib/Sema/SemaCUDA.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCUDA.cpp Sun Oct 16 21:25:55 2016
@@ -644,10 +644,16 @@ static void MarkKnownEmitted(Sema &S, Fu
 S.CUDAKnownEmittedFns.insert(Caller);
 EmitDeferredDiags(S, Caller);
 
-// Deferred diags are often emitted on the template itself, so emit those 
as
-// well.
-if (auto *Templ = Caller->getPrimaryTemplate())
-  EmitDeferredDiags(S, Templ->getAsFunction());
+// If this is a template instantiation, explore its callgraph as well:
+// Non-dependent calls are part of the template's callgraph, while 
dependent
+// calls are part of to the instantiation's call graph.
+if (auto *Templ = Caller->getPrimaryTemplate()) {
+  FunctionDecl *TemplFD = Templ->getAsFunction();
+  if (!Seen.count(TemplFD) && !S.CUDAKnownEmittedFns.count(TemplFD)) {
+Seen.insert(TemplFD);
+Worklist.push_back(TemplFD);
+  }
+}
 
 // Add all functions called by Caller to our worklist.
 auto CGIt = S.CUDACallGraph.find(Caller);
@@ -676,11 +682,21 @@ bool Sema::CheckCUDACall(SourceLocation
   if (!Caller)
 return true;
 
+  // If the caller is known-emitted, mark the callee as known-emitted.
+  // Otherwise, mark the call in our call graph so we can traverse it later.
   bool CallerKnownEmitted = IsKnownEmitted(*this, Caller);
   if (CallerKnownEmitted)
 MarkKnownEmitted(*this, Callee);
-  else
-CUDACallGraph[Caller].insert(Callee);
+  else {
+// If we have
+//   host fn calls kernel fn calls host+device,
+// the HD function does not get instantiated on the host.  We model this by
+// omitting at the call to the kernel from the callgraph.  This ensures
+// that, when compiling for host, only HD functions actually called from 
the
+// host get marked as known-emitted.
+if (getLangOpts().CUDAIsDevice || IdentifyCUDATarget(Callee) != CFT_Global)
+  CUDACallGraph[Caller].insert(Callee);
+  }
 
   CUDADiagBuilder::Kind DiagKind = [&] {
 switch (IdentifyCUDAPreference(Caller, Callee)) {

Added: cfe/trunk/test/SemaCUDA/trace-through-global.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCUDA/trace-through-global.cu?rev=284355&view=auto
==
--- cfe/trunk/test/SemaCUDA/trace-through-global.cu (added)
+++ cfe/trunk/test/SemaCUDA/trace-through-global.cu Sun Oct 16 21:25:55 2016
@@ -0,0 +1,44 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// Check that it's OK for kernels to call HD functions that call device-only
+// functions.
+
+#include "Inputs/cuda.h"
+
+__device__ void device_fn(int) {}
+// expected-note@-1 {{declared here}}
+// expected-note@-2 {{declared here}}
+
+inline __host__ __device__ int hd1() {
+  device_fn(0);  // expected-error {{reference to __device__ function}}
+  return 0;
+}
+
+inline __host__ __device__ int hd2() {
+  // No error here because hd2 is only referenced from a kernel.
+  device_fn(0);
+  return 0;
+}
+
+inline __host__ __device__ void hd3(int) {
+  device_fn(0);  // expected-error {{reference to __device__ function 
'device_fn'}}
+}
+inline __host__ __device__ void hd3(double) {}
+
+inline __host__ __device__ void hd4(int) {}
+inline __host__ __device__ void hd4(double) {
+  device_fn(0);  // No error; this function is never called.
+}
+
+__global__ void kernel(int) { hd2(); }
+
+template 
+void launch_kernel() {
+  kernel<<<0, 0>>>(T());
+  hd1();
+  hd3(T());
+}
+
+void host_fn() {
+  launch_kernel();
+}


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


[PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-10-16 Thread Vitaly Buka via cfe-commits
vitalybuka updated this revision to Diff 74813.
vitalybuka marked 5 inline comments as done.
vitalybuka added a comment.
Herald added a subscriber: modocache.

- updated comments
- indirect jumps
- optimized Detect()


https://reviews.llvm.org/D24693

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/VarBypassDetector.cpp
  lib/CodeGen/VarBypassDetector.h
  test/CodeGen/lifetime2.c

Index: test/CodeGen/lifetime2.c
===
--- test/CodeGen/lifetime2.c
+++ test/CodeGen/lifetime2.c
@@ -1,8 +1,9 @@
-// RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefix=O2
-// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0
+// RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefixes=CHECK,O2
+// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefixes=CHECK,O0
 
 extern int bar(char *A, int n);
 
+// CHECK-LABEL: @foo
 // O0-NOT: @llvm.lifetime.start
 int foo (int n) {
   if (n) {
@@ -15,3 +16,66 @@
 return bar(A, 2);
   }
 }
+
+// CHECK-LABEL: @no_goto_bypass
+void no_goto_bypass() {
+  // O2: @llvm.lifetime.start(i64 1
+  char x;
+l1:
+  bar(&x, 1);
+  // O2: @llvm.lifetime.start(i64 5
+  // O2: @llvm.lifetime.end(i64 5
+  char y[5];
+  bar(y, 5);
+  goto l1;
+  // Infinite loop
+  // O2-NOT: @llvm.lifetime.end(i64 1
+}
+
+// CHECK-LABEL: @goto_bypass
+void goto_bypass() {
+  {
+// O2-NOT: @llvm.lifetime.start(i64 1
+// O2-NOT: @llvm.lifetime.end(i64 1
+char x;
+  l1:
+bar(&x, 1);
+  }
+  goto l1;
+}
+
+// CHECK-LABEL: @no_switch_bypass
+void no_switch_bypass(int n) {
+  switch (n) {
+  case 1: {
+// O2: @llvm.lifetime.start(i64 1
+// O2: @llvm.lifetime.end(i64 1
+char x;
+bar(&x, 1);
+break;
+  }
+  case 2:
+n = n;
+// O2: @llvm.lifetime.start(i64 5
+// O2: @llvm.lifetime.end(i64 5
+char y[5];
+bar(y, 5);
+break;
+  }
+}
+
+// CHECK-LABEL: @switch_bypass
+void switch_bypass(int n) {
+  switch (n) {
+  case 1:
+n = n;
+// O2-NOT: @llvm.lifetime.start(i64 1
+// O2-NOT: @llvm.lifetime.end(i64 1
+char x;
+bar(&x, 1);
+break;
+  case 2:
+bar(&x, 1);
+break;
+  }
+}
Index: lib/CodeGen/VarBypassDetector.h
===
--- /dev/null
+++ lib/CodeGen/VarBypassDetector.h
@@ -0,0 +1,70 @@
+//===--- VarBypassDetector.cpp - Bypass jumps detector *- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file contains VarBypassDetector class, which is used to detect
+// local variable declarations which can be bypassed by jumps.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
+#define LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+class Decl;
+class Stmt;
+class VarDecl;
+
+namespace CodeGen {
+
+/// The class detects jumps which bypass local variables declaration:
+///goto L;
+///int a;
+///  L:
+///
+/// This is simplified version of JumpScopeChecker. Primary differences:
+///  * Detects only jumps into the scope local variables.
+///  * Does not detect jumps out of the scope of local variables.
+///  * Not limited to variables with initializers, JumpScopeChecker is limited.
+class VarBypassDetector {
+  // Scope information. Contains a parent scope and related variable
+  // declaration.
+  llvm::SmallVector, 48> Scopes;
+  // Lookup map to file scope for jumps.
+  llvm::SmallVector, 16> FromScopes;
+  // Lookup map to file scope for destinations.
+  llvm::DenseMap ToScopes;
+  // Set of variables which were bypassed by some jump.
+  llvm::DenseSet Bypasses;
+  // If true assume that all variables are being bypassed.
+  bool AlwaysBypassed = false;
+
+public:
+  void Init(const Stmt *Body);
+
+  /// Returns true if the variable declaration was by bypassed by any goto or
+  /// switch statement.
+  bool IsBypassed(const VarDecl *D) const {
+return AlwaysBypassed || Bypasses.find(D) != Bypasses.end();
+  }
+
+private:
+  bool BuildScopeInformation(const Decl *D, unsigned &ParentScope);
+  bool BuildScopeInformation(const Stmt *S, unsigned &origParentScope);
+  void Detect();
+  void Detect(unsigned From, unsigned To);
+};
+}
+}
+
+#endif
Index: lib/CodeGen/VarBypassDetector.cpp
===
--- /dev/null
+++ lib/CodeGen/VarBypassDetector.cpp
@@ -0,0 +1,168 @@
+//===--- VarBypassDetector.h - Bypass jumps detector --*- C++ -*-=//
+//
+// 

[clang-tools-extra] r284359 - Reformat.

2016-10-16 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Mon Oct 17 00:08:49 2016
New Revision: 284359

URL: http://llvm.org/viewvc/llvm-project?rev=284359&view=rev
Log:
Reformat.

Modified:
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=284359&r1=284358&r2=284359&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Mon Oct 17 
00:08:49 2016
@@ -213,7 +213,7 @@ runClangMoveOnCode(const move::ClangMove
 
 TEST(ClangMove, MoveHeaderAndCC) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = { "a::b::Foo" };
+  Spec.Names = {"a::b::Foo"};
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";
@@ -228,7 +228,7 @@ TEST(ClangMove, MoveHeaderAndCC) {
 
 TEST(ClangMove, MoveHeaderOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = { "a::b::Foo" };
+  Spec.Names = {"a::b::Foo"};
   Spec.OldHeader = "foo.h";
   Spec.NewHeader = "new_foo.h";
   auto Results = runClangMoveOnCode(Spec);
@@ -239,7 +239,7 @@ TEST(ClangMove, MoveHeaderOnly) {
 
 TEST(ClangMove, MoveCCOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = { "a::b::Foo" };
+  Spec.Names = {"a::b::Foo"};
   Spec.OldCC = "foo.cc";
   Spec.NewCC = "new_foo.cc";
   std::string ExpectedHeader = "#include \"foo.h\"\n\n";
@@ -251,7 +251,7 @@ TEST(ClangMove, MoveCCOnly) {
 
 TEST(ClangMove, MoveNonExistClass) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = { "NonExistFoo" };
+  Spec.Names = {"NonExistFoo"};
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";


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


[clang-tools-extra] r284360 - ClangMoveTests.cpp: Appease msc18.

2016-10-16 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Mon Oct 17 00:09:58 2016
New Revision: 284360

URL: http://llvm.org/viewvc/llvm-project?rev=284360&view=rev
Log:
ClangMoveTests.cpp: Appease msc18.

  clang-tools-extra\unittests\clang-move\ClangMoveTests.cpp(216) : error C2593: 
'operator =' is ambiguous
  llvm\include\llvm/ADT/SmallVector.h(898): could be 'const 
llvm::SmallVector &llvm::SmallVector::operator 
=(std::initializer_list,std::allocator>>)'
  llvm\include\llvm/ADT/SmallVector.h(893): or   'const 
llvm::SmallVector &llvm::SmallVector::operator 
=(llvm::SmallVectorImpl &&)'
  with
  [
  T=std::string
  ]
  llvm\include\llvm/ADT/SmallVector.h(883): or   'const 
llvm::SmallVector &llvm::SmallVector::operator 
=(llvm::SmallVector &&)'
  llvm\include\llvm/ADT/SmallVector.h(873): or   'const 
llvm::SmallVector &llvm::SmallVector::operator 
=(const llvm::SmallVector &)'
  while trying to match the argument list 
'(llvm::SmallVector, initializer-list)'

Modified:
clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp

Modified: clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp?rev=284360&r1=284359&r2=284360&view=diff
==
--- clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-move/ClangMoveTests.cpp Mon Oct 17 
00:09:58 2016
@@ -213,7 +213,7 @@ runClangMoveOnCode(const move::ClangMove
 
 TEST(ClangMove, MoveHeaderAndCC) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = {"a::b::Foo"};
+  Spec.Names = {std::string("a::b::Foo")};
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";
@@ -228,7 +228,7 @@ TEST(ClangMove, MoveHeaderAndCC) {
 
 TEST(ClangMove, MoveHeaderOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = {"a::b::Foo"};
+  Spec.Names = {std::string("a::b::Foo")};
   Spec.OldHeader = "foo.h";
   Spec.NewHeader = "new_foo.h";
   auto Results = runClangMoveOnCode(Spec);
@@ -239,7 +239,7 @@ TEST(ClangMove, MoveHeaderOnly) {
 
 TEST(ClangMove, MoveCCOnly) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = {"a::b::Foo"};
+  Spec.Names = {std::string("a::b::Foo")};
   Spec.OldCC = "foo.cc";
   Spec.NewCC = "new_foo.cc";
   std::string ExpectedHeader = "#include \"foo.h\"\n\n";
@@ -251,7 +251,7 @@ TEST(ClangMove, MoveCCOnly) {
 
 TEST(ClangMove, MoveNonExistClass) {
   move::ClangMoveTool::MoveDefinitionSpec Spec;
-  Spec.Names = {"NonExistFoo"};
+  Spec.Names = {std::string("NonExistFoo")};
   Spec.OldHeader = "foo.h";
   Spec.OldCC = "foo.cc";
   Spec.NewHeader = "new_foo.h";


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


[PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-10-16 Thread Vitaly Buka via cfe-commits
vitalybuka updated this revision to Diff 74814.
vitalybuka added a comment.

- fixed comment
- added test for indirect jumps


https://reviews.llvm.org/D24693

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CMakeLists.txt
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/VarBypassDetector.cpp
  lib/CodeGen/VarBypassDetector.h
  test/CodeGen/lifetime2.c

Index: test/CodeGen/lifetime2.c
===
--- test/CodeGen/lifetime2.c
+++ test/CodeGen/lifetime2.c
@@ -1,8 +1,9 @@
-// RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefix=O2
-// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefix=O0
+// RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefixes=CHECK,O2
+// RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefixes=CHECK,O0
 
 extern int bar(char *A, int n);
 
+// CHECK-LABEL: @foo
 // O0-NOT: @llvm.lifetime.start
 int foo (int n) {
   if (n) {
@@ -15,3 +16,76 @@
 return bar(A, 2);
   }
 }
+
+// CHECK-LABEL: @no_goto_bypass
+void no_goto_bypass() {
+  // O2: @llvm.lifetime.start(i64 1
+  char x;
+l1:
+  bar(&x, 1);
+  // O2: @llvm.lifetime.start(i64 5
+  // O2: @llvm.lifetime.end(i64 5
+  char y[5];
+  bar(y, 5);
+  goto l1;
+  // Infinite loop
+  // O2-NOT: @llvm.lifetime.end(i64 1
+}
+
+// CHECK-LABEL: @goto_bypass
+void goto_bypass() {
+  {
+// O2-NOT: @llvm.lifetime.start(i64 1
+// O2-NOT: @llvm.lifetime.end(i64 1
+char x;
+  l1:
+bar(&x, 1);
+  }
+  goto l1;
+}
+
+// CHECK-LABEL: @no_switch_bypass
+void no_switch_bypass(int n) {
+  switch (n) {
+  case 1: {
+// O2: @llvm.lifetime.start(i64 1
+// O2: @llvm.lifetime.end(i64 1
+char x;
+bar(&x, 1);
+break;
+  }
+  case 2:
+n = n;
+// O2: @llvm.lifetime.start(i64 5
+// O2: @llvm.lifetime.end(i64 5
+char y[5];
+bar(y, 5);
+break;
+  }
+}
+
+// CHECK-LABEL: @switch_bypass
+void switch_bypass(int n) {
+  switch (n) {
+  case 1:
+n = n;
+// O2-NOT: @llvm.lifetime.start(i64 1
+// O2-NOT: @llvm.lifetime.end(i64 1
+char x;
+bar(&x, 1);
+break;
+  case 2:
+bar(&x, 1);
+break;
+  }
+}
+
+// CHECK-LABEL: @indirect_jump
+void indirect_jump(int n) {
+  char x;
+  // O2-NOT: @llvm.lifetime
+  void *T[] = {&&L};
+  goto *T[n];
+L:
+  bar(&x, 1);
+}
Index: lib/CodeGen/VarBypassDetector.h
===
--- /dev/null
+++ lib/CodeGen/VarBypassDetector.h
@@ -0,0 +1,70 @@
+//===--- VarBypassDetector.cpp - Bypass jumps detector *- C++ -*-=//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file contains VarBypassDetector class, which is used to detect
+// local variable declarations which can be bypassed by jumps.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
+#define LLVM_CLANG_LIB_CODEGEN_VARBYPASSDETECTOR_H
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace clang {
+
+class Decl;
+class Stmt;
+class VarDecl;
+
+namespace CodeGen {
+
+/// The class detects jumps which bypass local variables declaration:
+///goto L;
+///int a;
+///  L:
+///
+/// This is simplified version of JumpScopeChecker. Primary differences:
+///  * Detects only jumps into the scope local variables.
+///  * Does not detect jumps out of the scope of local variables.
+///  * Not limited to variables with initializers, JumpScopeChecker is limited.
+class VarBypassDetector {
+  // Scope information. Contains a parent scope and related variable
+  // declaration.
+  llvm::SmallVector, 48> Scopes;
+  // List of jumps with scopes.
+  llvm::SmallVector, 16> FromScopes;
+  // Lookup map to find scope for destinations.
+  llvm::DenseMap ToScopes;
+  // Set of variables which were bypassed by some jump.
+  llvm::DenseSet Bypasses;
+  // If true assume that all variables are being bypassed.
+  bool AlwaysBypassed = false;
+
+public:
+  void Init(const Stmt *Body);
+
+  /// Returns true if the variable declaration was by bypassed by any goto or
+  /// switch statement.
+  bool IsBypassed(const VarDecl *D) const {
+return AlwaysBypassed || Bypasses.find(D) != Bypasses.end();
+  }
+
+private:
+  bool BuildScopeInformation(const Decl *D, unsigned &ParentScope);
+  bool BuildScopeInformation(const Stmt *S, unsigned &origParentScope);
+  void Detect();
+  void Detect(unsigned From, unsigned To);
+};
+}
+}
+
+#endif
Index: lib/CodeGen/VarBypassDetector.cpp
===
--- /dev/null
+++ lib/CodeGen/VarBypassDetector.cpp
@@ -0,0 +1,168 @@
+//===--- VarBypassDetector.h - Bypass jumps 

[PATCH] D24693: [CodeGen] Don't emit lifetime intrinsics for some local variables

2016-10-16 Thread Vitaly Buka via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added a comment.

Please take a look. Meanwhile, I will investigate performance footprint.

In https://reviews.llvm.org/D24693#559781, @rsmith wrote:

> Is there some reasonable base set of functionality between this and 
> JumpDiagnostics that could be factored out and shared?


I tried to do so from beginning but seems common part is only recursive 
traversal of AST. Sharing this will likely make both classes less readable.
In my taste it would be easier to maintain them separately.




Comment at: lib/CodeGen/VarBypassDetector.cpp:50-51
+  // If this is a statement, rather than an expression, scopes within it don't
+  // propagate out into the enclosing scope.  Otherwise we have to worry
+  // about block literals, which have the lifetime of their enclosing 
statement.
+  unsigned independentParentScope = origParentScope;

rsmith wrote:
> Comment seems to not be relevant in this copy of the code; we don't have any 
> special case for block literals here.
I read this comment as explanation of "origParentScope : 
independentParentScope" and it's still needed and  relevant.



Comment at: lib/CodeGen/VarBypassDetector.cpp:82-86
+  case Stmt::CaseStmtClass:
+  case Stmt::DefaultStmtClass:
+  case Stmt::LabelStmtClass:
+LabelAndGotoScopes[S] = ParentScope;
+break;

rsmith wrote:
> This looks unreachable (our only callers are the recursive call below -- 
> which already checked for these -- and cases that cannot have a labelled 
> statement). If we did reach it, we'd do the wrong thing, because we'd have 
> created an independent scope rather than reusing the parent's scope (`x: int 
> n;` would not introduce a new scope into the parent for `n`). Maybe replace 
> this case with `llvm_unreachable`, or move the `while (true)` loop below up 
> to the top of this function and delete these cases.
> 
> Do we have the same issue in JumpDiagnostics?
Done here, but can't do for  JumpDiagnostics. there are various 
BuildScopeInformation which can have label as child.


https://reviews.llvm.org/D24693



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


r284366 - AST: Prefer LLVM_NODISCARD to LLVM_ATTRIBUTE_UNUSED_RESULT

2016-10-16 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Mon Oct 17 01:46:35 2016
New Revision: 284366

URL: http://llvm.org/viewvc/llvm-project?rev=284366&view=rev
Log:
AST: Prefer LLVM_NODISCARD to LLVM_ATTRIBUTE_UNUSED_RESULT

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=284366&r1=284365&r2=284366&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Mon Oct 17 01:46:35 2016
@@ -787,7 +787,7 @@ namespace {
 /// (Foo(), 1)  // use noteSideEffect
 /// (Foo() || true) // use noteSideEffect
 /// Foo() + 1   // use noteFailure
-LLVM_ATTRIBUTE_UNUSED_RESULT bool noteFailure() {
+LLVM_NODISCARD bool noteFailure() {
   // Failure when evaluating some expression often means there is some
   // subexpression whose evaluation was skipped. Therefore, (because we
   // don't track whether we skipped an expression when unwinding after an


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