Re: [PATCH] D13474: [VFS] Port tooling to use the in-memory file system.

2015-10-09 Thread Manuel Klimek via cfe-commits
klimek accepted this revision.
klimek added a comment.
This revision is now accepted and ready to land.

lg


http://reviews.llvm.org/D13474



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


Re: [PATCH] D13474: [VFS] Port tooling to use the in-memory file system.

2015-10-09 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL249815: [VFS] Port tooling to use the in-memory file system. 
(authored by d0k).

Changed prior to commit:
  http://reviews.llvm.org/D13474?vs=36632=36929#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D13474

Files:
  cfe/trunk/include/clang/Tooling/Tooling.h
  cfe/trunk/lib/Tooling/Tooling.cpp
  cfe/trunk/unittests/Tooling/ToolingTest.cpp

Index: cfe/trunk/include/clang/Tooling/Tooling.h
===
--- cfe/trunk/include/clang/Tooling/Tooling.h
+++ cfe/trunk/include/clang/Tooling/Tooling.h
@@ -243,6 +243,7 @@
   ///
   /// \param FilePath The path at which the content will be mapped.
   /// \param Content A null terminated buffer of the file's content.
+  // FIXME: remove this when all users have migrated!
   void mapVirtualFile(StringRef FilePath, StringRef Content);
 
   /// \brief Run the clang invocation.
@@ -331,9 +332,12 @@
   std::vector SourcePaths;
   std::shared_ptr PCHContainerOps;
 
+  llvm::IntrusiveRefCntPtr OverlayFileSystem;
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem;
   llvm::IntrusiveRefCntPtr Files;
   // Contains a list of pairs (, ).
   std::vector< std::pair > MappedFileContents;
+  llvm::StringSet<> SeenWorkingDirectories;
 
   ArgumentsAdjuster ArgsAdjuster;
 
Index: cfe/trunk/lib/Tooling/Tooling.cpp
===
--- cfe/trunk/lib/Tooling/Tooling.cpp
+++ cfe/trunk/lib/Tooling/Tooling.cpp
@@ -32,13 +32,6 @@
 #include "llvm/Support/Host.h"
 #include "llvm/Support/raw_ostream.h"
 
-// For chdir, see the comment in ClangTool::run for more information.
-#ifdef LLVM_ON_WIN32
-#  include 
-#else
-#  include 
-#endif
-
 #define DEBUG_TYPE "clang-tooling"
 
 namespace clang {
@@ -131,18 +124,25 @@
 
   SmallString<16> FileNameStorage;
   StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage);
+  llvm::IntrusiveRefCntPtr OverlayFileSystem(
+  new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
+  llvm::IntrusiveRefCntPtr InMemoryFileSystem(
+  new vfs::InMemoryFileSystem);
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   llvm::IntrusiveRefCntPtr Files(
-  new FileManager(FileSystemOptions()));
+  new FileManager(FileSystemOptions(), OverlayFileSystem));
   ToolInvocation Invocation(getSyntaxOnlyToolArgs(Args, FileNameRef),
 ToolAction, Files.get(), PCHContainerOps);
 
   SmallString<1024> CodeStorage;
-  Invocation.mapVirtualFile(FileNameRef,
-Code.toNullTerminatedStringRef(CodeStorage));
+  InMemoryFileSystem->addFile(FileNameRef, 0,
+  llvm::MemoryBuffer::getMemBuffer(
+  Code.toNullTerminatedStringRef(CodeStorage)));
 
   for (auto  : VirtualMappedFiles) {
-Invocation.mapVirtualFile(FilenameWithContent.first,
-  FilenameWithContent.second);
+InMemoryFileSystem->addFile(
+FilenameWithContent.first, 0,
+llvm::MemoryBuffer::getMemBuffer(FilenameWithContent.second));
   }
 
   return Invocation.run();
@@ -250,6 +250,7 @@
   }
   std::unique_ptr Invocation(
   newInvocation(, *CC1Args));
+  // FIXME: remove this when all users have migrated!
   for (const auto  : MappedFileContents) {
 // Inject the code as the given file name into the preprocessor options.
 std::unique_ptr Input =
@@ -308,7 +309,11 @@
  std::shared_ptr PCHContainerOps)
 : Compilations(Compilations), SourcePaths(SourcePaths),
   PCHContainerOps(PCHContainerOps),
-  Files(new FileManager(FileSystemOptions())), DiagConsumer(nullptr) {
+  OverlayFileSystem(new vfs::OverlayFileSystem(vfs::getRealFileSystem())),
+  InMemoryFileSystem(new vfs::InMemoryFileSystem),
+  Files(new FileManager(FileSystemOptions(), OverlayFileSystem)),
+  DiagConsumer(nullptr) {
+  OverlayFileSystem->pushOverlay(InMemoryFileSystem);
   appendArgumentsAdjuster(getClangStripOutputAdjuster());
   appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
 }
@@ -346,6 +351,16 @@
   if (std::error_code EC = llvm::sys::fs::current_path(InitialDirectory))
 llvm::report_fatal_error("Cannot detect current path: " +
  Twine(EC.message()));
+
+  // First insert all absolute paths into the in-memory VFS. These are global
+  // for all compile commands.
+  if (SeenWorkingDirectories.insert("/").second)
+for (const auto  : MappedFileContents)
+  if (llvm::sys::path::is_absolute(MappedFile.first))
+InMemoryFileSystem->addFile(
+MappedFile.first, 0,
+llvm::MemoryBuffer::getMemBuffer(MappedFile.second));
+
   bool ProcessingFailed = false;
   for (const auto  : SourcePaths) {
 std::string File(getAbsolutePath(SourcePath));
@@ -376,9 +391,21 @@
   // difference for example on network 

Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-10-09 Thread Sean Eveson via cfe-commits
seaneveson updated this revision to Diff 36927.
seaneveson added a comment.

Updated to latest trunk.
Added FIXME test for circular reference issue.


http://reviews.llvm.org/D13099

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  lib/StaticAnalyzer/Core/CallEvent.cpp
  test/Analysis/const-method-call.cpp

Index: test/Analysis/const-method-call.cpp
===
--- test/Analysis/const-method-call.cpp
+++ test/Analysis/const-method-call.cpp
@@ -0,0 +1,230 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(bool);
+
+struct A {
+  int x;
+  void foo() const;
+  void bar();
+};
+
+struct B {
+  mutable int mut;
+  void foo() const;
+};
+
+struct C {
+  int *p;
+  void foo() const;
+};
+
+struct MutBase {
+  mutable int b_mut;
+};
+
+struct MutDerived : MutBase {
+  void foo() const;
+};
+
+struct PBase {
+  int *p;
+};
+
+struct PDerived : PBase {
+  void foo() const;
+};
+
+struct Inner {
+  int x;
+  int *p;
+  void bar() const;
+};
+
+struct Outer {
+  int x;
+  Inner in;
+  void foo() const;
+};
+
+void checkThatConstMethodWithoutDefinitionDoesNotInvalidateObject() {
+  A t;
+  t.x = 3;
+  t.foo();
+  clang_analyzer_eval(t.x == 3); // expected-warning{{TRUE}}
+  // Test non-const does invalidate
+  t.bar();
+  clang_analyzer_eval(t.x); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatConstMethodDoesInvalidateMutableFields() {
+  B t;
+  t.mut = 4;
+  t.foo();
+  clang_analyzer_eval(t.mut); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatConstMethodDoesInvalidatePointedAtMemory() {
+  int x = 1;
+  C t;
+  t.p = 
+  t.foo();
+  clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(t.p == ); // expected-warning{{TRUE}}
+}
+
+void checkThatConstMethodDoesInvalidateInheritedMutableFields() {
+  MutDerived t;
+  t.b_mut = 4;
+  t.foo();
+  clang_analyzer_eval(t.b_mut); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatConstMethodDoesInvalidateInheritedPointedAtMemory() {
+  int x = 1;
+  PDerived t;
+  t.p = 
+  t.foo();
+  clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(t.p == ); // expected-warning{{TRUE}}
+}
+
+void checkThatConstMethodDoesInvalidateContainedPointedAtMemory() {
+  int x = 1;
+  Outer t;
+  t.x = 2;
+  t.in.p = 
+  t.foo();
+  clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(t.x == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(t.in.p == ); // expected-warning{{TRUE}}
+}
+
+void checkThatContainedConstMethodDoesNotInvalidateObjects() {
+  Outer t;
+  t.x = 1;
+  t.in.x = 2;
+  t.in.bar();
+  clang_analyzer_eval(t.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(t.in.x == 2); // expected-warning{{TRUE}}
+}
+
+// --- Versions of the above tests where the const method is inherited --- //
+
+struct B1 {
+  void foo() const;
+};
+
+struct D1 : public B1 {
+  int x;
+};
+
+struct D2 : public B1 {
+  mutable int mut;
+};
+
+struct D3 : public B1 {
+  int *p;
+};
+
+struct DInner : public B1 {
+  int x;
+  int *p;
+};
+
+struct DOuter : public B1 {
+  int x;
+  DInner in;
+};
+
+void checkThatInheritedConstMethodDoesNotInvalidateObject() {
+  D1 t;
+  t.x = 1;
+  t.foo();
+  clang_analyzer_eval(t.x == 1); // expected-warning{{TRUE}}
+}
+
+void checkThatInheritedConstMethodDoesInvalidateMutableFields() {
+  D2 t;
+  t.mut = 1;
+  t.foo();
+  clang_analyzer_eval(t.mut); // expected-warning{{UNKNOWN}}
+}
+
+void checkThatInheritedConstMethodDoesInvalidatePointedAtMemory() {
+  int x = 1;
+  D3 t;
+  t.p = 
+  t.foo();
+  clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(t.p == ); // expected-warning{{TRUE}}
+}
+
+void checkThatInheritedConstMethodDoesInvalidateContainedPointedAtMemory() {
+  int x = 1;
+  DOuter t;
+  t.x = 2;
+  t.in.x = 3;
+  t.in.p = 
+  t.foo();
+  clang_analyzer_eval(x); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(t.x == 2); // expected-warning{{TRUE}}
+  clang_analyzer_eval(t.in.x == 3); // expected-warning{{TRUE}}
+  clang_analyzer_eval(t.in.p == ); // expected-warning{{TRUE}}
+}
+
+void checkThatInheritedContainedConstMethodDoesNotInvalidateObjects() {
+  DOuter t;
+  t.x = 1;
+  t.in.x = 2;
+  t.in.foo();
+  clang_analyzer_eval(t.x == 1); // expected-warning{{TRUE}}
+  clang_analyzer_eval(t.in.x == 2); // expected-warning{{TRUE}}
+}
+
+// --- PR21606 --- //
+
+struct s1 {
+void g(const int *i) const;
+};
+
+struct s2 {
+void f(int *i) {
+m_i = i;
+m_s.g(m_i);
+if (m_i)
+*i = 42; // no-warning
+}
+
+int *m_i;
+s1 m_s;
+};
+
+void PR21606()
+{
+s2().f(0);
+}
+
+// FIXME
+// When there is a circular reference to an object and a const method is called
+// the object is not invalidated because TK_PreserveContents has already been
+// set.
+struct Outer2;
+
+struct InnerWithRef {
+  Outer2 *ref;
+};
+
+struct Outer2 {
+  int x;
+  

[PATCH] D13614: [Extension] Optimizing passed by-value const objects.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo created this revision.
lvoufo added reviewers: chandlerc, dberlin, majnemer, nicholas.
lvoufo added a subscriber: cfe-commits.

Continued from D13603, handling functions that are defined with const 
parameters.

http://reviews.llvm.org/D13614

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,10 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,402 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const
+// variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+#define Const const
+#else
+#define Const
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+struct A {
+  int a;
+  int b;
+  A(int a) : a(a) {}
+};
+
+// A with explicit destructor
+struct D {
+  int a;
+  int b;
+  D(int a) : a(a) {}
+  ~D();
+};
+
+// A with mutable data field.
+struct M {
+  int a;
+  mutable int b;
+  M(int a) : a(a) {}
+  void f() {}
+};
+
+// A with non-trivial method that may write to memory.
+struct F {
+  int a;
+  F(int a) : a(a) {}
+  void f();
+};
+
+// A non-virtual base class.
+struct Base {
+  int pa;
+  Base(int a);
+};
+struct I : public Base {
+  int a;
+  int b;
+  I(int a);
+};
+
+// A virtual base class, not-writeonce.
+struct VBase {
+  int pa;
+  VBase(int a);
+  virtual void f();
+};
+struct IV : public VBase {
+  int a;
+  int b;
+  IV(int a);
+};
+
+// A virtual base class, 

Re: [PATCH] D11740: ABI versioning macros for libc++

2015-10-09 Thread Evgeniy Stepanov via cfe-commits
eugenis set the repository for this revision to rL LLVM.
eugenis updated this revision to Diff 37015.
eugenis added a comment.

Rebased on http://reviews.llvm.org/D13407


Repository:
  rL LLVM

http://reviews.llvm.org/D11740

Files:
  CMakeLists.txt
  cmake/Modules/HandleLibcxxFlags.cmake
  docs/Abi.rst
  docs/BuildingLibcxx.rst
  include/__config
  include/__config_site.in
  include/string
  lib/CMakeLists.txt
  test/CMakeLists.txt
  test/libcxx/test/config.py
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -7,6 +7,8 @@
 config.enable_rtti  = "@LIBCXX_ENABLE_RTTI@"
 config.enable_shared= "@LIBCXX_ENABLE_SHARED@"
 config.enable_32bit = "@LIBCXX_BUILD_32_BITS@"
+config.abi_version  = "@LIBCXX_ABI_VERSION@"
+config.abi_unstable = "@LIBCXX_ABI_UNSTABLE@"
 config.enable_global_filesystem_namespace = "@LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE@"
 config.enable_stdin = "@LIBCXX_ENABLE_STDIN@"
 config.enable_stdout= "@LIBCXX_ENABLE_STDOUT@"
Index: test/libcxx/test/config.py
===
--- test/libcxx/test/config.py
+++ test/libcxx/test/config.py
@@ -370,6 +370,7 @@
 # Configure feature flags.
 self.configure_compile_flags_exceptions()
 self.configure_compile_flags_rtti()
+self.configure_compile_flags_abi_version()
 self.configure_compile_flags_no_global_filesystem_namespace()
 self.configure_compile_flags_no_stdin()
 self.configure_compile_flags_no_stdout()
@@ -423,6 +424,14 @@
 self.config.available_features.add('libcpp-no-rtti')
 self.cxx.compile_flags += ['-fno-rtti', '-D_LIBCPP_NO_RTTI']
 
+def configure_compile_flags_abi_version(self):
+abi_version = self.get_lit_conf('abi_version', '').strip()
+abi_unstable = self.get_lit_bool('abi_unstable')
+self.cxx.compile_flags += ['-D_LIBCPP_ABI_VERSION=' + abi_version]
+if abi_unstable:
+  self.config.available_features.add('libcpp-abi-unstable')
+  self.cxx.compile_flags += ['-D_LIBCPP_ABI_UNSTABLE']
+
 def configure_compile_flags_no_global_filesystem_namespace(self):
 enable_global_filesystem_namespace = self.get_lit_bool(
 'enable_global_filesystem_namespace', True)
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -13,6 +13,7 @@
 pythonize_bool(LIBCXX_ENABLE_RTTI)
 pythonize_bool(LIBCXX_ENABLE_SHARED)
 pythonize_bool(LIBCXX_BUILD_32_BITS)
+pythonize_bool(LIBCXX_ABI_UNSTABLE)
 pythonize_bool(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE)
 pythonize_bool(LIBCXX_ENABLE_STDIN)
 pythonize_bool(LIBCXX_ENABLE_STDOUT)
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -129,8 +129,8 @@
 COMPILE_FLAGS "${LIBCXX_COMPILE_FLAGS}"
 LINK_FLAGS"${LIBCXX_LINK_FLAGS}"
 OUTPUT_NAME   "c++"
-VERSION   "1.0"
-SOVERSION "1"
+VERSION   "${LIBCXX_ABI_VERSION}.0"
+SOVERSION "${LIBCXX_ABI_VERSION}"
   )
 
 if (LIBCXX_INSTALL_LIBRARY)
Index: include/string
===
--- include/string
+++ include/string
@@ -1185,7 +1185,7 @@
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 template 
 struct __padding
@@ -1198,7 +1198,7 @@
 {
 };
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 template
 class _LIBCPP_TYPE_VIS_ONLY basic_string
@@ -1234,7 +1234,7 @@
 
 private:
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 struct __long
 {
@@ -1294,7 +1294,7 @@
 value_type __data_[__min_cap];
 };
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 union __ulx{__long __lx; __short __lxx;};
 
@@ -1698,7 +1698,7 @@
 const allocator_type& __alloc() const _NOEXCEPT
 {return __r_.second();}
 
-#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT
+#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_short_size(size_type __s) _NOEXCEPT
@@ -1716,7 +1716,7 @@
 {return __r_.first().__s.__size_;}
 #   endif
 
-#else  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#else  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_short_size(size_type __s) _NOEXCEPT
@@ -1734,7 +1734,7 @@
 {return __r_.first().__s.__size_ >> 1;}
 #   endif
 
-#endif  // _LIBCPP_ALTERNATE_STRING_LAYOUT
+#endif  // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
 
 _LIBCPP_INLINE_VISIBILITY
 void __set_long_size(size_type __s) 

Re: [PATCH] D12747: Implement [depr.c.headers]

2015-10-09 Thread Richard Smith via cfe-commits
On Fri, Oct 9, 2015 at 3:48 PM, Eric Fiselier  wrote:

> Regarding Patch #15.
>
> 1. Tests under 'test/std' shouldn't directly include <__config> or
> depend on any libc++ implementation details. We are trying to make the
> test suite generic so refrain from referencing libc++ symbols.
>

OK, I'll include a different header instead.

2. "static_assert" is C++11 only but this test should work in C++03.
> Can you use "#if TEST_STD_VER >= 11" from "test_macros.h" to use
> static assert in C++11 and just "assert" in C++03 (or something
> similar)?
>

libc++ provides static_assert emulation in the cases where it's not
available, and other tests are using it unconditionally.


> 3. Could you throw the standarese that requires this behavior at the
> top of the test?
>

Done.


> LGTM after you address those points.


Thanks, all done in r249931 (other than the one reverted patch).

/Eric
>
>
> On Fri, Oct 9, 2015 at 4:26 PM, Eric Fiselier  wrote:
> > Patch #12 LGTM. Thanks for doing tho cwchar approach in this patch.
> > One small nit. I would prefer a "negative" feature macro for
> > "_LIBCPP_STRING_H_HAS_CONST_OVERLOADS" because correct defaults
> > shouldn't need a macro definition to be selected. (ie
> > _LIBCPP_STRING_H_HAS_NO_CONST_OVERLOAD.)
> >
> > /Eric
> >
> > On Fri, Oct 9, 2015 at 1:59 PM, Richard Smith 
> wrote:
> >> As of r249890, all committed other than patches 12 (string.h) and 15
> (more
> >> tests).
> >>
> >> On Thu, Oct 8, 2015 at 9:12 PM, Richard Smith 
> wrote:
> >>>
> >>> On Thu, Oct 8, 2015 at 6:58 PM, Richard Smith 
> >>> wrote:
> 
>  On Thu, Oct 8, 2015 at 6:25 PM, Eric Fiselier  wrote:
> >
> > Patch #12 needs revision. A bunch of function definitions were moved
> > out of the std namespace and into the global.
> > That change is incorrect.
> 
> 
>  Slightly updated version attached. I should probably explain what's
> going
>  on here in more detail:
> 
>  Per [c.strings]p4-p13, we're supposed to replace C functions of the
> form
> 
>    char *foo(const char*);
> 
>  with a pair of const-correct overloads of the form
> 
>    char *foo(char *);
>    const char *foo(const char*);
> 
>  Now, most C standard libraries will do this for us when included in
> C++
>  mode (because it's not possible for the C++ library to fix this up
> after the
>  fact). For the cases where we *don't* believe we have such a
> considerate C
>  library, we add one declaration to C's overload, to get:
> 
>    char *foo(char*);
>    char *foo(const char*)
> 
>  ... which doesn't really help much, but is the closest we can get to
> the
>  right set of declarations. The declarations we add just dispatch to
> the C
>  declarations.
> 
>  These new declarations *should* be in the global namespace when
> including
>  , and it makes sense for us to put them in the global
> namespace
>  when including  (otherwise, that header leaves us with a
> broken
>  overload set in the global namespace, containing just one of the two
>  expected functions).
> 
>  Anyway, most of the above is a description of what we did before.
> What's
>  new here is that we attempt to fix the overload set for both
>  and
>  for , not just for the latter. At the end of all these
> changes,
>  you'll see that all that the  headers do is to include the
> 
>  header and use using-declarations to pull the names into namespace
> std; this
>  is no exception to that pattern.
> >>>
> >>>
> >>> Per Eric and my discussion on IRC, the pattern used by  seems
> >>> better here:
> >>>
> >>> If libc has left us with a bad overload set, don't try to fix the
> names in
> >>> ::, just provide a complete set of overloads in namespace std.
> >>>
> >>> A patch for that approach is attached.
> >>>
> > On Thu, Oct 8, 2015 at 7:09 PM, Eric Fiselier  wrote:
> > > Patch #11 LGTM. Any reason you removed the "#pragma diagnostic
> ignored
> > > "-Wnonnull"" in test/std/depr/depr.c.headers/stdlib_h.pass.cpp?
> > > I would like to leave it in so this test doesn't fail with older
> clang
> > > versions.
> > >
> > > /Eric
> > >
> > > On Thu, Oct 8, 2015 at 6:47 PM, Eric Fiselier 
> wrote:
> > >> Patch #10 LGTM.
> > >>
> > >> On Thu, Oct 8, 2015 at 4:28 PM, Richard Smith <
> rich...@metafoo.co.uk>
> > >> wrote:
> > >>> On Thu, Oct 8, 2015 at 11:50 AM, Marshall Clow
> > >>> 
> > >>> wrote:
> > 
> >  On Tue, Oct 6, 2015 at 3:57 PM, Richard Smith
> >  
> >  wrote:
> > >
> > > . This one is tricky:
> > >
> > > 1) There's an (undocumented) interface between the C standard
> > > library and
> > 

Re: [libcxx] r249926 - Revert r249889 due to bot failure.

2015-10-09 Thread Richard Smith via cfe-commits
On Fri, Oct 9, 2015 at 6:29 PM, Richard Smith  wrote:

> On Fri, Oct 9, 2015 at 6:03 PM, Manman Ren via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: mren
>> Date: Fri Oct  9 20:03:55 2015
>> New Revision: 249926
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=249926=rev
>> Log:
>> Revert r249889 due to bot failure.
>>
>
> Can you provide a pointer to the failing bot?
>

Ah, found it:

http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA_check/7703/testReport/junit/libc++/std_depr_depr_c_headers/wchar_h_pass_cpp/

Unreverted in r249932, with an XFAIL for Darwin. The problem is that the
underlying libc provides a bad overload set, and there's nothing that
libc++ can do to fix that.


>
>
>> Removed:
>> libcxx/trunk/include/wchar.h
>> Modified:
>> libcxx/trunk/include/cwchar
>> libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
>>
>> Modified: libcxx/trunk/include/cwchar
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=249926=249925=249926=diff
>>
>> ==
>> --- libcxx/trunk/include/cwchar (original)
>> +++ libcxx/trunk/include/cwchar Fri Oct  9 20:03:55 2015
>> @@ -106,6 +106,9 @@ size_t wcsrtombs(char* restrict dst, con
>>  #include <__config>
>>  #include 
>>  #include 
>> +#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
>> +#include  // pull in *swprintf defines
>> +#endif // _LIBCPP_MSVCRT
>>
>>  #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
>>  #pragma GCC system_header
>> @@ -158,13 +161,16 @@ using ::wcscoll;
>>  using ::wcsncmp;
>>  using ::wcsxfrm;
>>
>> -#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
>> +#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
>> +
>>  using ::wcschr;
>>  using ::wcspbrk;
>>  using ::wcsrchr;
>>  using ::wcsstr;
>>  using ::wmemchr;
>> +
>>  #else
>> +
>>  inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t*
>> __s, wchar_t __c) {return ::wcschr(__s, __c);}
>>  inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t*
>> __s, wchar_t __c) {return ::wcschr(__s, __c);}
>>
>> @@ -179,6 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY   w
>>
>>  inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t*
>> __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
>>  inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wmemchr(  wchar_t*
>> __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
>> +
>>  #endif
>>
>>  using ::wcscspn;
>>
>> Removed: libcxx/trunk/include/wchar.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=249925=auto
>>
>> ==
>> --- libcxx/trunk/include/wchar.h (original)
>> +++ libcxx/trunk/include/wchar.h (removed)
>> @@ -1,136 +0,0 @@
>> -// -*- C++ -*-
>> -//===--- wchar.h
>> --===//
>> -//
>> -// The LLVM Compiler Infrastructure
>> -//
>> -// This file is dual licensed under the MIT and the University of
>> Illinois Open
>> -// Source Licenses. See LICENSE.TXT for details.
>> -//
>>
>> -//===--===//
>> -
>> -#if defined(__need_wint_t) || defined(__need_mbstate_t)
>> -
>> -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
>> -#pragma GCC system_header
>> -#endif
>> -
>> -#include_next 
>> -
>> -#elif !defined(_LIBCPP_WCHAR_H)
>> -#define _LIBCPP_WCHAR_H
>> -
>> -/*
>> -wchar.h synopsis
>> -
>> -Macros:
>> -
>> -NULL
>> -WCHAR_MAX
>> -WCHAR_MIN
>> -WEOF
>> -
>> -Types:
>> -
>> -mbstate_t
>> -size_t
>> -tm
>> -wint_t
>> -
>> -int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
>> -int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
>> -int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict
>> format, ...);
>> -int swscanf(const wchar_t* restrict s, const wchar_t* restrict format,
>> ...);
>> -int vfwprintf(FILE* restrict stream, const wchar_t* restrict format,
>> va_list arg);
>> -int vfwscanf(FILE* restrict stream, const wchar_t* restrict format,
>> va_list arg);  // C99
>> -int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict
>> format, va_list arg);
>> -int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format,
>> va_list arg);  // C99
>> -int vwprintf(const wchar_t* restrict format, va_list arg);
>> -int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
>> -int wprintf(const wchar_t* restrict format, ...);
>> -int wscanf(const wchar_t* restrict format, ...);
>> -wint_t fgetwc(FILE* stream);
>> -wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
>> -wint_t fputwc(wchar_t c, FILE* stream);
>> -int fputws(const wchar_t* restrict s, FILE* restrict stream);
>> -int fwide(FILE* stream, int mode);
>> -wint_t getwc(FILE* stream);
>> 

Re: [PATCH] D13453: Always generate cmake config files

2015-10-09 Thread NAKAMURA Takumi via cfe-commits
chapuni closed this revision.
chapuni added a comment.

Applied in r249935, thanks!


http://reviews.llvm.org/D13453



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


[libcxx] r249936 - Get some of wchar_h.pass.cpp working on apple.

2015-10-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Oct  9 21:54:41 2015
New Revision: 249936

URL: http://llvm.org/viewvc/llvm-project?rev=249936=rev
Log:
Get some of wchar_h.pass.cpp working on apple.

Modified:
libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp

Modified: libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp?rev=249936=249935=249936=diff
==
--- libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp Fri Oct  9 
21:54:41 2015
@@ -9,11 +9,6 @@
 
 // 
 
-// This test fails on systems whose C library doesn't provide a correct 
overload
-// set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr. There's no way for
-// libc++ to fix that on the C library's behalf.
-//
-// XFAIL: apple-darwin
 
 #include 
 #include 
@@ -79,19 +74,19 @@ int main()
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
+// const wchar_t* wcschr((const wchar_t*)0, L' ') - See below
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
+// const wchar_t* wcspbrk((const wchar_t*)0, L"") - See below
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
+// const wchar_t* wcsrchr((const wchar_t*)0, L' ') - See below
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
-static_assert((std::is_same::value), "");
+// const wchar_t* wcsstr((const wchar_t*)0, L"") - See below
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
+// const wchar_t* wmemchr((const wchar_t*)0, L' ', s) - See below
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
@@ -107,6 +102,17 @@ int main()
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 
+// This test fails on systems whose C library doesn't provide a correct 
overload
+// set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr. There's no way for
+// libc++ to fix that on the C library's behalf.
+#ifndef __APPLE__
+static_assert((std::is_same::value), "");
+static_assert((std::is_same::value), "");
+static_assert((std::is_same::value), "");
+static_assert((std::is_same::value), "");
+static_assert((std::is_same::value), "");
+#endif
+
 #ifndef _LIBCPP_HAS_NO_STDIN
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");


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


Re: [PATCH] D13618: [Extension] Optimizing const member objects.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37024.

http://reviews.llvm.org/D13618

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp

Index: test/CodeGenCXX/const-invariant.cpp
===
--- test/CodeGenCXX/const-invariant.cpp
+++ test/CodeGenCXX/const-invariant.cpp
@@ -37,8 +37,8 @@
 #if defined(OBJ)
 struct A {
   int a;
-  int b;
-  A(int a) : a(a) {}
+  Const int b;
+  A(int a) : a(a), b(a) {}
 };
 
 // A with explicit destructor
@@ -177,6 +177,8 @@
 
 void foo(const Type* const);
 void bar(Type);
+void foo(const int* const);
+void bar(int);
 #if defined(OBJ)
 void foo_d(const D* const);
 void bar_d(D);
@@ -359,6 +361,22 @@
   // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end(
 }
 
+// Example 1 with const member of non-const object:
+// collects offsets in invariant_start call.
+void ex1_cm() {
+// CHECK: @_Z6ex1_cmv(
+#ifdef LOCAL
+  Type i(one());
+#endif
+
+  // CHECK-L-CO-OBJ: call void @_ZN1AC{{[0-9]+}}Ei({{.*}}* %i,
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8* {{.*}},
+  bar(i.b);
+  foo();  // Does not change i.b.
+  bar(i.b);
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8*
+}
+
 #endif  // #if defined(OBJ)
 
 // Example 1 with references and pointers:
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -260,9 +260,11 @@
   typedef std::vector CtorList;
 
   struct InvariantArgs {
-llvm::CallInst *StartInst;
-llvm::Value *Size;
+llvm::CallInst *StartInst;  // TODO: Is this necessary?
+llvm::Value *Size;  // TODO: Is this necessary?
 llvm::Value *Addr;
+llvm::SmallVector Offsets;
+
 InvariantArgs() : StartInst(nullptr), Size(nullptr), Addr(nullptr) {}
 InvariantArgs(llvm::CallInst *C, llvm::Value *S, llvm::Value *A)
 : StartInst(C), Size(S), Addr(A) {}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1905,9 +1905,9 @@
   llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
   CodeGenModule::InvariantArgs EmitInvariantStart(const VarDecl ,
-  llvm::Value *Addr);
-  void EmitInvariantEnd(llvm::CallInst *C, llvm::Value *Size,
-llvm::Value *Addr);
+  llvm::Value *Addr,
+  bool IsGlobalConstant = true);
+  void EmitInvariantEnd(CodeGenModule::InvariantArgs );
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -530,15 +530,12 @@
 
   /// A cleanup to call @llvm.invariant.end.
   class CallInvariantEnd final : public EHScopeStack::Cleanup {
-llvm::CallInst *StartInst;
-llvm::Value *Addr;
-llvm::Value *Size;  // TODO: Is this even necessary?
+CodeGenModule::InvariantArgs Args;
public:
-CallInvariantEnd(llvm::CallInst *C, llvm::Value *addr, llvm::Value *size)
-: StartInst(C), Addr(addr), Size(size) {}
+CallInvariantEnd(CodeGenModule::InvariantArgs ) : Args(args) {}
 
 void Emit(CodeGenFunction , Flags flags) override {
-  CGF.EmitInvariantEnd(StartInst, Size, Addr);
+  CGF.EmitInvariantEnd(Args);
 }
   };
 }
@@ -881,16 +878,14 @@
   // If the address is writeonce, then emit @llvm.invariant.start() intrinsic.
   // Then, for non-global variables, push the emission of the
   // @llvm.invariant.end() intrinsic onto the cleanup stack.
-  if ((AI || !GV->isConstant()) && D->getType().isWriteOnce(CGF.getContext()))
-Args = CGF.EmitInvariantStart(*D, AddrPtr);
+  if (AI || !GV->isConstant())
+Args = CGF.EmitInvariantStart(*D, AddrPtr, /*IsGlobalConstant =*/false);
 }
 
 MarkWriteOnceWrittenRAII::~MarkWriteOnceWrittenRAII() {
-  if (AI && Args.StartInst) {
-assert(!GV && "Can't have it both ways!");
-CGF.EHStack.pushCleanup(NormalCleanup, Args.StartInst,
-  Args.Addr, Args.Size);
-  }
+  if (Args.Addr && dyn_cast(Args.Addr->stripPointerCasts()) &&
+  Args.StartInst)
+CGF.EHStack.pushCleanup(NormalCleanup, Args);
 }
 
 /// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a
@@ -932,44 +927,85 @@
   C->setDoesNotThrow();
 }
 
+/// Collect offsets in bits.
+static bool getInvariantOffsets(const CodeGenFunction , QualType Ty,
+llvm::SmallVectorImpl ) {
+  ASTContext  = CGF.getContext();
+  bool FoundWriteOnce = false;
+  

Re: [PATCH] D12502: [libcxx] Better constain tuples constructors -- Fix PR23256 and PR22806

2015-10-09 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Howard gave this approach and patch the thumbs up privately.

@mclow.lists What's holding you back from approving this?


http://reviews.llvm.org/D12502



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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-09 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.


Comment at: include/CMakeLists.txt:38
@@ +37,3 @@
+  COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> 
${LIBCXX_BINARY_DIR}/__generated_config
+  DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config
+)

eugenis wrote:
> I think you need to depend on __config_site.in as well. Or on 
> ${LIBCXX_BINARY_DIR}/__config_site 
I don't think we need it. `__config_site` is generated with `configure_file`, 
which runs at configuration time and re-runs whenever the input file is 
changed. So `__config_site` should always be up to date. 

However I'll see if we can actually make the change. It seems clearer and safer.


http://reviews.llvm.org/D13407



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


[libcxx] r249926 - Revert r249889 due to bot failure.

2015-10-09 Thread Manman Ren via cfe-commits
Author: mren
Date: Fri Oct  9 20:03:55 2015
New Revision: 249926

URL: http://llvm.org/viewvc/llvm-project?rev=249926=rev
Log:
Revert r249889 due to bot failure.

Removed:
libcxx/trunk/include/wchar.h
Modified:
libcxx/trunk/include/cwchar
libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp

Modified: libcxx/trunk/include/cwchar
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=249926=249925=249926=diff
==
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/cwchar Fri Oct  9 20:03:55 2015
@@ -106,6 +106,9 @@ size_t wcsrtombs(char* restrict dst, con
 #include <__config>
 #include 
 #include 
+#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
+#include  // pull in *swprintf defines
+#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -158,13 +161,16 @@ using ::wcscoll;
 using ::wcsncmp;
 using ::wcsxfrm;
 
-#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
+#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
+
 using ::wcschr;
 using ::wcspbrk;
 using ::wcsrchr;
 using ::wcsstr;
 using ::wmemchr;
+
 #else
+
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 
@@ -179,6 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY   w
 
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wmemchr(  wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
+
 #endif
 
 using ::wcscspn;

Removed: libcxx/trunk/include/wchar.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=249925=auto
==
--- libcxx/trunk/include/wchar.h (original)
+++ libcxx/trunk/include/wchar.h (removed)
@@ -1,136 +0,0 @@
-// -*- C++ -*-
-//===--- wchar.h 
--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-#if defined(__need_wint_t) || defined(__need_mbstate_t)
-
-#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
-#pragma GCC system_header
-#endif
-
-#include_next 
-
-#elif !defined(_LIBCPP_WCHAR_H)
-#define _LIBCPP_WCHAR_H
-
-/*
-wchar.h synopsis
-
-Macros:
-
-NULL
-WCHAR_MAX
-WCHAR_MIN
-WEOF
-
-Types:
-
-mbstate_t
-size_t
-tm
-wint_t
-
-int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
-int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
-int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, 
...);
-int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
-int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list 
arg);
-int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list 
arg);  // C99
-int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, 
va_list arg);
-int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, 
va_list arg);  // C99
-int vwprintf(const wchar_t* restrict format, va_list arg);
-int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
-int wprintf(const wchar_t* restrict format, ...);
-int wscanf(const wchar_t* restrict format, ...);
-wint_t fgetwc(FILE* stream);
-wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
-wint_t fputwc(wchar_t c, FILE* stream);
-int fputws(const wchar_t* restrict s, FILE* restrict stream);
-int fwide(FILE* stream, int mode);
-wint_t getwc(FILE* stream);
-wint_t getwchar();
-wint_t putwc(wchar_t c, FILE* stream);
-wint_t putwchar(wchar_t c);
-wint_t ungetwc(wint_t c, FILE* stream);
-double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
-float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); 
// C99
-long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr);  
// C99
-long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
-long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int 
base);  // C99
-unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, 
int base);
-unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict 
endptr, int base);  // C99
-wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
-wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
-wchar_t* wcscat(wchar_t* restrict s1, const 

[libcxx] r249931 - Add a test that we declare the right set of C library function signatures in ::

2015-10-09 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct  9 20:33:17 2015
New Revision: 249931

URL: http://llvm.org/viewvc/llvm-project?rev=249931=rev
Log:
Add a test that we declare the right set of C library function signatures in ::
and std::, and that the names in :: and std:: are declaring the same entity.

Added:
libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp

Added: libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp?rev=249931=auto
==
--- libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp (added)
+++ libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp Fri Oct  9 
20:33:17 2015
@@ -0,0 +1,517 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// [depr.c.headers]p2:
+//   Every C header, each of which has a name of the form name.h, behaves as if
+//   each name placed in the standard library namespace by the corresponding
+//   cname header is placed within the global namespace scope.
+//
+// This implies that the name in the global namespace and the name in namespace
+// std declare the same entity, so check that that is actually the case.
+
+// Pull in libc++'s static_assert emulation if in C++98 mode.
+#include 
+
+template struct check { static_assert(F == G, ""); };
+
+// ctype.h
+
+#include 
+#include 
+
+void test_ctype() {
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+}
+
+// fenv.h
+
+#include 
+#include 
+
+void test_fenv() {
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+}
+
+// inttypes.h
+
+#include 
+#include 
+
+// Avoid error if abs and div are not declared by .
+struct nat {};
+static void abs(nat);
+static void div(nat);
+namespace std {
+  static void abs(nat);
+  static void div(nat);
+}
+
+// These may or may not exist, depending on whether intmax_t
+// is an extended integer type (larger than long long).
+template sizeof(long long))>
+void test_inttypes_abs_div() {
+  check();
+  check();
+}
+template<> void test_inttypes_abs_div() {}
+
+void test_inttypes() {
+  test_inttypes_abs_div();
+
+  check();
+  check();
+  check();
+  check();
+  check();
+  check();
+}
+
+// locale.h
+
+#include 
+#include 
+
+void test_locale() {
+  check();
+  check();
+}
+
+// math.h
+
+#include 
+#include 
+
+template
+void test_math_float() {
+  typedef Float ff(Float);
+  typedef Float ffi(Float, int);
+  typedef Float ffpi(Float, int*);
+  typedef Float ffl(Float, long);
+  typedef Float fff(Float, Float);
+  typedef Float ffpf(Float, Float*);
+  typedef Float ffld(Float, long double);
+  typedef Float fffpi(Float, Float, int*);
+  typedef Float (Float, Float, Float);
+  typedef bool bf(Float);
+  typedef bool bff(Float, Float);
+  typedef int i_f(Float);
+  typedef long lf(Float);
+  typedef long long llf(Float);
+
+  check();
+  check();
+  check();
+  check();
+  check

r249935 - [CMake] Always generate and install cmake config files on CMake>=3.0.

2015-10-09 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Fri Oct  9 21:37:30 2015
New Revision: 249935

URL: http://llvm.org/viewvc/llvm-project?rev=249935=rev
Log:
[CMake] Always generate and install cmake config files on CMake>=3.0.

Currently, cmake config files are only generated and installed when 
CLANG_BUILD_STANDALONE set, which means config file will not be generated or 
installed when clang is built with llvm. This change removes that restriction.

Thanks to Don Hinton 

http://reviews.llvm.org/D13453

Modified:
cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=249935=249934=249935=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Fri Oct  9 21:37:30 2015
@@ -550,7 +550,8 @@ endif()
 set(CLANG_ORDER_FILE "" CACHE FILEPATH
   "Order file to use when compiling clang in order to improve startup time.")
 
-if (CLANG_BUILT_STANDALONE)
+if (CLANG_BUILT_STANDALONE OR CMAKE_VERSION VERSION_EQUAL 3 OR
+CMAKE_VERSION VERSION_GREATER 3)
   # Generate a list of CMake library targets so that other CMake projects can
   # link against them. LLVM calls its version of this file LLVMExports.cmake, 
but
   # the usual CMake convention seems to be ${Project}Targets.cmake.


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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-09 Thread Eric Fiselier via cfe-commits
EricWF marked an inline comment as done.
EricWF added a comment.

@eugenis I'll commit this tuesday morning If I don't hear anything over the 
weekend (Monday is a holiday for me).
If you rebase the ABI patch to work with this I'll make sure to review it ASAP.



Comment at: include/CMakeLists.txt:9
@@ -7,2 +8,3 @@
   PATTERN ".svn" EXCLUDE
+  PATTERN "__config_site.in" EXCLUDE
   ${LIBCXX_SUPPORT_HEADER_PATTERN}

vkalintiris wrote:
> Kind of silly but I believe that the files used for auto-generated config 
> headers in LLVM have the extesions `.cmake` and `.in`, for cmake and 
> autoconf, respectively.
libc++ uses `.cmake` for CMake scripts and `.in` for auto-generated files and I 
think this is fine. libc++ doesn't support autoconf I'm not worried about it 
causing confusion. 



http://reviews.llvm.org/D13407



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


Re: [PATCH] D13614: [Extension] Optimizing passed by-value const objects.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37012.
lvoufo added a comment.

Update patch (Wrong patch submitted earlier).


http://reviews.llvm.org/D13614

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenObjCXX/arc.mm

Index: test/CodeGenObjCXX/arc.mm
===
--- test/CodeGenObjCXX/arc.mm
+++ test/CodeGenObjCXX/arc.mm
@@ -43,9 +43,11 @@
 @interface Test1 @end
 @implementation Test1 { Test1_helper x; } @end
 // CHECK: define internal i8* @"\01-[Test1 .cxx_construct]"(
+// CHECK:  call {{.*}}@llvm.invariant.start(
 // CHECK:  call void @_ZN12Test1_helperC1Ev(
 // CHECK-NEXT: load
 // CHECK-NEXT: bitcast
+// CHECK-NEXT: call {{.*}}@llvm.invariant.end(
 // CHECK-NEXT: ret i8*
 
 void test34(int cond) {
Index: test/CodeGenCXX/const-invariant.cpp
===
--- test/CodeGenCXX/const-invariant.cpp
+++ test/CodeGenCXX/const-invariant.cpp
@@ -398,5 +398,17 @@
   // CHECK-L-CO: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8*
 }
 
+#ifdef LOCAL
+void ex1_parms(Const Type i) {
+  // CHECK: @_Z9ex1_parms1A(
+  // CHECK-L-CO: store {{.*}} %i
+  // CHECK-L-CO: call {{.*}}@llvm.invariant.start(
+  bar(i);
+  foo();  // May change i.
+  bar(i);
+  // CHECK-L-CO: call {{.*}}@llvm.invariant.end(
+}
+#endif
+
 // CHECK-G-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8* 
bitcast ({{.*}} @_ZL1j to i8*))
 // CHECK-G-CO-INT: store {{.*}}, {{.*}}* @_ZL1j
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1897,4 +1897,6 @@
 
   if (D.hasAttr())
 EmitVarAnnotations(, DeclPtr.getPointer());
+
+  MarkWriteOnceWrittenRAII MWO(*this, );
 }


Index: test/CodeGenObjCXX/arc.mm
===
--- test/CodeGenObjCXX/arc.mm
+++ test/CodeGenObjCXX/arc.mm
@@ -43,9 +43,11 @@
 @interface Test1 @end
 @implementation Test1 { Test1_helper x; } @end
 // CHECK: define internal i8* @"\01-[Test1 .cxx_construct]"(
+// CHECK:  call {{.*}}@llvm.invariant.start(
 // CHECK:  call void @_ZN12Test1_helperC1Ev(
 // CHECK-NEXT: load
 // CHECK-NEXT: bitcast
+// CHECK-NEXT: call {{.*}}@llvm.invariant.end(
 // CHECK-NEXT: ret i8*
 
 void test34(int cond) {
Index: test/CodeGenCXX/const-invariant.cpp
===
--- test/CodeGenCXX/const-invariant.cpp
+++ test/CodeGenCXX/const-invariant.cpp
@@ -398,5 +398,17 @@
   // CHECK-L-CO: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8*
 }
 
+#ifdef LOCAL
+void ex1_parms(Const Type i) {
+  // CHECK: @_Z9ex1_parms1A(
+  // CHECK-L-CO: store {{.*}} %i
+  // CHECK-L-CO: call {{.*}}@llvm.invariant.start(
+  bar(i);
+  foo();  // May change i.
+  bar(i);
+  // CHECK-L-CO: call {{.*}}@llvm.invariant.end(
+}
+#endif
+
 // CHECK-G-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8* bitcast ({{.*}} @_ZL1j to i8*))
 // CHECK-G-CO-INT: store {{.*}}, {{.*}}* @_ZL1j
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1897,4 +1897,6 @@
 
   if (D.hasAttr())
 EmitVarAnnotations(, DeclPtr.getPointer());
+
+  MarkWriteOnceWrittenRAII MWO(*this, );
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-09 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 37013.
EricWF added a comment.

Make the generated config dependent on the "__config_site" file. It probably 
didn't need this but it doesn't hurt to have.


http://reviews.llvm.org/D13407

Files:
  CMakeLists.txt
  cmake/Modules/HandleLibcxxFlags.cmake
  docs/DesignDocs/CapturingConfigInfo.rst
  docs/index.rst
  include/CMakeLists.txt
  include/__config_site.in

Index: include/__config_site.in
===
--- /dev/null
+++ include/__config_site.in
@@ -0,0 +1,20 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef _LIBCPP_CONFIG_SITE
+#define _LIBCPP_CONFIG_SITE
+
+#cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
+#cmakedefine _LIBCPP_HAS_NO_STDIN
+#cmakedefine _LIBCPP_HAS_NO_STDOUT
+#cmakedefine _LIBCPP_HAS_NO_THREADS
+#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+#cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
+
+#endif
Index: include/CMakeLists.txt
===
--- include/CMakeLists.txt
+++ include/CMakeLists.txt
@@ -1,10 +1,12 @@
 if (NOT LIBCXX_INSTALL_SUPPORT_HEADERS)
   set(LIBCXX_SUPPORT_HEADER_PATTERN PATTERN "support" EXCLUDE)
 endif()
+
 set(LIBCXX_HEADER_PATTERN
   PATTERN "*"
   PATTERN "CMakeLists.txt" EXCLUDE
   PATTERN ".svn" EXCLUDE
+  PATTERN "__config_site.in" EXCLUDE
   ${LIBCXX_SUPPORT_HEADER_PATTERN}
   )
 
@@ -22,4 +24,29 @@
 ${LIBCXX_HEADER_PATTERN}
 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
   )
+
+  if (LIBCXX_NEEDS_SITE_CONFIG)
+set(UNIX_CAT cat)
+if (WIN32)
+  set(UNIX_CAT type)
+endif()
+# Generate and install a custom __config header. The new header is created
+# by  prepending __config_site to the current __config header.
+add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config
+  COMMAND ${CMAKE_COMMAND} -E copy ${LIBCXX_BINARY_DIR}/__config_site ${LIBCXX_BINARY_DIR}/__generated_config
+  COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> ${LIBCXX_BINARY_DIR}/__generated_config
+  DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config
+  ${LIBCXX_BINARY_DIR}/__config_site
+)
+# Add a target that executes the generation commands.
+add_custom_target(generate_config_header ALL
+  DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config)
+# Install the generated header as __config.
+install(FILES ${LIBCXX_BINARY_DIR}/__generated_config
+  DESTINATION include/c++/v1
+  PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+  RENAME __config
+  COMPONENT libcxx)
+  endif()
+
 endif()
Index: docs/index.rst
===
--- docs/index.rst
+++ docs/index.rst
@@ -124,6 +124,12 @@
 Design Documents
 
 
+.. toctree::
+   :maxdepth: 1
+
+   DesignDocs/CapturingConfigInfo
+
+
 * ` design `_
 * ` design `_
 * `Status of debug mode `_
Index: docs/DesignDocs/CapturingConfigInfo.rst
===
--- /dev/null
+++ docs/DesignDocs/CapturingConfigInfo.rst
@@ -0,0 +1,88 @@
+===
+Capturing configuration information during installation
+===
+
+.. contents::
+   :local:
+
+The Problem
+===
+
+Currently the libc++ supports building the library with a number of different
+configuration options.  Unfortunately all of that configuration information is
+lost when libc++ is installed. In order to support "persistent"
+configurations libc++ needs a mechanism to capture the configuration options
+in the INSTALLED headers.
+
+
+Design Goals
+
+
+* The solution should not INSTALL any additional headers. We don't want an extra
+  #include slowing everybody down.
+
+* The solution should not unduly affect libc++ developers. The problem is limited
+  to installed versions of libc++ and the solution should be as well.
+
+* The solution should not modify any existing headers EXCEPT during installation.
+  It makes developers lives harder if they have to regenerate the libc++ headers
+  every time they are modified.
+
+* The solution should not make any of the libc++ headers dependant on
+  files generated by the build system. The headers should be able to compile
+  out of the box without any modification.
+
+* The solution should not have ANY effect on users who don't need special
+  configuration options. The vast majority of users will never 

Re: [libcxx] r249926 - Revert r249889 due to bot failure.

2015-10-09 Thread Richard Smith via cfe-commits
On Fri, Oct 9, 2015 at 6:03 PM, Manman Ren via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: mren
> Date: Fri Oct  9 20:03:55 2015
> New Revision: 249926
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249926=rev
> Log:
> Revert r249889 due to bot failure.
>

Can you provide a pointer to the failing bot?


> Removed:
> libcxx/trunk/include/wchar.h
> Modified:
> libcxx/trunk/include/cwchar
> libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
>
> Modified: libcxx/trunk/include/cwchar
> URL:
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=249926=249925=249926=diff
>
> ==
> --- libcxx/trunk/include/cwchar (original)
> +++ libcxx/trunk/include/cwchar Fri Oct  9 20:03:55 2015
> @@ -106,6 +106,9 @@ size_t wcsrtombs(char* restrict dst, con
>  #include <__config>
>  #include 
>  #include 
> +#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
> +#include  // pull in *swprintf defines
> +#endif // _LIBCPP_MSVCRT
>
>  #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
>  #pragma GCC system_header
> @@ -158,13 +161,16 @@ using ::wcscoll;
>  using ::wcsncmp;
>  using ::wcsxfrm;
>
> -#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
> +#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
> +
>  using ::wcschr;
>  using ::wcspbrk;
>  using ::wcsrchr;
>  using ::wcsstr;
>  using ::wmemchr;
> +
>  #else
> +
>  inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t*
> __s, wchar_t __c) {return ::wcschr(__s, __c);}
>  inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t*
> __s, wchar_t __c) {return ::wcschr(__s, __c);}
>
> @@ -179,6 +185,7 @@ inline _LIBCPP_INLINE_VISIBILITY   w
>
>  inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t*
> __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
>  inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wmemchr(  wchar_t*
> __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
> +
>  #endif
>
>  using ::wcscspn;
>
> Removed: libcxx/trunk/include/wchar.h
> URL:
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?rev=249925=auto
>
> ==
> --- libcxx/trunk/include/wchar.h (original)
> +++ libcxx/trunk/include/wchar.h (removed)
> @@ -1,136 +0,0 @@
> -// -*- C++ -*-
> -//===--- wchar.h
> --===//
> -//
> -// The LLVM Compiler Infrastructure
> -//
> -// This file is dual licensed under the MIT and the University of
> Illinois Open
> -// Source Licenses. See LICENSE.TXT for details.
> -//
>
> -//===--===//
> -
> -#if defined(__need_wint_t) || defined(__need_mbstate_t)
> -
> -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
> -#pragma GCC system_header
> -#endif
> -
> -#include_next 
> -
> -#elif !defined(_LIBCPP_WCHAR_H)
> -#define _LIBCPP_WCHAR_H
> -
> -/*
> -wchar.h synopsis
> -
> -Macros:
> -
> -NULL
> -WCHAR_MAX
> -WCHAR_MIN
> -WEOF
> -
> -Types:
> -
> -mbstate_t
> -size_t
> -tm
> -wint_t
> -
> -int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
> -int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
> -int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict
> format, ...);
> -int swscanf(const wchar_t* restrict s, const wchar_t* restrict format,
> ...);
> -int vfwprintf(FILE* restrict stream, const wchar_t* restrict format,
> va_list arg);
> -int vfwscanf(FILE* restrict stream, const wchar_t* restrict format,
> va_list arg);  // C99
> -int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict
> format, va_list arg);
> -int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format,
> va_list arg);  // C99
> -int vwprintf(const wchar_t* restrict format, va_list arg);
> -int vwscanf(const wchar_t* restrict format, va_list arg);  // C99
> -int wprintf(const wchar_t* restrict format, ...);
> -int wscanf(const wchar_t* restrict format, ...);
> -wint_t fgetwc(FILE* stream);
> -wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
> -wint_t fputwc(wchar_t c, FILE* stream);
> -int fputws(const wchar_t* restrict s, FILE* restrict stream);
> -int fwide(FILE* stream, int mode);
> -wint_t getwc(FILE* stream);
> -wint_t getwchar();
> -wint_t putwc(wchar_t c, FILE* stream);
> -wint_t putwchar(wchar_t c);
> -wint_t ungetwc(wint_t c, FILE* stream);
> -double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
> -float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr);
>  // C99
> -long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict
> endptr);  // C99
> -long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int
> base);
> -long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict
> endptr, 

[libcxx] r249929 - Split out of .

2015-10-09 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct  9 20:25:31 2015
New Revision: 249929

URL: http://llvm.org/viewvc/llvm-project?rev=249929=rev
Log:
Split  out of .

Also fix the overload set for the five functions whose signatures change in the
case where we can fix it. This is already covered by existing tests for the
affected systems.

Added:
libcxx/trunk/include/string.h
  - copied, changed from r249736, libcxx/trunk/include/cstring
Modified:
libcxx/trunk/include/cstring

Modified: libcxx/trunk/include/cstring
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cstring?rev=249929=249928=249929=diff
==
--- libcxx/trunk/include/cstring (original)
+++ libcxx/trunk/include/cstring Fri Oct  9 20:25:31 2015
@@ -78,37 +78,42 @@ using ::strcmp;
 using ::strncmp;
 using ::strcoll;
 using ::strxfrm;
+using ::strcspn;
+using ::strspn;
+#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
+using ::strtok;
+#endif
+using ::memset;
+using ::strerror;
+using ::strlen;
 
-using ::memchr;
+// MSVCRT, GNU libc and its derivates already have the correct prototype in
+//  if __cplusplus is defined. This macro can be defined by users if
+// their C library provides the right signature.
+#if defined(__GLIBC__) || defined(_LIBCPP_MSVCRT) || defined(__sun__) || \
+defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
+#endif
 
+#ifdef _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
 using ::strchr;
-
-using ::strcspn;
-
 using ::strpbrk;
-
 using ::strrchr;
-
-using ::strspn;
-
+using ::memchr;
 using ::strstr;
-
-// MSVCRT, GNU libc and its derivates already have the correct prototype in 
 #ifdef __cplusplus
-#if !defined(__GLIBC__) && !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && 
!defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
+#else
+inline _LIBCPP_INLINE_VISIBILITY const char* strchr(const char* __s, int __c) 
{return ::strchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY   char* strchr(  char* __s, int __c) 
{return ::strchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strpbrk(const char* __s1, const 
char* __s2) {return ::strpbrk(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY   char* strpbrk(  char* __s1, const 
char* __s2) {return ::strpbrk(__s1, __s2);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strrchr(const char* __s, int __c) 
{return ::strrchr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY   char* strrchr(  char* __s, int __c) 
{return ::strrchr(__s, __c);}
+inline _LIBCPP_INLINE_VISIBILITY const void* memchr(const void* __s, int __c, 
size_t __n) {return ::memchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY   void* memchr(  void* __s, int __c, 
size_t __n) {return ::memchr(__s, __c, __n);}
+inline _LIBCPP_INLINE_VISIBILITY const char* strstr(const char* __s1, const 
char* __s2) {return ::strstr(__s1, __s2);}
 inline _LIBCPP_INLINE_VISIBILITY   char* strstr(  char* __s1, const 
char* __s2) {return ::strstr(__s1, __s2);}
 #endif
 
-#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
-using ::strtok;
-#endif
-using ::memset;
-using ::strerror;
-using ::strlen;
-
 _LIBCPP_END_NAMESPACE_STD
 
 #endif  // _LIBCPP_CSTRING

Copied: libcxx/trunk/include/string.h (from r249736, 
libcxx/trunk/include/cstring)
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string.h?p2=libcxx/trunk/include/string.h=libcxx/trunk/include/cstring=249736=249929=249929=diff
==
--- libcxx/trunk/include/cstring (original)
+++ libcxx/trunk/include/string.h Fri Oct  9 20:25:31 2015
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--- cstring 
--===//
+//===--- string.h 
-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,19 +8,16 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_CSTRING
-#define _LIBCPP_CSTRING
+#ifndef _LIBCPP_STRING_H
+#define _LIBCPP_STRING_H
 
 /*
-cstring synopsis
+string.h synopsis
 
 Macros:
 
 NULL
 
-namespace std
-{
-
 Types:
 
 size_t
@@ -53,62 +50,14 @@ void* memset(void* s, int c, size_t n);
 char* strerror(int errnum);
 size_t strlen(const char* s);
 
-}  // std
-
 */
 
 #include <__config>
-#include 
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-using ::size_t;
-using ::memcpy;
-using ::memmove;
-using ::strcpy;
-using ::strncpy;
-using ::strcat;
-using ::strncat;
-using ::memcmp;
-using ::strcmp;
-using ::strncmp;
-using ::strcoll;
-using ::strxfrm;
-
-using ::memchr;
-
-using ::strchr;
-
-using ::strcspn;
-
-using ::strpbrk;
-
-using ::strrchr;
-
-using ::strspn;
-
-using ::strstr;
-
-// MSVCRT, GNU libc and its derivates already have the correct prototype in 
 #ifdef __cplusplus
-#if 

Re: [PATCH] D13618: [Extension] Optimizing const member objects.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37023.

http://reviews.llvm.org/D13618

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp

Index: test/CodeGenCXX/const-invariant.cpp
===
--- test/CodeGenCXX/const-invariant.cpp
+++ test/CodeGenCXX/const-invariant.cpp
@@ -37,8 +37,8 @@
 #if defined(OBJ)
 struct A {
   int a;
-  int b;
-  A(int a) : a(a) {}
+  Const int b;
+  A(int a) : a(a), b(a) {}
 };
 
 // A with explicit destructor
@@ -177,6 +177,8 @@
 
 void foo(const Type* const);
 void bar(Type);
+void foo(const int* const);
+void bar(int);
 #if defined(OBJ)
 void foo_d(const D* const);
 void bar_d(D);
@@ -359,6 +361,23 @@
   // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end(
 }
 
+// Example 1 with const member of non-const object:
+// collects offsets in invariant_start call.
+void ex1_cm() {
+// CHECK: @_Z6ex1_cmv(
+#ifdef LOCAL
+  Type i(one());
+#endif
+
+  // CHECK-L-CO-OBJ: call void @_ZN1AC{{[0-9]+}}Ei({{.*}}* %i,
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8*
+  // {{.*}},
+  bar(i.b);
+  foo();  // Does not change i.b.
+  bar(i.b);
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8*
+}
+
 #endif  // #if defined(OBJ)
 
 // Example 1 with references and pointers:
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -260,9 +260,11 @@
   typedef std::vector CtorList;
 
   struct InvariantArgs {
-llvm::CallInst *StartInst;
-llvm::Value *Size;
+llvm::CallInst *StartInst;  // TODO: Is this necessary?
+llvm::Value *Size;  // TODO: Is this necessary?
 llvm::Value *Addr;
+llvm::SmallVector Offsets;
+
 InvariantArgs() : StartInst(nullptr), Size(nullptr), Addr(nullptr) {}
 InvariantArgs(llvm::CallInst *C, llvm::Value *S, llvm::Value *A)
 : StartInst(C), Size(S), Addr(A) {}
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1905,9 +1905,9 @@
   llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
   CodeGenModule::InvariantArgs EmitInvariantStart(const VarDecl ,
-  llvm::Value *Addr);
-  void EmitInvariantEnd(llvm::CallInst *C, llvm::Value *Size,
-llvm::Value *Addr);
+  llvm::Value *Addr,
+  bool IsGlobalConstant = true);
+  void EmitInvariantEnd(CodeGenModule::InvariantArgs );
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -530,15 +530,13 @@
 
   /// A cleanup to call @llvm.invariant.end.
   class CallInvariantEnd final : public EHScopeStack::Cleanup {
-llvm::CallInst *StartInst;
-llvm::Value *Addr;
-llvm::Value *Size;  // TODO: Is this even necessary?
+CodeGenModule::InvariantArgs Args;
+
public:
-CallInvariantEnd(llvm::CallInst *C, llvm::Value *addr, llvm::Value *size)
-: StartInst(C), Addr(addr), Size(size) {}
+CallInvariantEnd(CodeGenModule::InvariantArgs ) : Args(args) {}
 
 void Emit(CodeGenFunction , Flags flags) override {
-  CGF.EmitInvariantEnd(StartInst, Size, Addr);
+  CGF.EmitInvariantEnd(Args);
 }
   };
 }
@@ -881,16 +879,14 @@
   // If the address is writeonce, then emit @llvm.invariant.start() intrinsic.
   // Then, for non-global variables, push the emission of the
   // @llvm.invariant.end() intrinsic onto the cleanup stack.
-  if ((AI || !GV->isConstant()) && D->getType().isWriteOnce(CGF.getContext()))
-Args = CGF.EmitInvariantStart(*D, AddrPtr);
+  if (AI || !GV->isConstant())
+Args = CGF.EmitInvariantStart(*D, AddrPtr, /*IsGlobalConstant =*/false);
 }
 
 MarkWriteOnceWrittenRAII::~MarkWriteOnceWrittenRAII() {
-  if (AI && Args.StartInst) {
-assert(!GV && "Can't have it both ways!");
-CGF.EHStack.pushCleanup(NormalCleanup, Args.StartInst,
-  Args.Addr, Args.Size);
-  }
+  if (Args.Addr && dyn_cast(Args.Addr->stripPointerCasts()) &&
+  Args.StartInst)
+CGF.EHStack.pushCleanup(NormalCleanup, Args);
 }
 
 /// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a
@@ -932,44 +928,85 @@
   C->setDoesNotThrow();
 }
 
+/// Collect offsets in bits.
+static bool getInvariantOffsets(const CodeGenFunction , QualType Ty,
+llvm::SmallVectorImpl ) {
+  ASTContext  = CGF.getContext();
+  bool FoundWriteOnce = 

Re: [PATCH] D13610: [CodeGen] Fix CodeGenModule::CreateGlobalInitOrDestructFunction

2015-10-09 Thread Akira Hatanaka via cfe-commits
ahatanak added a comment.

Add a comment to send this patch to cfe-commits.


http://reviews.llvm.org/D13610



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


Re: [PATCH] D13407: [libcxx] Capture configuration information when installing the libc++ headers

2015-10-09 Thread Evgeniy Stepanov via cfe-commits
eugenis added a comment.

Thanks. I'll upload the rebase patch on Monday.



Comment at: include/CMakeLists.txt:38
@@ +37,3 @@
+  COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> 
${LIBCXX_BINARY_DIR}/__generated_config
+  DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config
+)

I think you need to depend on __config_site.in as well. Or on 
${LIBCXX_BINARY_DIR}/__config_site 


http://reviews.llvm.org/D13407



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


[libcxx] r249932 - Unrevert r249889, and XFAIL the test for Darwin, where the libc apparently doesn't provide a correct overload set for some functions.

2015-10-09 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct  9 20:39:51 2015
New Revision: 249932

URL: http://llvm.org/viewvc/llvm-project?rev=249932=rev
Log:
Unrevert r249889, and XFAIL the test for Darwin, where the libc apparently 
doesn't provide a correct overload set for some functions.

Added:
libcxx/trunk/include/wchar.h
  - copied unchanged from r249925, libcxx/trunk/include/wchar.h
Modified:
libcxx/trunk/include/cwchar
libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp

Modified: libcxx/trunk/include/cwchar
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=249932=249931=249932=diff
==
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/cwchar Fri Oct  9 20:39:51 2015
@@ -106,9 +106,6 @@ size_t wcsrtombs(char* restrict dst, con
 #include <__config>
 #include 
 #include 
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include  // pull in *swprintf defines
-#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -161,16 +158,13 @@ using ::wcscoll;
 using ::wcsncmp;
 using ::wcsxfrm;
 
-#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
-
+#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
 using ::wcschr;
 using ::wcspbrk;
 using ::wcsrchr;
 using ::wcsstr;
 using ::wmemchr;
-
 #else
-
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 
@@ -185,7 +179,6 @@ inline _LIBCPP_INLINE_VISIBILITY   w
 
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wmemchr(  wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
-
 #endif
 
 using ::wcscspn;

Modified: libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp?rev=249932=249931=249932=diff
==
--- libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp Fri Oct  9 
20:39:51 2015
@@ -9,6 +9,12 @@
 
 // 
 
+// This test fails on systems whose C library doesn't provide a correct 
overload
+// set for wcschr, wcspbrk, wcsrchr, wcsstr, and wmemchr. There's no way for
+// libc++ to fix that on the C library's behalf.
+//
+// XFAIL: apple-darwin
+
 #include 
 #include 
 
@@ -28,13 +34,9 @@
 #error WEOF not defined
 #endif
 
-#if defined(__clang__)
-#pragma clang diagnostic ignored "-Wmissing-braces"
-#endif
-
 int main()
 {
-mbstate_t mb = {};
+mbstate_t mb = {0};
 size_t s = 0;
 tm *tm = 0;
 wint_t w = 0;
@@ -54,19 +56,13 @@ int main()
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
-static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
-static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), "");
@@ -83,14 +79,19 @@ int main()
 static_assert((std::is_same::value), "");
 static_assert((std::is_same::value), 
"");
 static_assert((std::is_same::value), "");
+static_assert((std::is_same::value), "");
 

r249934 - [Concepts] Fixing Concepts TS directory structure; NFC

2015-10-09 Thread Nathan Wilson via cfe-commits
Author: nwilson
Date: Fri Oct  9 21:17:39 2015
New Revision: 249934

URL: http://llvm.org/viewvc/llvm-project?rev=249934=rev
Log:
[Concepts] Fixing Concepts TS directory structure; NFC

Added:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.spec.concept/
  - copied from r249932, 
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/
Removed:
cfe/trunk/test/CXX/concepts-ts/dcl.dcl/dcl.spec/dcl.concept/

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


[PATCH] D13618: [Extension] Optimizing const member objects.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo created this revision.
lvoufo added reviewers: dberlin, chandlerc, majnemer, nlewycky.
lvoufo added a subscriber: cfe-commits.

Continued from D13603...

http://reviews.llvm.org/D13618

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp

Index: test/CodeGenCXX/const-invariant.cpp
===
--- test/CodeGenCXX/const-invariant.cpp
+++ test/CodeGenCXX/const-invariant.cpp
@@ -37,8 +37,8 @@
 #if defined(OBJ)
 struct A {
   int a;
-  int b;
-  A(int a) : a(a) {}
+Const int b;
+A(int a) : a(a), b(a) {}
 };
 
 // A with explicit destructor
@@ -177,6 +177,8 @@
 
 void foo(const Type* const);
 void bar(Type);
+void foo(const int* const);
+void bar(int);
 #if defined(OBJ)
 void foo_d(const D* const);
 void bar_d(D);
@@ -359,6 +361,22 @@
   // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end(
 }
 
+// Example 1 with const member of non-const object:
+// collects offsets in invariant_start call.
+void ex1_cm() {
+// CHECK: @_Z6ex1_cmv(
+#ifdef LOCAL
+  Type i(one());
+#endif
+
+  // CHECK-L-CO-OBJ: call void @_ZN1AC{{[0-9]+}}Ei({{.*}}* %i,
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.start(i64 {{[0-9]+}}, i8* {{.*}},
+  bar(i.b);
+  foo();   // Does not change i.b.
+  bar(i.b);
+  // CHECK-L-CO-OBJ: call {{.*}}@llvm.invariant.end({{.*}}, i64 {{[0-9]+}}, i8*
+}
+
 #endif  // #if defined(OBJ)
 
 // Example 1 with references and pointers:
Index: lib/CodeGen/CodeGenModule.h
===
--- lib/CodeGen/CodeGenModule.h
+++ lib/CodeGen/CodeGenModule.h
@@ -260,12 +260,14 @@
   typedef std::vector CtorList;
 
   struct InvariantArgs {
-llvm::CallInst *StartInst;
-llvm::Value *Size;
+llvm::CallInst *StartInst;  // TODO: Is this necessary?
+llvm::Value *Size;  // TODO: Is this necessary?
 llvm::Value *Addr;
+llvm::SmallVector Offsets;
+
 InvariantArgs() : StartInst(nullptr), Size(nullptr), Addr(nullptr) {}
 InvariantArgs(llvm::CallInst *C, llvm::Value *S, llvm::Value *A)
-: StartInst(C), Size(S), Addr(A) {}
+: StartInst(C), Size(S), Addr(A) {}
   };
 
 private:
Index: lib/CodeGen/CodeGenFunction.h
===
--- lib/CodeGen/CodeGenFunction.h
+++ lib/CodeGen/CodeGenFunction.h
@@ -1904,10 +1904,10 @@
 
   llvm::Value *EmitLifetimeStart(uint64_t Size, llvm::Value *Addr);
   void EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr);
-  CodeGenModule::InvariantArgs EmitInvariantStart(const VarDecl ,
-  llvm::Value *Addr);
-  void EmitInvariantEnd(llvm::CallInst *C, llvm::Value *Size,
-llvm::Value *Addr);
+  CodeGenModule::InvariantArgs
+  EmitInvariantStart(const VarDecl , llvm::Value* Addr,
+ bool IsGlobalConstant = true);
+  void EmitInvariantEnd(CodeGenModule::InvariantArgs );
 
   llvm::Value *EmitCXXNewExpr(const CXXNewExpr *E);
   void EmitCXXDeleteExpr(const CXXDeleteExpr *E);
Index: lib/CodeGen/CGDecl.cpp
===
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -530,15 +530,12 @@
 
   /// A cleanup to call @llvm.invariant.end.
   class CallInvariantEnd final : public EHScopeStack::Cleanup {
-llvm::CallInst *StartInst;
-llvm::Value *Addr;
-llvm::Value *Size;  // TODO: Is this even necessary?
+CodeGenModule::InvariantArgs Args;
public:
-CallInvariantEnd(llvm::CallInst *C, llvm::Value *addr, llvm::Value *size)
-: StartInst(C), Addr(addr), Size(size) {}
+CallInvariantEnd(CodeGenModule::InvariantArgs ) : Args(args) {}
 
 void Emit(CodeGenFunction , Flags flags) override {
-  CGF.EmitInvariantEnd(StartInst, Size, Addr);
+  CGF.EmitInvariantEnd(Args);
 }
   };
 }
@@ -881,16 +878,15 @@
   // If the address is writeonce, then emit @llvm.invariant.start() intrinsic.
   // Then, for non-global variables, push the emission of the
   // @llvm.invariant.end() intrinsic onto the cleanup stack.
-  if ((AI || !GV->isConstant()) && D->getType().isWriteOnce(CGF.getContext()))
-Args = CGF.EmitInvariantStart(*D, AddrPtr);
+  if (AI || !GV->isConstant())
+Args = CGF.EmitInvariantStart(*D, AddrPtr, /*IsGlobalConstant =*/false);
 }
 
 MarkWriteOnceWrittenRAII::~MarkWriteOnceWrittenRAII() {
-  if (AI && Args.StartInst) {
-assert(!GV && "Can't have it both ways!");
-CGF.EHStack.pushCleanup(NormalCleanup, Args.StartInst,
-  Args.Addr, Args.Size);
-  }
+  if (Args.Addr &&
+  dyn_cast(Args.Addr->stripPointerCasts()) &&
+  Args.StartInst)
+CGF.EHStack.pushCleanup(NormalCleanup, Args);
 }
 
 /// EmitAutoVarDecl - Emit code and set up an entry in LocalDeclMap for a
@@ -932,44 +928,87 @@
   C->setDoesNotThrow();
 }
 
+/// Collect 

[PATCH] D13603: [Introduction] C++ Const object optimization.

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo created this revision.
lvoufo added reviewers: chandlerc, majnemer, dberlin, nlewycky.
lvoufo added a subscriber: cfe-commits.

Based on the design doc at 
https://docs.google.com/a/google.com/document/d/1vtoMypqHjkUle8KldKWYYwJF750KkYnEKffQKoYs6jo/edit?usp=sharing,
 it handles non-member const objects.
Extensions are discussed in the design doc and will be submitted separately.


http://reviews.llvm.org/D13603

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,10 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,404 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+ #define Const const
+#else
+ #define Const 
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+  struct A {
+int a;
+int b;
+A(int a) : a(a) { }
+  };
+
+  // A with explicit destructor
+  struct D {
+int a;
+int b;
+D(int a) : a(a) { }
+~D();
+  };
+  
+  // A with mutable data field.
+  struct M {
+int a;
+mutable int b;
+M(int a) : a(a) { }
+void f() { }
+  };
+
+  // A with non-trivial method that may write to memory.
+  struct F {
+int a;
+F(int a) : a(a) { }
+void f();
+  };
+  
+  // A non-virtual base class.
+  struct Base {
+int pa;
+Base(int a);
+  };
+  struct I : public Base {
+

r249894 - Add a fixme to handleTargetFeatures.

2015-10-09 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Fri Oct  9 15:30:48 2015
New Revision: 249894

URL: http://llvm.org/viewvc/llvm-project?rev=249894=rev
Log:
Add a fixme to handleTargetFeatures.

The goal of wanting this to avoid munging the feature list is so
that it can be used for various targets as a way of both adding
and verifying the features that are going to be output into the
IR.

Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=249894=249893=249894=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct  9 15:30:48 2015
@@ -801,6 +801,8 @@ public:
   ///
   /// The target may modify the features list, to change which options are
   /// passed onwards to the backend.
+  /// FIXME: This part should be fixed so that we can change 
handleTargetFeatures
+  /// to merely a TargetInfo initialization routine.
   ///
   /// \return  False on error.
   virtual bool handleTargetFeatures(std::vector ,


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


Re: r248949 - Don't inherit availability information when implementing a protocol requirement.

2015-10-09 Thread Douglas Gregor via cfe-commits

> On Oct 7, 2015, at 11:55 AM, Hans Wennborg  wrote:
> 
> Hi Doug,
> 
> On Wed, Sep 30, 2015 at 2:27 PM, Douglas Gregor via cfe-commits
>  wrote:
>> Author: dgregor
>> Date: Wed Sep 30 16:27:42 2015
>> New Revision: 248949
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=248949=rev
>> Log:
>> Don't inherit availability information when implementing a protocol 
>> requirement.
>> 
>> When an Objective-C method implements a protocol requirement, do not
>> inherit any availability information from the protocol
>> requirement. Rather, check that the implementation is not less
>> available than the protocol requirement, as we do when overriding a
>> method that has availability. Fixes rdar://problem/22734745.
> 
> This is causing new warnings to fire in Chromium, and I'm not sure
> they're correct.
> 
> For example:
> 
>  $ cat | build/bin/clang -c -x objective-c++ -
>  #import 
>  @protocol Foo
>  @end
>  @interface Bar : NSTextView {
>  }
>  @end
>  @implementation Bar
>  - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange {
>[super setMarkedText:aString selectedRange:selRange];
>  }
>  @end
>  :9:10: warning: 'setMarkedText:selectedRange:' is deprecated:
> first deprecated in OS X 10.6 [-Wdeprecated-declarations]
>[super setMarkedText:aString selectedRange:selRange];
>   ^
>  /System/Library/Frameworks/AppKit.framework/Headers/NSInputManager.h:21:1:
> note: 'setMarkedText:selectedRange:' has been explicitly marked
> deprecated here
>  - (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
> NS_DEPRECATED_MAC(10_0, 10_6);
>  ^
> 
> I don't really know Objective-C, but from what I understand,
> NSTextView implements both NSTextInput and NSTextInputClient.
> setMarkedText is deprecated in the former, but not the latter. So
> warning here is probably wrong?

The warning is correct. We no longer infer that -[Bar 
setMarkedText:selectedRange:] is deprecated simply because it matches up with a 
deprecated requirement in the NSTextView protocol. You can mark this method with

NS_DEPRECATED_MAC(10_0, 10_6)

(i.e., copy the availability information from the protocol requirement) to get 
the old behavior.

- Doug

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


Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Aaron Ballman via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

I have commit in r249899. Thanks again!


http://reviews.llvm.org/D11328



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


Re: [PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

2015-10-09 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaExpr.cpp:10246-10253
@@ -10245,1 +10245,10 @@
+
+if (RHS.get()->getType() == Context.OverloadTy) {
+  // As a set of extensions to C, we support overloading on functions. 
These
+  // functions need to be resolved here.
+  DeclAccessPair DAP;
+  if (FunctionDecl *FD = ResolveAddressOfOverloadedFunction(
+  RHS.get(), LHS.get()->getType(), /*Complain=*/false, DAP))
+RHS = FixOverloadedFunctionReference(RHS.get(), DAP, FD);
+}
   }

Converting the RHS to the type of the LHS seems to only be appropriate for 
simple assignment operators, not for arbitrary binary operators.


Comment at: lib/Sema/SemaInit.cpp:4978-4990
@@ -4977,1 +4977,15 @@
 
+// As an extension, C can have overloaded functions. We need to add the
+// address resolution step.
+if (Initializer->getType() == Context.OverloadTy) {
+  bool MultipleCandidates;
+  DeclAccessPair DAP;
+  if (FunctionDecl *FD = S.ResolveAddressOfOverloadedFunction(
+  Initializer, DestType, false, DAP, )) {
+AddAddressOverloadResolutionStep(FD, DAP, MultipleCandidates);
+  } else {
+SetFailed(InitializationSequence::FK_AddressOfOverloadFailed);
+return;
+  }
+}
+

It would seem better to handle this in the assignment rules rather than 
duplicating it between here and the binary operator case.


http://reviews.llvm.org/D13607



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


Re: r174630 - Enable overloading of OpenCL events - this is needed for the overloaded OpenCL builtin functions.

2015-10-09 Thread Richard Smith via cfe-commits
(Resending to correct mailing list address.)

On Fri, Oct 9, 2015 at 3:23 PM, Richard Smith  wrote:

> On Thu, Feb 7, 2013 at 8:05 AM, Guy Benyei  wrote:
>
>> Author: gbenyei
>> Date: Thu Feb  7 10:05:33 2013
>> New Revision: 174630
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=174630=rev
>> Log:
>> Enable overloading of OpenCL events - this is needed for the overloaded
>> OpenCL builtin functions.
>>
>> Added:
>> cfe/trunk/test/SemaOpenCL/event_t_overload.cl
>> Modified:
>> cfe/trunk/include/clang/Sema/Overload.h
>> cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> cfe/trunk/lib/Sema/SemaOverload.cpp
>>
>> Modified: cfe/trunk/include/clang/Sema/Overload.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=174630=174629=174630=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Sema/Overload.h (original)
>> +++ cfe/trunk/include/clang/Sema/Overload.h Thu Feb  7 10:05:33 2013
>> @@ -80,6 +80,7 @@ namespace clang {
>>  ICK_Block_Pointer_Conversion,///< Block Pointer conversions
>>  ICK_TransparentUnionConversion, /// Transparent Union Conversions
>>  ICK_Writeback_Conversion,  ///< Objective-C ARC writeback conversion
>> +ICK_Zero_Event_Conversion, ///< Zero constant to event (OpenCL1.2
>> 6.12.10)
>>
>
> No corresponding change was made to clang::GetConversionRank; what should
> the conversion rank of this be?
>
>
>>  ICK_Num_Conversion_Kinds   ///< The number of conversion kinds
>>};
>>
>>
>> Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=174630=174629=174630=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Feb  7 10:05:33 2013
>> @@ -2783,6 +2783,12 @@ Sema::PerformImplicitConversion(Expr *Fr
>>  break;
>>}
>>
>> +  case ICK_Zero_Event_Conversion:
>> +From = ImpCastExprToType(From, ToType,
>> + CK_ZeroToOCLEvent,
>> + From->getValueKind()).take();
>> +break;
>> +
>>case ICK_Lvalue_To_Rvalue:
>>case ICK_Array_To_Pointer:
>>case ICK_Function_To_Pointer:
>>
>> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=174630=174629=174630=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Thu Feb  7 10:05:33 2013
>> @@ -1633,6 +1633,11 @@ static bool IsStandardConversion(Sema 
>>  // tryAtomicConversion has updated the standard conversion sequence
>>  // appropriately.
>>  return true;
>> +  } else if (ToType->isEventT() &&
>> + From->isIntegerConstantExpr(S.getASTContext()) &&
>> + (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) {
>> +SCS.Second = ICK_Zero_Event_Conversion;
>> +FromType = ToType;
>>} else {
>>  // No second conversion required.
>>  SCS.Second = ICK_Identity;
>> @@ -4871,6 +4876,7 @@ static bool CheckConvertedConstantConver
>>case ICK_Identity:
>>case ICK_Integral_Promotion:
>>case ICK_Integral_Conversion:
>> +  case ICK_Zero_Event_Conversion:
>>  return true;
>>
>>case ICK_Boolean_Conversion:
>>
>> Added: cfe/trunk/test/SemaOpenCL/event_t_overload.cl
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/event_t_overload.cl?rev=174630=auto
>>
>> ==
>> --- cfe/trunk/test/SemaOpenCL/event_t_overload.cl (added)
>> +++ cfe/trunk/test/SemaOpenCL/event_t_overload.cl Thu Feb  7 10:05:33
>> 2013
>> @@ -0,0 +1,11 @@
>> +// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
>> +
>> +void __attribute__((overloadable)) foo(event_t, __local char *); //
>> expected-note {{candidate function not viable: no known conversion from
>> '__global int *' to '__local char *' for 2nd argument}}
>> +void __attribute__((overloadable)) foo(event_t, __local float *); //
>> expected-note {{candidate function not viable: no known conversion from
>> '__global int *' to '__local float *' for 2nd argument}}
>> +
>> +void kernel ker(__local char *src1, __local float *src2, __global int
>> *src3) {
>> +  event_t evt;
>> +  foo(evt, src1);
>> +  foo(0, src2);
>> +  foo(evt, src3); // expected-error {{no matching function for call to
>> 'foo'}}
>> +}
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-comm...@cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

Re: Implict casts disappeared from syntactic init list expressions in C++

2015-10-09 Thread Abramo Bagnara via cfe-commits
Il 08/10/2015 23:36, Richard Smith ha scritto:
> There are some other open problems in this area:
> 
> - RecursiveASTVisitor on nested InitListExprs is currently worst-case
> exponential time because it walks the syntactic and semantic forms
> separately
> - Tools such as "find all references to this function" need the semantic
> form of every initializer, whether or not that initializer is actually
> used for the initialization (it might be overridden through the use of a
> designator)
> - ...
> 
> Having thought about this for a while, I think the right answer is this:
> 
> The only difference between the syntactic and semantic forms of an
> InitListExpr should be designated initializers and brace elision. In all
> other respects, the syntactic and semantic forms should be identical --
> in particular, both should contain the results of performing the
> relevant initialization sequences on the list elements, and we should
> extend the syntactic form to include the implicit initializations for
> trailing elements.

I suppose that you are proposing to include implicit initializations for
trailing elements to have in syntactic form all the references.

Note however that what you suggest is not enough when extending C++ with
designated initializers (like gcc and clang do, at least partially).

This is an example:

struct f1 {
  f1();
};
struct f2 {
  f2();
};

struct s {
  f1 x;
  f2 y;
};

s v = { .x = f1() };

You can easily imagine a similar example where the same effect is
obtained with an array (three elements, first and third are explicitly
initialized).

IMHO it is better to avoid to add implicit fields/array elements
initialization in syntactic form and let tools that need to collect
implicit constructor reference to find a different way, e.g. scanning
semantic form for ImplicitValueInitExpr children of InitListExpr
(unfortunately currently not present (by mistake I guess, but I'd like
to hear your opinion) as you can observe from -ast-dump output of
previous example).

> With that in hand, we should make RecursiveASTVisitor visit /only/ the
> syntactic form. The semantic ("simplified") form should only be used in
> places where we want to know the semantic effect of the initialization
> (after applying the designated initialization overriding rules and
> inserting the elided braces), and is always derivable in a fairly
> straightforward fashion from the syntactic form.
> 
> I think that's largely what you were suggesting below. Do you agree?

Apart the doubt about the detail above, your design matches perfectly my
suggestions.


-- 
Abramo Bagnara

BUGSENG srl - http://bugseng.com
mailto:abramo.bagn...@bugseng.com
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13603: [Introduction] C++ Const object optimization in LLVM

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 36991.
lvoufo added a comment.

Clang-formatted.


http://reviews.llvm.org/D13603

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,12 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to
+// i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to
+// i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,435 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST
+// -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s
+// --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ
+// --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s
+// --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO
+// --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s
+// --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ
+// --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST
+// -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s
+// --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT
+// --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s
+// --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO
+// --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s
+// --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT
+// --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s
+// --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm
+// -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s
+// --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const
+// variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+#define Const const
+#else
+#define Const
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+struct A {
+  int a;
+  int b;
+  A(int a) : a(a) {}
+};
+
+// A with explicit destructor
+struct D {
+  int a;
+  int b;
+  D(int a) : a(a) {}
+  ~D();
+};
+
+// A with mutable data field.
+struct M {
+  int a;
+  mutable int b;
+  M(int a) : a(a) {}
+  void f() {}
+};
+
+// A with non-trivial method that may write to memory.
+struct F {
+  int a;
+  F(int a) : a(a) {}
+  void f();
+};
+
+// A non-virtual base class.
+struct Base {
+  int pa;
+  Base(int a);
+};
+struct I : public Base {
+  int a;
+  int b;
+  I(int a);
+};
+
+// A virtual base class, not-writeonce.
+struct VBase {
+  int pa;
+  VBase(int a);
+  virtual void f();
+};
+struct IV : public VBase {
+  int a;
+  int b;
+  IV(int a);
+};
+
+// A virtual base class, writeonce.
+struct CVBase {
+ 

Re: r248949 - Don't inherit availability information when implementing a protocol requirement.

2015-10-09 Thread Hans Wennborg via cfe-commits
On Fri, Oct 9, 2015 at 1:46 PM, Douglas Gregor  wrote:
>
>> On Oct 7, 2015, at 11:55 AM, Hans Wennborg  wrote:
>>
>> Hi Doug,
>>
>> On Wed, Sep 30, 2015 at 2:27 PM, Douglas Gregor via cfe-commits
>>  wrote:
>>> Author: dgregor
>>> Date: Wed Sep 30 16:27:42 2015
>>> New Revision: 248949
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=248949=rev
>>> Log:
>>> Don't inherit availability information when implementing a protocol 
>>> requirement.
>>>
>>> When an Objective-C method implements a protocol requirement, do not
>>> inherit any availability information from the protocol
>>> requirement. Rather, check that the implementation is not less
>>> available than the protocol requirement, as we do when overriding a
>>> method that has availability. Fixes rdar://problem/22734745.
>>
>> This is causing new warnings to fire in Chromium, and I'm not sure
>> they're correct.
>>
>> For example:
>>
>>  $ cat | build/bin/clang -c -x objective-c++ -
>>  #import 
>>  @protocol Foo
>>  @end
>>  @interface Bar : NSTextView {
>>  }
>>  @end
>>  @implementation Bar
>>  - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange {
>>[super setMarkedText:aString selectedRange:selRange];
>>  }
>>  @end
>>  :9:10: warning: 'setMarkedText:selectedRange:' is deprecated:
>> first deprecated in OS X 10.6 [-Wdeprecated-declarations]
>>[super setMarkedText:aString selectedRange:selRange];
>>   ^
>>  /System/Library/Frameworks/AppKit.framework/Headers/NSInputManager.h:21:1:
>> note: 'setMarkedText:selectedRange:' has been explicitly marked
>> deprecated here
>>  - (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
>> NS_DEPRECATED_MAC(10_0, 10_6);
>>  ^
>>
>> I don't really know Objective-C, but from what I understand,
>> NSTextView implements both NSTextInput and NSTextInputClient.
>> setMarkedText is deprecated in the former, but not the latter. So
>> warning here is probably wrong?
>
> The warning is correct. We no longer infer that -[Bar 
> setMarkedText:selectedRange:] is deprecated simply because it matches up with 
> a deprecated requirement in the NSTextView protocol. You can mark this method 
> with
>
> NS_DEPRECATED_MAC(10_0, 10_6)
>
> (i.e., copy the availability information from the protocol requirement) to 
> get the old behavior.


Again, apologies for my Objective-C ignorance here, but don't you mean
the other way around?

Before this patch we did not warn that setMarkedText was deprecated,
but now we do. It seems we've gone from not inferring that it's
deprecated to doing so?
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13603: [Introduction] C++ Const object optimization in LLVM

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37003.
lvoufo added a comment.

Fix unit test formatting.


http://reviews.llvm.org/D13603

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,12 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to
+// i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to
+// i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,402 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const
+// variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+#define Const const
+#else
+#define Const
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+struct A {
+  int a;
+  int b;
+  A(int a) : a(a) {}
+};
+
+// A with explicit destructor
+struct D {
+  int a;
+  int b;
+  D(int a) : a(a) {}
+  ~D();
+};
+
+// A with mutable data field.
+struct M {
+  int a;
+  mutable int b;
+  M(int a) : a(a) {}
+  void f() {}
+};
+
+// A with non-trivial method that may write to memory.
+struct F {
+  int a;
+  F(int a) : a(a) {}
+  void f();
+};
+
+// A non-virtual base class.
+struct Base {
+  int pa;
+  Base(int a);
+};
+struct I : public Base {
+  int a;
+  int b;
+  I(int a);
+};
+
+// A virtual base class, not-writeonce.
+struct VBase {
+  int pa;
+  VBase(int a);
+  virtual void f();
+};
+struct IV : public VBase {
+  int a;
+  int b;
+  IV(int a);
+};
+
+// A virtual base class, writeonce.
+struct CVBase {
+  int pa;
+  CVBase(int a);
+  virtual void f() = 0;
+  virtual void g() {}
+};
+struct CIV 

[clang-tools-extra] r249899 - Add a new checker that tests whether a throw expression throws by value, and whether a catch statement catches by reference.

2015-10-09 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  9 15:42:44 2015
New Revision: 249899

URL: http://llvm.org/viewvc/llvm-project?rev=249899=rev
Log:
Add a new checker that tests whether a throw expression throws by value, and 
whether a catch statement catches by reference.

Patch by Tobias Langner!

Added:

clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h

clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=249899=249898=249899=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Fri Oct  9 15:42:44 
2015
@@ -17,6 +17,7 @@ add_clang_library(clangTidyMiscModule
   SizeofContainerCheck.cpp
   StaticAssertCheck.cpp
   SwappedArgumentsCheck.cpp
+  ThrowByValueCatchByReferenceCheck.cpp
   UndelegatedConstructor.cpp
   UnusedAliasDeclsCheck.cpp
   UnusedParametersCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=249899=249898=249899=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Fri Oct  9 
15:42:44 2015
@@ -25,6 +25,7 @@
 #include "SizeofContainerCheck.h"
 #include "StaticAssertCheck.h"
 #include "SwappedArgumentsCheck.h"
+#include "ThrowByValueCatchByReferenceCheck.h"
 #include "UndelegatedConstructor.h"
 #include "UniqueptrResetReleaseCheck.h"
 #include "UnusedAliasDeclsCheck.h"
@@ -66,6 +67,8 @@ public:
 "misc-static-assert");
 CheckFactories.registerCheck(
 "misc-swapped-arguments");
+CheckFactories.registerCheck(
+"misc-throw-by-value-catch-by-reference");
 CheckFactories.registerCheck(
 "misc-undelegated-constructor");
 CheckFactories.registerCheck(

Added: 
clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp?rev=249899=auto
==
--- 
clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp 
(added)
+++ 
clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp 
Fri Oct  9 15:42:44 2015
@@ -0,0 +1,159 @@
+//===--- ThrowByValueCatchByReferenceCheck.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 "ThrowByValueCatchByReferenceCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/AST/OperationKinds.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+
+ThrowByValueCatchByReferenceCheck::ThrowByValueCatchByReferenceCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  CheckAnonymousTemporaries(Options.get("CheckThrowTemporaries", true)) {}
+
+void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
+  // This is a C++ only check thus we register the matchers only for C++
+  if (!getLangOpts().CPlusPlus)
+return;
+
+  Finder->addMatcher(cxxThrowExpr().bind("throw"), this);
+  Finder->addMatcher(cxxCatchStmt().bind("catch"), this);
+}
+
+void ThrowByValueCatchByReferenceCheck::storeOptions(
+ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "CheckThrowTemporaries", true);
+}
+
+void ThrowByValueCatchByReferenceCheck::check(
+const MatchFinder::MatchResult ) {
+  diagnoseThrowLocations(Result.Nodes.getNodeAs("throw"));
+  diagnoseCatchLocations(Result.Nodes.getNodeAs("catch"),
+ *Result.Context);
+}
+
+bool ThrowByValueCatchByReferenceCheck::isFunctionParameter(
+const DeclRefExpr *declRefExpr) {
+  return isa(declRefExpr->getDecl());
+}
+
+bool ThrowByValueCatchByReferenceCheck::isCatchVariable(
+const DeclRefExpr *declRefExpr) {
+  auto *valueDecl = declRefExpr->getDecl();
+  if (auto *varDecl = dyn_cast(valueDecl))
+return varDecl->isExceptionVariable();
+  return false;
+}
+
+bool ThrowByValueCatchByReferenceCheck::isFunctionOrCatchVar(
+const 

Re: [PATCH] D13603: [Introduction] C++ Const object optimization in LLVM

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37005.
lvoufo added a comment.

All formatting changes should be done by now.


http://reviews.llvm.org/D13603

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,10 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,402 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const
+// variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+#define Const const
+#else
+#define Const
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+struct A {
+  int a;
+  int b;
+  A(int a) : a(a) {}
+};
+
+// A with explicit destructor
+struct D {
+  int a;
+  int b;
+  D(int a) : a(a) {}
+  ~D();
+};
+
+// A with mutable data field.
+struct M {
+  int a;
+  mutable int b;
+  M(int a) : a(a) {}
+  void f() {}
+};
+
+// A with non-trivial method that may write to memory.
+struct F {
+  int a;
+  F(int a) : a(a) {}
+  void f();
+};
+
+// A non-virtual base class.
+struct Base {
+  int pa;
+  Base(int a);
+};
+struct I : public Base {
+  int a;
+  int b;
+  I(int a);
+};
+
+// A virtual base class, not-writeonce.
+struct VBase {
+  int pa;
+  VBase(int a);
+  virtual void f();
+};
+struct IV : public VBase {
+  int a;
+  int b;
+  IV(int a);
+};
+
+// A virtual base class, writeonce.
+struct CVBase {
+  int pa;
+  CVBase(int a);
+  virtual void f() = 0;
+  virtual void g() {}
+};

Re: [PATCH] D12747: Implement [depr.c.headers]

2015-10-09 Thread Eric Fiselier via cfe-commits
Regarding Patch #15.

1. Tests under 'test/std' shouldn't directly include <__config> or
depend on any libc++ implementation details. We are trying to make the
test suite generic so refrain from referencing libc++ symbols.
2. "static_assert" is C++11 only but this test should work in C++03.
Can you use "#if TEST_STD_VER >= 11" from "test_macros.h" to use
static assert in C++11 and just "assert" in C++03 (or something
similar)?
3. Could you throw the standarese that requires this behavior at the
top of the test?

LGTM after you address those points.

/Eric


On Fri, Oct 9, 2015 at 4:26 PM, Eric Fiselier  wrote:
> Patch #12 LGTM. Thanks for doing tho cwchar approach in this patch.
> One small nit. I would prefer a "negative" feature macro for
> "_LIBCPP_STRING_H_HAS_CONST_OVERLOADS" because correct defaults
> shouldn't need a macro definition to be selected. (ie
> _LIBCPP_STRING_H_HAS_NO_CONST_OVERLOAD.)
>
> /Eric
>
> On Fri, Oct 9, 2015 at 1:59 PM, Richard Smith  wrote:
>> As of r249890, all committed other than patches 12 (string.h) and 15 (more
>> tests).
>>
>> On Thu, Oct 8, 2015 at 9:12 PM, Richard Smith  wrote:
>>>
>>> On Thu, Oct 8, 2015 at 6:58 PM, Richard Smith 
>>> wrote:

 On Thu, Oct 8, 2015 at 6:25 PM, Eric Fiselier  wrote:
>
> Patch #12 needs revision. A bunch of function definitions were moved
> out of the std namespace and into the global.
> That change is incorrect.


 Slightly updated version attached. I should probably explain what's going
 on here in more detail:

 Per [c.strings]p4-p13, we're supposed to replace C functions of the form

   char *foo(const char*);

 with a pair of const-correct overloads of the form

   char *foo(char *);
   const char *foo(const char*);

 Now, most C standard libraries will do this for us when included in C++
 mode (because it's not possible for the C++ library to fix this up after 
 the
 fact). For the cases where we *don't* believe we have such a considerate C
 library, we add one declaration to C's overload, to get:

   char *foo(char*);
   char *foo(const char*)

 ... which doesn't really help much, but is the closest we can get to the
 right set of declarations. The declarations we add just dispatch to the C
 declarations.

 These new declarations *should* be in the global namespace when including
 , and it makes sense for us to put them in the global namespace
 when including  (otherwise, that header leaves us with a broken
 overload set in the global namespace, containing just one of the two
 expected functions).

 Anyway, most of the above is a description of what we did before. What's
 new here is that we attempt to fix the overload set for both  and
 for , not just for the latter. At the end of all these changes,
 you'll see that all that the  headers do is to include the 
 header and use using-declarations to pull the names into namespace std; 
 this
 is no exception to that pattern.
>>>
>>>
>>> Per Eric and my discussion on IRC, the pattern used by  seems
>>> better here:
>>>
>>> If libc has left us with a bad overload set, don't try to fix the names in
>>> ::, just provide a complete set of overloads in namespace std.
>>>
>>> A patch for that approach is attached.
>>>
> On Thu, Oct 8, 2015 at 7:09 PM, Eric Fiselier  wrote:
> > Patch #11 LGTM. Any reason you removed the "#pragma diagnostic ignored
> > "-Wnonnull"" in test/std/depr/depr.c.headers/stdlib_h.pass.cpp?
> > I would like to leave it in so this test doesn't fail with older clang
> > versions.
> >
> > /Eric
> >
> > On Thu, Oct 8, 2015 at 6:47 PM, Eric Fiselier  wrote:
> >> Patch #10 LGTM.
> >>
> >> On Thu, Oct 8, 2015 at 4:28 PM, Richard Smith 
> >> wrote:
> >>> On Thu, Oct 8, 2015 at 11:50 AM, Marshall Clow
> >>> 
> >>> wrote:
> 
>  On Tue, Oct 6, 2015 at 3:57 PM, Richard Smith
>  
>  wrote:
> >
> > . This one is tricky:
> >
> > 1) There's an (undocumented) interface between the C standard
> > library and
> > this header, where the macros __need_ptrdiff_t, __need_size_t,
> > __need_wchar_t, __need_NULL, __need_wint_t request just a piece of
> > this
> > header rather than the whole thing. If we see any of those, just
> > go straight
> > to the underlying header.
> 
> 
>  Ok, but in that case we don't get nullptr.  I suspect that's OK.
> 
> >
> > 2) We probably don't want  to include  (for
> > consistency with other headers)
> 
> 
>  No, we do not! :-)

r249893 - [Myriad]: put libstdc++ and libc in the right order

2015-10-09 Thread Douglas Katzman via cfe-commits
Author: dougk
Date: Fri Oct  9 15:26:20 2015
New Revision: 249893

URL: http://llvm.org/viewvc/llvm-project?rev=249893=rev
Log:
[Myriad]: put libstdc++ and libc in the right order

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/myriad-toolchain.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=249893=249892=249893=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Oct  9 15:26:20 2015
@@ -9885,6 +9885,8 @@ void tools::Myriad::Linker::ConstructJob
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
 
   if (UseDefaultLibs) {
+if (C.getDriver().CCCIsCXX())
+  CmdArgs.push_back("-lstdc++");
 if (T.getOS() == llvm::Triple::RTEMS) {
   CmdArgs.push_back("--start-group");
   CmdArgs.push_back("-lc");
@@ -9895,8 +9897,6 @@ void tools::Myriad::Linker::ConstructJob
 } else {
   CmdArgs.push_back("-lc");
 }
-if (C.getDriver().CCCIsCXX())
-  CmdArgs.push_back("-lstdc++");
 CmdArgs.push_back("-lgcc");
   }
   if (UseStartfiles) {

Modified: cfe/trunk/test/Driver/myriad-toolchain.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/myriad-toolchain.c?rev=249893=249892=249893=diff
==
--- cfe/trunk/test/Driver/myriad-toolchain.c (original)
+++ cfe/trunk/test/Driver/myriad-toolchain.c Fri Oct  9 15:26:20 2015
@@ -54,8 +54,10 @@
 // RUN:   | FileCheck %s -check-prefix=MDMF
 // MDMF: "-S" "-MD" "-MF" "dep.d" "-MT" "foo.o"
 
+// RUN: %clang -target sparc-myriad -### --driver-mode=g++ %s 2>&1 | FileCheck 
%s --check-prefix=STDLIBCXX
+// STDLIBCXX: "-lstdc++" "-lc" "-lgcc"
+
 // RUN: %clang -target sparc-myriad -### -nostdlib %s 2>&1 | FileCheck %s 
--check-prefix=NOSTDLIB
-//
 // NOSTDLIB-NOT: "-lc"
 
 // RUN: %clang -### -c -g %s -target sparc-myriad 2>&1 | FileCheck 
-check-prefix=G_SPARC %s


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


r249896 - Fix inference of _Nullable for weak Objective-C properties.

2015-10-09 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Fri Oct  9 15:36:17 2015
New Revision: 249896

URL: http://llvm.org/viewvc/llvm-project?rev=249896=rev
Log:
Fix inference of _Nullable for weak Objective-C properties.

The inference of _Nullable for weak Objective-C properties was broken
in several ways:

* It was back-patching the type information very late in the process
  of checking the attributes for an Objective-C property, which is
  just wrong.
* It was using ad hoc checks to try to suppress the warning about
  missing nullability specifiers (-Wnullability-completeness), which
  didn't actual work in all cases (rdar://problem/22985457)
* It was inferring _Nullable even outside of assumes-nonnull regions,
  which is wrong.

Putting the inference of _Nullable for weak Objective-C properties in
the same place as all of the other inference logic fixes all of these
ills.


Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
cfe/trunk/test/SemaObjC/nullable-weak-property.m
cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-2.h
cfe/trunk/test/SemaObjCXX/Inputs/nullability-consistency-6.h

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=249896=249895=249896=diff
==
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Fri Oct  9 15:36:17 2015
@@ -181,7 +181,7 @@ Decl *Sema::ActOnProperty(Scope *S, Sour
   }
 
   // Validate the attributes on the @property.
-  CheckObjCPropertyAttributes(Res, AtLoc, Attributes, 
+  CheckObjCPropertyAttributes(Res, AtLoc, Attributes,
   (isa(ClassDecl) ||
isa(ClassDecl)));
 
@@ -2301,13 +2301,6 @@ void Sema::CheckObjCPropertyAttributes(D
   if (*nullability == NullabilityKind::NonNull)
 Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
   << "nonnull" << "weak";
-} else {
-PropertyTy =
-  Context.getAttributedType(
-AttributedType::getNullabilityAttrKind(NullabilityKind::Nullable),
-PropertyTy, PropertyTy);
-TypeSourceInfo *TSInfo = PropertyDecl->getTypeSourceInfo();
-PropertyDecl->setType(PropertyTy, TSInfo);
 }
   }
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=249896=249895=249896=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Fri Oct  9 15:36:17 2015
@@ -3311,9 +3311,7 @@ static TypeSourceInfo *GetFullTypeForDec
 
   // Are we in an assume-nonnull region?
   bool inAssumeNonNullRegion = false;
-  if (S.PP.getPragmaAssumeNonNullLoc().isValid() &&
-  !state.getDeclarator().isObjCWeakProperty() &&
-  !S.deduceWeakPropertyFromType(T)) {
+  if (S.PP.getPragmaAssumeNonNullLoc().isValid()) {
 inAssumeNonNullRegion = true;
 // Determine which file we saw the assume-nonnull region in.
 FileID file = getNullabilityCompletenessCheckFileID(
@@ -3392,6 +3390,13 @@ static TypeSourceInfo *GetFullTypeForDec
 complainAboutMissingNullability = CAMN_No;
 break;
   }
+
+  // Weak properties are inferred to be nullable.
+  if (state.getDeclarator().isObjCWeakProperty() && inAssumeNonNullRegion) 
{
+inferNullability = NullabilityKind::Nullable;
+break;
+  }
+
   // fallthrough
 
 case Declarator::FileContext:

Modified: cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m?rev=249896=249895=249896=diff
==
--- cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m (original)
+++ cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m Fri Oct  9 15:36:17 
2015
@@ -56,7 +56,7 @@ __attribute__((objc_arc_weak_reference_u
 @interface I
 {
 }
-@property (weak) NSFont *font; // expected-error {{synthesizing __weak 
instance variable of type 'NSFont * _Nullable', which does not support weak 
references}}
+@property (weak) NSFont *font; // expected-error {{synthesizing __weak 
instance variable of type 'NSFont *', which does not support weak references}}
 @end
 
 @implementation I // expected-note {{when implemented by class I}}
@@ -65,7 +65,7 @@ __attribute__((objc_arc_weak_reference_u
 
 // rdar://13676793
 @protocol MyProtocol
-@property (weak) NSFont *font; // expected-error {{synthesizing __weak 
instance variable of type 'NSFont * _Nullable', which does not support weak 
references}}
+@property (weak) NSFont *font; // expected-error {{synthesizing __weak 
instance variable of type 'NSFont *', which does not support weak 

Re: [PATCH] D13604: Fix to allow C conversions on arguments passed to functions with __attribute__((overloadable)) in C

2015-10-09 Thread Richard Smith via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Instead of `FixRHS`, I'd prefer either `ConvertRHS` or `PerformConversion` as 
your parameter name. Otherwise, LGTM, thanks!



Comment at: lib/Sema/SemaOverload.cpp:1444-1445
@@ -1438,3 +1443,4 @@
+  // abort early. When overloading in C, however, we do permit them.
   if (FromType->isRecordType() || ToType->isRecordType()) {
 if (S.getLangOpts().CPlusPlus)
   return false;

Fold these two 'if's together.


http://reviews.llvm.org/D13604



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


Re: [PATCH] D12747: Implement [depr.c.headers]

2015-10-09 Thread Eric Fiselier via cfe-commits
@Marshall, @Richard Have we fixed the Solaris build yet?

On Fri, Oct 9, 2015 at 4:48 PM, Eric Fiselier  wrote:
> Regarding Patch #15.
>
> 1. Tests under 'test/std' shouldn't directly include <__config> or
> depend on any libc++ implementation details. We are trying to make the
> test suite generic so refrain from referencing libc++ symbols.
> 2. "static_assert" is C++11 only but this test should work in C++03.
> Can you use "#if TEST_STD_VER >= 11" from "test_macros.h" to use
> static assert in C++11 and just "assert" in C++03 (or something
> similar)?
> 3. Could you throw the standarese that requires this behavior at the
> top of the test?
>
> LGTM after you address those points.
>
> /Eric
>
>
> On Fri, Oct 9, 2015 at 4:26 PM, Eric Fiselier  wrote:
>> Patch #12 LGTM. Thanks for doing tho cwchar approach in this patch.
>> One small nit. I would prefer a "negative" feature macro for
>> "_LIBCPP_STRING_H_HAS_CONST_OVERLOADS" because correct defaults
>> shouldn't need a macro definition to be selected. (ie
>> _LIBCPP_STRING_H_HAS_NO_CONST_OVERLOAD.)
>>
>> /Eric
>>
>> On Fri, Oct 9, 2015 at 1:59 PM, Richard Smith  wrote:
>>> As of r249890, all committed other than patches 12 (string.h) and 15 (more
>>> tests).
>>>
>>> On Thu, Oct 8, 2015 at 9:12 PM, Richard Smith  wrote:

 On Thu, Oct 8, 2015 at 6:58 PM, Richard Smith 
 wrote:
>
> On Thu, Oct 8, 2015 at 6:25 PM, Eric Fiselier  wrote:
>>
>> Patch #12 needs revision. A bunch of function definitions were moved
>> out of the std namespace and into the global.
>> That change is incorrect.
>
>
> Slightly updated version attached. I should probably explain what's going
> on here in more detail:
>
> Per [c.strings]p4-p13, we're supposed to replace C functions of the form
>
>   char *foo(const char*);
>
> with a pair of const-correct overloads of the form
>
>   char *foo(char *);
>   const char *foo(const char*);
>
> Now, most C standard libraries will do this for us when included in C++
> mode (because it's not possible for the C++ library to fix this up after 
> the
> fact). For the cases where we *don't* believe we have such a considerate C
> library, we add one declaration to C's overload, to get:
>
>   char *foo(char*);
>   char *foo(const char*)
>
> ... which doesn't really help much, but is the closest we can get to the
> right set of declarations. The declarations we add just dispatch to the C
> declarations.
>
> These new declarations *should* be in the global namespace when including
> , and it makes sense for us to put them in the global namespace
> when including  (otherwise, that header leaves us with a broken
> overload set in the global namespace, containing just one of the two
> expected functions).
>
> Anyway, most of the above is a description of what we did before. What's
> new here is that we attempt to fix the overload set for both  
> and
> for , not just for the latter. At the end of all these changes,
> you'll see that all that the  headers do is to include the 
> header and use using-declarations to pull the names into namespace std; 
> this
> is no exception to that pattern.


 Per Eric and my discussion on IRC, the pattern used by  seems
 better here:

 If libc has left us with a bad overload set, don't try to fix the names in
 ::, just provide a complete set of overloads in namespace std.

 A patch for that approach is attached.

>> On Thu, Oct 8, 2015 at 7:09 PM, Eric Fiselier  wrote:
>> > Patch #11 LGTM. Any reason you removed the "#pragma diagnostic ignored
>> > "-Wnonnull"" in test/std/depr/depr.c.headers/stdlib_h.pass.cpp?
>> > I would like to leave it in so this test doesn't fail with older clang
>> > versions.
>> >
>> > /Eric
>> >
>> > On Thu, Oct 8, 2015 at 6:47 PM, Eric Fiselier  wrote:
>> >> Patch #10 LGTM.
>> >>
>> >> On Thu, Oct 8, 2015 at 4:28 PM, Richard Smith 
>> >> wrote:
>> >>> On Thu, Oct 8, 2015 at 11:50 AM, Marshall Clow
>> >>> 
>> >>> wrote:
>> 
>>  On Tue, Oct 6, 2015 at 3:57 PM, Richard Smith
>>  
>>  wrote:
>> >
>> > . This one is tricky:
>> >
>> > 1) There's an (undocumented) interface between the C standard
>> > library and
>> > this header, where the macros __need_ptrdiff_t, __need_size_t,
>> > __need_wchar_t, __need_NULL, __need_wint_t request just a piece of
>> > this
>> > header rather than the whole thing. If we see any of those, just
>> > go straight
>> > to the underlying header.
>> 

Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Tobias Langner via cfe-commits
randomcppprogrammer updated this revision to Diff 36983.
randomcppprogrammer added a comment.

fixed formatting


http://reviews.llvm.org/D11328

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
  clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
  test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp

Index: test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
@@ -0,0 +1,156 @@
+// RUN: %python %S/check_clang_tidy.py %s misc-throw-by-value-catch-by-reference %t
+
+
+class logic_error {
+public:
+  logic_error(const char *message) {}
+};
+
+typedef logic_error *logic_ptr;
+typedef logic_ptr logic_double_typedef;
+
+int lastException;
+
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+
+template  typename remove_reference::type &(T &) {
+  return static_cast::type &&>(arg);
+}
+
+logic_error CreateException() { return logic_error("created"); }
+
+void testThrowFunc() {
+  throw new logic_error("by pointer");
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  logic_ptr tmp = new logic_error("by pointer");
+  throw tmp;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  throw logic_error("by value");
+  auto *literal = "test";
+  throw logic_error(literal);
+  throw "test string literal";
+  throw L"throw wide string literal";
+  const char *characters = 0;
+  throw characters;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  logic_error lvalue("lvalue");
+  throw lvalue;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+
+  throw move(lvalue);
+  int  = lastException;
+  throw ex;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  throw CreateException();
+}
+
+void throwReferenceFunc(logic_error ) { throw ref; }
+
+void catchByPointer() {
+  try {
+testThrowFunc();
+  } catch (logic_error *e) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchByValue() {
+  try {
+testThrowFunc();
+  } catch (logic_error e) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchByReference() {
+  try {
+testThrowFunc();
+  } catch (logic_error ) {
+  }
+}
+
+void catchByConstReference() {
+  try {
+testThrowFunc();
+  } catch (const logic_error ) {
+  }
+}
+
+void catchTypedef() {
+  try {
+testThrowFunc();
+  } catch (logic_ptr) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchAll() {
+  try {
+testThrowFunc();
+  } catch (...) {
+  }
+}
+
+void catchLiteral() {
+  try {
+testThrowFunc();
+  } catch (const char *) {
+  } catch (const wchar_t *) {
+// disabled for now until it is clear
+// how to enable them in the test
+//} catch (const char16_t*) {
+//} catch (const char32_t*) {
+  }
+}
+
+// catching fundamentals should not warn
+void catchFundamental() {
+  try {
+testThrowFunc();
+  } catch (int) {
+  } catch (double) {
+  } catch (unsigned long) {
+  }
+}
+
+struct TrivialType {
+  double x;
+  double y;
+};
+
+void catchTrivial() {
+  try {
+testThrowFunc();
+  } catch (TrivialType) {
+  }
+}
+
+typedef logic_error 
+void additionalTests() {
+  try {
+  } catch (int i) {  // ok
+throw i; // ok
+  } catch (fine e) { // ok
+throw e; // ok
+  } catch (logic_error *e) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead 

[clang-tools-extra] r249905 - Explicitly enable -fcxx-exceptions for this test to appease Windows build bots.

2015-10-09 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  9 16:15:00 2015
New Revision: 249905

URL: http://llvm.org/viewvc/llvm-project?rev=249905=rev
Log:
Explicitly enable -fcxx-exceptions for this test to appease Windows build bots.

Modified:

clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp

Modified: 
clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp?rev=249905=249904=249905=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
 (original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
 Fri Oct  9 16:15:00 2015
@@ -1,4 +1,4 @@
-// RUN: %python %S/check_clang_tidy.py %s 
misc-throw-by-value-catch-by-reference %t
+// RUN: %python %S/check_clang_tidy.py %s 
misc-throw-by-value-catch-by-reference %t -- -std=c++11 -fcxx-exceptions
 
 
 class logic_error {


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


Re: [PATCH] D13603: [Introduction] C++ Const object optimization in LLVM

2015-10-09 Thread Larisse Voufo via cfe-commits
lvoufo updated this revision to Diff 37004.
lvoufo added a comment.

Fix regression test formatting.


http://reviews.llvm.org/D13603

Files:
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  test/CodeGenCXX/const-invariant.cpp
  test/CodeGenCXX/init-invariant.cpp

Index: test/CodeGenCXX/init-invariant.cpp
===
--- test/CodeGenCXX/init-invariant.cpp
+++ test/CodeGenCXX/init-invariant.cpp
@@ -45,10 +45,12 @@
 // CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @a to i8*))
 
 // CHECK: call void @_ZN1BC1Ev({{.*}}* nonnull @b)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @b to
+// i8*))
 
 // CHECK: call void @_ZN1CC1Ev({{.*}}* nonnull @c)
-// CHECK-NOT: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to i8*))
+// CHECK: call {{.*}}@llvm.invariant.start(i64 4, i8* bitcast ({{.*}} @c to
+// i8*))
 
 // CHECK: call i32 @_Z1fv(
 // CHECK: store {{.*}}, i32* @d
Index: test/CodeGenCXX/const-invariant.cpp
===
--- /dev/null
+++ test/CodeGenCXX/const-invariant.cpp
@@ -0,0 +1,402 @@
+// *** const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DOBJ | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-OBJ --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-OBJ
+
+// *** const variables of builtin type.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O0 -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-O0
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DCONST -DINT | FileCheck %s --check-prefix=CHECK-L-CO --check-prefix=CHECK-L-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-GP-CO --check-prefix=CHECK-NL-CO --check-prefix=CHECK-NL-CO-INT --check-prefix=CHECK-NG-CO
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DCONST -DINT | FileCheck %s --check-prefix=CHECK-G-CO --check-prefix=CHECK-G-CO-INT --check-prefix=CHECK-NL-CO
+
+// *** non-const objects.
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DPART_GLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+// RUN: %clang -x c++ -emit-llvm -target x86_64-linux-gnu -S %s -O2 -mllvm -disable-llvm-optzns -o - -DGLOBAL -DOBJ | FileCheck %s --check-prefix=CHECK-NC
+
+// Check that llvm.invariant.start/end are properly generated on C++ const
+// variables.
+
+// Do not produce markers at -O0.
+// CHECK-O0-NOT: llvm.invariant.start
+// CHECK-O0-NOT: llvm.invariant.end
+
+// Do not produce markers from non-const objects
+// CHECK-NC-NOT: llvm.invariant.start
+// CHECK-NC-NOT: llvm.invariant.end
+
+// const or not?
+#ifdef CONST
+#define Const const
+#else
+#define Const
+#endif
+
+// object or builtin?
+#if defined(OBJ)
+struct A {
+  int a;
+  int b;
+  A(int a) : a(a) {}
+};
+
+// A with explicit destructor
+struct D {
+  int a;
+  int b;
+  D(int a) : a(a) {}
+  ~D();
+};
+
+// A with mutable data field.
+struct M {
+  int a;
+  mutable int b;
+  M(int a) : a(a) {}
+  void f() {}
+};
+
+// A with non-trivial method that may write to memory.
+struct F {
+  int a;
+  F(int a) : a(a) {}
+  void f();
+};
+
+// A non-virtual base class.
+struct Base {
+  int pa;
+  Base(int a);
+};
+struct I : public Base {
+  int a;
+  int b;
+  I(int a);
+};
+
+// A virtual base class, not-writeonce.
+struct VBase {
+  int pa;
+  VBase(int a);
+  virtual void f();
+};
+struct IV : public VBase {
+  int a;
+  int b;
+  IV(int a);
+};
+
+// A virtual base class, writeonce.
+struct CVBase {
+  int pa;
+  CVBase(int a);
+  virtual void f() = 0;
+  virtual void g() {}
+};

[libcxx] r249939 - Turn off -pedantic by default when building due to #include_next. :-(

2015-10-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Oct  9 22:34:52 2015
New Revision: 249939

URL: http://llvm.org/viewvc/llvm-project?rev=249939=rev
Log:
Turn off -pedantic by default when building due to #include_next. :-(

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=249939=249938=249939=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Fri Oct  9 22:34:52 2015
@@ -89,7 +89,9 @@ option(LIBCXX_ENABLE_MONOTONIC_CLOCK
This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON)
 
 # Misc options 
-option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
+# FIXME: Turn -pedantic back ON. It is currently off because it warns
+# about #include_next which is used everywhere.
+option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
 
 option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF)


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


Re: r248949 - Don't inherit availability information when implementing a protocol requirement.

2015-10-09 Thread Douglas Gregor via cfe-commits


Sent from my iPhone

> On Oct 9, 2015, at 2:17 PM, Hans Wennborg  wrote:
> 
>> On Fri, Oct 9, 2015 at 1:46 PM, Douglas Gregor  wrote:
>> 
>>> On Oct 7, 2015, at 11:55 AM, Hans Wennborg  wrote:
>>> 
>>> Hi Doug,
>>> 
>>> On Wed, Sep 30, 2015 at 2:27 PM, Douglas Gregor via cfe-commits
>>>  wrote:
 Author: dgregor
 Date: Wed Sep 30 16:27:42 2015
 New Revision: 248949
 
 URL: http://llvm.org/viewvc/llvm-project?rev=248949=rev
 Log:
 Don't inherit availability information when implementing a protocol 
 requirement.
 
 When an Objective-C method implements a protocol requirement, do not
 inherit any availability information from the protocol
 requirement. Rather, check that the implementation is not less
 available than the protocol requirement, as we do when overriding a
 method that has availability. Fixes rdar://problem/22734745.
>>> 
>>> This is causing new warnings to fire in Chromium, and I'm not sure
>>> they're correct.
>>> 
>>> For example:
>>> 
>>> $ cat | build/bin/clang -c -x objective-c++ -
>>> #import 
>>> @protocol Foo
>>> @end
>>> @interface Bar : NSTextView {
>>> }
>>> @end
>>> @implementation Bar
>>> - (void)setMarkedText:(id)aString selectedRange:(NSRange)selRange {
>>>   [super setMarkedText:aString selectedRange:selRange];
>>> }
>>> @end
>>> :9:10: warning: 'setMarkedText:selectedRange:' is deprecated:
>>> first deprecated in OS X 10.6 [-Wdeprecated-declarations]
>>>   [super setMarkedText:aString selectedRange:selRange];
>>>  ^
>>> /System/Library/Frameworks/AppKit.framework/Headers/NSInputManager.h:21:1:
>>> note: 'setMarkedText:selectedRange:' has been explicitly marked
>>> deprecated here
>>> - (void) setMarkedText:(id)aString selectedRange:(NSRange)selRange
>>> NS_DEPRECATED_MAC(10_0, 10_6);
>>> ^
>>> 
>>> I don't really know Objective-C, but from what I understand,
>>> NSTextView implements both NSTextInput and NSTextInputClient.
>>> setMarkedText is deprecated in the former, but not the latter. So
>>> warning here is probably wrong?
>> 
>> The warning is correct. We no longer infer that -[Bar 
>> setMarkedText:selectedRange:] is deprecated simply because it matches up 
>> with a deprecated requirement in the NSTextView protocol. You can mark this 
>> method with
>> 
>>NS_DEPRECATED_MAC(10_0, 10_6)
>> 
>> (i.e., copy the availability information from the protocol requirement) to 
>> get the old behavior.
> 
> 
> Again, apologies for my Objective-C ignorance here, but don't you mean
> the other way around?

No, I have it correct. 

> Before this patch we did not warn that setMarkedText was deprecated,
> but now we do. It seems we've gone from not inferring that it's
> deprecated to doing so?

NSTextView's setMarkedText is deprecated. Whether we diagnose a call to a 
deprecated method depends on the context: inside another deprecated method we 
suppress the diagnostic. 

That's where the inference comes in. We used to (incorrectly) infer that Bar's 
setMarkedText was deprecated. That's wrong, and it suppressed the deprecated 
warning for the call to the NSTextView version. 

  - Doug

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


[libcxx] r249938 - Revert r249931 - Remove same_decls.pass.cpp because it fails on OS X and in C++03 mode.

2015-10-09 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Fri Oct  9 22:31:23 2015
New Revision: 249938

URL: http://llvm.org/viewvc/llvm-project?rev=249938=rev
Log:
Revert r249931 - Remove same_decls.pass.cpp because it fails on OS X and in 
C++03 mode.

Removed:
libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp

Removed: libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp?rev=249937=auto
==
--- libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp (original)
+++ libcxx/trunk/test/std/depr/depr.c.headers/same_decls.pass.cpp (removed)
@@ -1,517 +0,0 @@
-//===--===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is dual licensed under the MIT and the University of Illinois Open
-// Source Licenses. See LICENSE.TXT for details.
-//
-//===--===//
-
-// [depr.c.headers]p2:
-//   Every C header, each of which has a name of the form name.h, behaves as if
-//   each name placed in the standard library namespace by the corresponding
-//   cname header is placed within the global namespace scope.
-//
-// This implies that the name in the global namespace and the name in namespace
-// std declare the same entity, so check that that is actually the case.
-
-// Pull in libc++'s static_assert emulation if in C++98 mode.
-#include 
-
-template struct check { static_assert(F == G, ""); };
-
-// ctype.h
-
-#include 
-#include 
-
-void test_ctype() {
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-}
-
-// fenv.h
-
-#include 
-#include 
-
-void test_fenv() {
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-}
-
-// inttypes.h
-
-#include 
-#include 
-
-// Avoid error if abs and div are not declared by .
-struct nat {};
-static void abs(nat);
-static void div(nat);
-namespace std {
-  static void abs(nat);
-  static void div(nat);
-}
-
-// These may or may not exist, depending on whether intmax_t
-// is an extended integer type (larger than long long).
-template sizeof(long long))>
-void test_inttypes_abs_div() {
-  check();
-  check();
-}
-template<> void test_inttypes_abs_div() {}
-
-void test_inttypes() {
-  test_inttypes_abs_div();
-
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-}
-
-// locale.h
-
-#include 
-#include 
-
-void test_locale() {
-  check();
-  check();
-}
-
-// math.h
-
-#include 
-#include 
-
-template
-void test_math_float() {
-  typedef Float ff(Float);
-  typedef Float ffi(Float, int);
-  typedef Float ffpi(Float, int*);
-  typedef Float ffl(Float, long);
-  typedef Float fff(Float, Float);
-  typedef Float ffpf(Float, Float*);
-  typedef Float ffld(Float, long double);
-  typedef Float fffpi(Float, Float, int*);
-  typedef Float (Float, Float, Float);
-  typedef bool bf(Float);
-  typedef bool bff(Float, Float);
-  typedef int i_f(Float);
-  typedef long lf(Float);
-  typedef long long llf(Float);
-
-  check();
-  check();
-  check();
-  check();
-  check();
-  check();
-  check

[PATCH] D13604: Fix to allow C conversions on arguments passed to functions with __attribute__((overloadable)) in C

2015-10-09 Thread George Burgess IV via cfe-commits
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

The following is legal in C, and illegal in C++:

```
void *getPtr();
void foo(char *c);
int main() {
foo(getPtr());
}
```

Currently, we only allow C++ conversions in functions with 
`__attribute__((overloadable))` on them, even in C. So, if `foo` from the above 
example had this attribute (and overload(s)), the example would fail to compile 
as C. This patch teaches our overload logic that C conversions are legal if 
we’re overloading something in C.

As a neat side effect, this patch also potentially saves us a few bytes of heap 
each time we call `Sema::CheckAssignmentConstraints(SourceLocation, QualType, 
QualType)`, due to additions that mention `FixRHS`.

http://reviews.llvm.org/D13604

Files:
  include/clang/Sema/Overload.h
  include/clang/Sema/Sema.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  test/Sema/overloadable.c

Index: test/Sema/overloadable.c
===
--- test/Sema/overloadable.c
+++ test/Sema/overloadable.c
@@ -85,3 +85,17 @@
 void after_local_1(int) __attribute__((overloadable)); // expected-error {{conflicting types}}
 void after_local_2(int); // expected-error {{must have the 'overloadable' attribute}}
 void after_local_3(int) __attribute__((overloadable));
+
+// Make sure we allow C-specific conversions in C.
+void conversions() {
+  void foo(char *c) __attribute__((overloadable));
+  void foo(char *c) __attribute__((overloadable, enable_if(c, "nope.jpg")));
+
+  void *ptr;
+  foo(ptr);
+
+  void multi_type(unsigned char *c) __attribute__((overloadable));
+  void multi_type(signed char *c) __attribute__((overloadable));
+  unsigned char *c;
+  multi_type(c);
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -130,7 +130,11 @@
 ICR_Complex_Real_Conversion,
 ICR_Conversion,
 ICR_Conversion,
-ICR_Writeback_Conversion
+ICR_Writeback_Conversion,
+ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
+ // it was omitted by the patch that added
+ // ICK_Zero_Event_Conversion
+ICR_C_Conversion
   };
   return Rank[(int)Kind];
 }
@@ -162,7 +166,9 @@
 "Complex-real conversion",
 "Block Pointer conversion",
 "Transparent Union Conversion",
-"Writeback conversion"
+"Writeback conversion",
+"OpenCL Zero Event Conversion",
+"C specific type conversion"
   };
   return Name[Kind];
 }
@@ -1411,7 +1417,7 @@
 bool InOverloadResolution,
 StandardConversionSequence ,
 bool CStyle);
-  
+
 /// IsStandardConversion - Determines whether there is a standard
 /// conversion sequence (C++ [conv], C++ [over.ics.scs]) from the
 /// expression From to the type ToType. Standard conversion sequences
@@ -1434,12 +1440,10 @@
   SCS.CopyConstructor = nullptr;
 
   // There are no standard conversions for class types in C++, so
-  // abort early. When overloading in C, however, we do permit
+  // abort early. When overloading in C, however, we do permit them.
   if (FromType->isRecordType() || ToType->isRecordType()) {
 if (S.getLangOpts().CPlusPlus)
   return false;
-
-// When we're overloading in C, we allow, as standard conversions,
   }
 
   // The first conversion can be an lvalue-to-rvalue conversion,
@@ -1649,9 +1653,9 @@
 // tryAtomicConversion has updated the standard conversion sequence
 // appropriately.
 return true;
-  } else if (ToType->isEventT() && 
+  } else if (ToType->isEventT() &&
  From->isIntegerConstantExpr(S.getASTContext()) &&
- (From->EvaluateKnownConstInt(S.getASTContext()) == 0)) {
+ From->EvaluateKnownConstInt(S.getASTContext()) == 0) {
 SCS.Second = ICK_Zero_Event_Conversion;
 FromType = ToType;
   } else {
@@ -1690,11 +1694,28 @@
   }
   SCS.setToType(2, FromType);
 
+  if (CanonFrom == CanonTo)
+return true;
+
   // If we have not converted the argument type to the parameter type,
-  // this is a bad conversion sequence.
-  if (CanonFrom != CanonTo)
+  // this is a bad conversion sequence, unless we're resolving an overload in C.
+  if (S.getLangOpts().CPlusPlus || !InOverloadResolution)
 return false;
 
+  ExprResult ER = ExprResult{From};
+  auto Conv = S.CheckSingleAssignmentConstraints(ToType, ER,
+ /*Diagnose=*/false,
+ /*DiagnoseCFAudited=*/false,
+ /*FixRHS=*/false);
+  if (Conv != Sema::Compatible)
+return false;
+
+  SCS.setAllToTypes(ToType);
+  // We need to set all three because we want this conversion to rank terribly,
+  // and 

[PATCH] D13607: [Fix] Make it an error to take the address of (most) enable_if functions.

2015-10-09 Thread George Burgess IV via cfe-commits
george.burgess.iv created this revision.
george.burgess.iv added a reviewer: rsmith.
george.burgess.iv added a subscriber: cfe-commits.

For the following function:

```
int foo(int a) __attribute__((enable_if(a > 0, “”)));
```

The callee should be able to reasonably assume that `foo` will be called iff 
`a` > 0. However, this is currently not the case. One can grab the address of 
`foo` and use the resultant function pointer to call `foo` with any value of 
`a`.

Additionally, given a situation like:

```
int bar(int a) __attribute__((overloadable, enable_if(a > 0, “”)));
int bar(int a) __attribute__((overloadable));
int baz(int a) { return bar(a); }
```

One may only indirectly call `bar` by making a wrapper like `baz`, because 
there’s no way to disambiguate which `bar` you’re referring to in ``.

This patch fixes both of these issues by making it an error to take the address 
of a function with an enable_if attribute, unless the condition in said 
attribute is always true.

http://reviews.llvm.org/D13607

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaCast.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaInit.cpp
  lib/Sema/SemaOverload.cpp
  test/CodeGen/enable_if.c
  test/Sema/enable_if.c
  test/SemaCXX/enable_if.cpp

Index: test/SemaCXX/enable_if.cpp
===
--- test/SemaCXX/enable_if.cpp
+++ test/SemaCXX/enable_if.cpp
@@ -163,3 +163,76 @@
 fn3(sizeof(T) == 1);
   }
 }
+
+namespace FnPtrs {
+  int ovlFoo(int m) __attribute__((enable_if(m > 0, "")));
+  int ovlFoo(int m);
+
+  void test() {
+// Assignment gives us a different code path than declarations, and ``
+// gives us a different code path than `foo`
+int (*p)(int) = ovlFoo;
+int (*p2)(int) = 
+int (*a)(int);
+a = ovlFoo;
+a = 
+  }
+
+  int ovlBar(int) __attribute__((enable_if(true, "")));
+  int ovlBar(int m) __attribute__((enable_if(false, "")));
+  void test2() {
+int (*p)(int) = ovlBar;
+int (*p2)(int) = 
+int (*a)(int);
+a = ovlBar;
+a = 
+  }
+
+  int ovlConflict(int m) __attribute__((enable_if(true, "")));
+  int ovlConflict(int m);
+  void test3() {
+int (*p)(int) = ovlConflict; // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+int (*p2)(int) =  // expected-error{{address of overloaded function 'ovlConflict' is ambiguous}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+int (*a)(int);
+a = ovlConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+a =  // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@191{{candidate function}} expected-note@192{{candidate function}}
+  }
+
+  template 
+  T templated(T m) __attribute__((enable_if(true, ""))) { return T(); }
+  template 
+  T templated(T m) __attribute__((enable_if(false, ""))) { return T(); }
+  void test4() {
+int (*p)(int) = templated;
+int (*p2)(int) = ;
+int (*a)(int);
+a = templated;
+a = ;
+  }
+
+  template 
+  T templatedBar(T m) __attribute__((enable_if(m > 0, ""))) { return T(); }
+  void test5() {
+int (*p)(int) = templatedBar; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
+int (*p2)(int) = ; // expected-error{{address of overloaded function 'templatedBar' does not match required type 'int (int)'}} expected-note@214{{candidate function made ineligible by enable_if}}
+int (*a)(int);
+a = templatedBar; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@214{{candidate function made ineligible by enable_if}}
+a = ; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@214{{candidate function made ineligible by enable_if}}
+  }
+
+  template 
+  T templatedConflict(T m) __attribute__((enable_if(false, ""))) { return T(); }
+  template 
+  T templatedConflict(T m) __attribute__((enable_if(true, ""))) { return T(); }
+  template 
+  T templatedConflict(T m) { return T(); }
+  void test6() {
+// NOTE: The redundant errors are a bug, not a feature. Fix is in the works.
+// :)
+int (*p)(int) = templatedConflict; // expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@224{{candidate function made ineligible by enable_if}} expected-note@226{{candidate function}} expected-note@228{{candidate function}} expected-error{{address of overloaded function 'templatedConflict' is ambiguous}} expected-note@228{{candidate function}} expected-note@226{{candidate function}}
+int (*p0)(int) = ; // expected-error{{address of overloaded function 

Re: [PATCH] D12244: Implement ACLE 2.0 macros of chapters 6.4 and 6.5 for [ARM] and [Aarch64] targets

2015-10-09 Thread Alexandros Lamprineas via cfe-commits
labrinea closed this revision.
labrinea added a comment.

committed as r246768


http://reviews.llvm.org/D12244



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


Re: r249721 - When mapping no_sanitize_* attributes to no_sanitize attributes, handle GNU-style formatting that involves prefix and suffix underscores. Cleans up other usages of similar functionality.

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 8:53 AM, Aaron Ballman  wrote:
> On Thu, Oct 8, 2015 at 6:10 PM, Richard Smith  wrote:
>> On Thu, Oct 8, 2015 at 2:59 PM, Adrian Zgorzalek  wrote:
>>>
>>> Same story:
>>>  warning: 'ownership_takes' attribute only applies to functions
>>> [-Wignored-attributes]
>>> __attribute__((ownership_takes(__))) void f();
>>>^
>>
>>
>> Oh, I see, you're building in C, and the diagnostic here is broken (we give
>> the "only applies to functions" diagnostic when it's applied to a function
>> without a prototype). =( Aaron, can I tempt you to fix that? ;)
>
> I'll look into that one. :-)

I've corrected the issue, but am not overly enamored with the
diagnostic wording. If you can think of something better, please let
me know.

~Aaron

>
> ~Aaron
>
>>
>> Try this one:
>>
>> __attribute__((ownership_takes(__, 1))) void f(void*);
>>>
>>> On Oct 8, 2015, at 2:52 PM, Richard Smith  wrote:
>>>
>>> On Thu, Oct 8, 2015 at 2:45 PM, Adrian Zgorzalek  wrote:


 On Oct 8, 2015, at 2:17 PM, Richard Smith  wrote:

 On Thu, Oct 8, 2015 at 2:10 PM, Adrian Zgorzalek via cfe-commits
  wrote:
>
> You are right, my bad, I thought this if covers all the cases, but 
> part could be empty.
>
> Here is the fix


 Please add a testcase ("__attribute__((ownership_takes(__))) void f();"
 maybe?).

 I tried different attributes but none of them triggers the assert though.
 They all spit out warning:
 warning: 'ownership_takes' attribute only applies to functions
 [-Wignored-attributes]
 __attribute__((ownership_takes(__))) f();
^
>>>
>>>
>>> You missed the 'void'.
>>>

 Do you have some other idea?



 The '&&' should go at the end of the previous line.

> Adrian
> > On Oct 8, 2015, at 1:52 PM, Aaron Ballman 
> > wrote:
> >
> > On Thu, Oct 8, 2015 at 4:49 PM, Richard Smith 
> > wrote:
> >> On Thu, Oct 8, 2015 at 1:21 PM, Aaron Ballman
> >> 
> >> wrote:
> >>>
> >>> On Thu, Oct 8, 2015 at 4:16 PM, Richard Smith
> >>> 
> >>> wrote:
>  On Thu, Oct 8, 2015 at 12:24 PM, Aaron Ballman via cfe-commits
>   wrote:
> >
> > Author: aaronballman
> > Date: Thu Oct  8 14:24:08 2015
> > New Revision: 249721
> >
> > URL:
> > https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project?rev%3D249721%26view%3Drev=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A=ZpIyPFH5RmN0EBF%2B6Om2Hg%3D%3D%0A=kMsJztGqfQof%2FUicfGEXM78GJV6jd7CTOxlypvgU10A%3D%0A=8862f3210cdb7661e90a0d8588334d3e1cf64e92851d05bbcd2b159daf05c7dd
> > Log:
> > When mapping no_sanitize_* attributes to no_sanitize attributes,
> > handle
> > GNU-style formatting that involves prefix and suffix underscores.
> > Cleans up
> > other usages of similar functionality.
> >
> > Patch by Adrian Zgorzalek!
> >
> > Modified:
> >cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> >cfe/trunk/test/SemaCXX/attr-no-sanitize-address.cpp
> >cfe/trunk/test/SemaCXX/attr-no-sanitize-memory.cpp
> >cfe/trunk/test/SemaCXX/attr-no-sanitize-thread.cpp
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > URL:
> >
> >
> > https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev%3D249721%26r1%3D249720%26r2%3D249721%26view%3Ddiff=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A=ZpIyPFH5RmN0EBF%2B6Om2Hg%3D%3D%0A=kMsJztGqfQof%2FUicfGEXM78GJV6jd7CTOxlypvgU10A%3D%0A=7dae8eb5cffae4493f0a6c26033810564fd7b688297fc93106a3b980f76cdd9f
> >
> >
> >
> > ==
> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Oct  8 14:24:08 2015
> > @@ -1308,6 +1308,17 @@ void Sema::AddAssumeAlignedAttr(SourceRa
> > AssumeAlignedAttr(AttrRange, Context, E, OE,
> > SpellingListIndex));
> > }
> >
> > +/// Normalize the attribute, __foo__ becomes foo.
> > +/// Returns true if normalization was applied.
> > +static bool normalizeName(StringRef ) {
> > +  if (AttrName.startswith("__") && AttrName.endswith("__")) {
> > +assert(AttrName.size() > 4 && "Name too short");
> 
> 
>  This assert will fire on the strings __, ___, and , which are
>  valid
>  in
>  some of the below 

Re: [PATCH] D13099: [Analyzer] Don’t invalidate CXXThis when conservatively evaluating const methods (PR 21606)

2015-10-09 Thread Anna Zaks via cfe-commits
zaks.anna accepted this revision.
This revision is now accepted and ready to land.


Comment at: lib/StaticAnalyzer/Core/CallEvent.cpp:419
@@ +418,3 @@
+const Expr *Ex = getCXXThisExpr();
+while (isa(Ex)) {
+  Ex = cast(Ex)->getSubExpr();

Use IgnoreParenImpCasts()?


http://reviews.llvm.org/D13099



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


r249846 - Fix VFS GCC unittest on Windows

2015-10-09 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Fri Oct  9 11:48:52 2015
New Revision: 249846

URL: http://llvm.org/viewvc/llvm-project?rev=249846=rev
Log:
Fix VFS GCC unittest on Windows

Modified:
cfe/trunk/unittests/Driver/ToolChainTest.cpp

Modified: cfe/trunk/unittests/Driver/ToolChainTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Driver/ToolChainTest.cpp?rev=249846=249845=249846=diff
==
--- cfe/trunk/unittests/Driver/ToolChainTest.cpp (original)
+++ cfe/trunk/unittests/Driver/ToolChainTest.cpp Fri Oct  9 11:48:52 2015
@@ -66,6 +66,9 @@ TEST(ToolChainTest, VFSGCCInstallation)
 llvm::raw_string_ostream OS(S);
 C->getDefaultToolChain().printVerboseInfo(OS);
   }
+#if LLVM_ON_WIN32
+  std::replace(S.begin(), S.end(), '\\', '/');
+#endif
   EXPECT_EQ(
   "Found candidate GCC installation: "
   "/usr/lib/gcc/arm-linux-gnueabihf/4.6.3\n"


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


Re: r249721 - When mapping no_sanitize_* attributes to no_sanitize attributes, handle GNU-style formatting that involves prefix and suffix underscores. Cleans up other usages of similar functionality.

2015-10-09 Thread Aaron Ballman via cfe-commits
On Thu, Oct 8, 2015 at 6:51 PM, Adrian Zgorzalek  wrote:
> Moved the test.
> Feel free to commit it for me :)

Thank you for the patch! I've commit it in r249833.

~Aaron

>
>
> On Oct 8, 2015, at 3:29 PM, Richard Smith  wrote:
>
> Please add the test to some existing test file for the ownership_takes
> attribute, such as test/Sema/attr-ownership.c. Otherwise, LGTM.
>
> On Thu, Oct 8, 2015 at 3:25 PM, Adrian Zgorzalek  wrote:
>
> Yay! It worked, thank you!
>
>
> On Oct 8, 2015, at 3:10 PM, Richard Smith  wrote:
>
> On Thu, Oct 8, 2015 at 2:59 PM, Adrian Zgorzalek  wrote:
>
> Same story:
>  warning: 'ownership_takes' attribute only applies to functions
> [-Wignored-attributes]
> __attribute__((ownership_takes(__))) void f();
>^
>
>
> Oh, I see, you're building in C, and the diagnostic here is broken (we give
> the "only applies to functions" diagnostic when it's applied to a function
> without a prototype). =( Aaron, can I tempt you to fix that? ;)
>
> Try this one:
>
> __attribute__((ownership_takes(__, 1))) void f(void*);
>
> On Oct 8, 2015, at 2:52 PM, Richard Smith  wrote:
>
> On Thu, Oct 8, 2015 at 2:45 PM, Adrian Zgorzalek  wrote:
>
>
> On Oct 8, 2015, at 2:17 PM, Richard Smith  wrote:
>
> On Thu, Oct 8, 2015 at 2:10 PM, Adrian Zgorzalek via cfe-commits
>  wrote:
>
> You are right, my bad, I thought this if covers all the cases, but 
> part could be empty.
>
> Here is the fix
>
>
> Please add a testcase ("__attribute__((ownership_takes(__))) void f();"
> maybe?).
>
> I tried different attributes but none of them triggers the assert though.
> They all spit out warning:
> warning: 'ownership_takes' attribute only applies to functions
> [-Wignored-attributes]
> __attribute__((ownership_takes(__))) f();
>^
>
>
> You missed the 'void'.
>
>
> Do you have some other idea?
>
>
>
> The '&&' should go at the end of the previous line.
>
> Adrian
>> On Oct 8, 2015, at 1:52 PM, Aaron Ballman  wrote:
>>
>> On Thu, Oct 8, 2015 at 4:49 PM, Richard Smith 
>> wrote:
>>> On Thu, Oct 8, 2015 at 1:21 PM, Aaron Ballman 
>>> wrote:

 On Thu, Oct 8, 2015 at 4:16 PM, Richard Smith 
 wrote:
> On Thu, Oct 8, 2015 at 12:24 PM, Aaron Ballman via cfe-commits
>  wrote:
>>
>> Author: aaronballman
>> Date: Thu Oct  8 14:24:08 2015
>> New Revision: 249721
>>
>> URL:
>> https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project?rev%3D249721%26view%3Drev=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A=ZpIyPFH5RmN0EBF%2B6Om2Hg%3D%3D%0A=kMsJztGqfQof%2FUicfGEXM78GJV6jd7CTOxlypvgU10A%3D%0A=8862f3210cdb7661e90a0d8588334d3e1cf64e92851d05bbcd2b159daf05c7dd
>> Log:
>> When mapping no_sanitize_* attributes to no_sanitize attributes,
>> handle
>> GNU-style formatting that involves prefix and suffix underscores.
>> Cleans up
>> other usages of similar functionality.
>>
>> Patch by Adrian Zgorzalek!
>>
>> Modified:
>>cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>>cfe/trunk/test/SemaCXX/attr-no-sanitize-address.cpp
>>cfe/trunk/test/SemaCXX/attr-no-sanitize-memory.cpp
>>cfe/trunk/test/SemaCXX/attr-no-sanitize-thread.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> URL:
>>
>>
>> https://urldefense.proofpoint.com/v1/url?u=http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev%3D249721%26r1%3D249720%26r2%3D249721%26view%3Ddiff=ZVNjlDMF0FElm4dQtryO4A%3D%3D%0A=ZpIyPFH5RmN0EBF%2B6Om2Hg%3D%3D%0A=kMsJztGqfQof%2FUicfGEXM78GJV6jd7CTOxlypvgU10A%3D%0A=7dae8eb5cffae4493f0a6c26033810564fd7b688297fc93106a3b980f76cdd9f
>>
>>
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Oct  8 14:24:08 2015
>> @@ -1308,6 +1308,17 @@ void Sema::AddAssumeAlignedAttr(SourceRa
>> AssumeAlignedAttr(AttrRange, Context, E, OE,
>> SpellingListIndex));
>> }
>>
>> +/// Normalize the attribute, __foo__ becomes foo.
>> +/// Returns true if normalization was applied.
>> +static bool normalizeName(StringRef ) {
>> +  if (AttrName.startswith("__") && AttrName.endswith("__")) {
>> +assert(AttrName.size() > 4 && "Name too short");
>
>
> This assert will fire on the strings __, ___, and , which are valid
> in
> some of the below cases.

 That assert won't fire on anything but  because it's &&, not ||.
>>>
>>>
>>> I disagree. __ starts with __ and ends with __. The right thing to do
>>> here
>>> is remove the assert and put back the 

[PATCH] D13590: Support every kind of initialization.

2015-10-09 Thread Angel Garcia via cfe-commits
angelgarcia created this revision.
angelgarcia added a reviewer: klimek.
angelgarcia added subscribers: alexfh, cfe-commits.

modernize-make-unique now correctly supports the different kinds of list 
initialization.

http://reviews.llvm.org/D13590

Files:
  clang-tidy/modernize/MakeUniqueCheck.cpp
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -34,21 +34,31 @@
   Derived(int, int);
 };
 
-struct Pair {
+struct APair {
   int a, b;
 };
 
+struct DPair {
+  DPair() : a(0), b(0) {}
+  DPair(int x, int y) : a(y), b(x) {}
+  int a, b;
+};
+
+struct Empty {};
+
 template using unique_ptr_ = std::unique_ptr;
 
+void *operator new(unsigned long Count, void *Ptr);
+
 int g(std::unique_ptr P);
 
 std::unique_ptr getPointer() {
   return std::unique_ptr(new Base);
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: use std::make_unique instead
   // CHECK-FIXES: return std::make_unique();
 }
 
-void f() {
+void basic() {
   std::unique_ptr P1 = std::unique_ptr(new int());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: use std::make_unique instead [modernize-make-unique]
   // CHECK-FIXES: std::unique_ptr P1 = std::make_unique();
@@ -78,24 +88,76 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::make_unique instead
   // CHECK-FIXES: int T = g(std::make_unique());
 
-  // Arguments are correctly handled.
-  std::unique_ptr Pbase = std::unique_ptr(new Base(5, T));
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: use std::make_unique instead
-  // CHECK-FIXES: std::unique_ptr Pbase = std::make_unique(5, T);
-
-  // Works with init lists.
-  std::unique_ptr Ppair = std::unique_ptr(new Pair{T, 1});
-  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: use std::make_unique instead
-  // CHECK-FIXES: std::unique_ptr Ppair = std::make_unique({T, 1});
-
   // Only replace if the type in the template is the same than the type returned
   // by the new operator.
   auto Pderived = std::unique_ptr(new Derived());
 
   // The pointer is returned by the function, nothing to do.
   std::unique_ptr RetPtr = getPointer();
 
-  // Aliases.
+  // This emulates std::move.
+  std::unique_ptr Move = static_cast(P1);
+
+  // Placemenet arguments should not be removed.
+  int *PInt = new int;
+  std::unique_ptr Placement = std::unique_ptr(new (PInt) int{3});
+}
+
+void initialization(int T, Base b) {
+  // Test different kinds of initialization of the pointee.
+
+  // Direct initialization with parenthesis.
+  std::unique_ptr PDir1 = std::unique_ptr(new DPair(1, T));
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir1 = std::make_unique(1, T);
+
+  // Direct initialization with braces.
+  std::unique_ptr PDir2 = std::unique_ptr(new DPair{2, T});
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir2 = std::make_unique(2, T);
+
+  // Aggregate initialization.
+  std::unique_ptr PAggr = std::unique_ptr(new APair{T, 1});
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PAggr = std::make_unique(APair{T, 1});
+
+
+  // Test different kinds of initialization of the pointee, when the unique_ptr
+  // is initialized with braces.
+
+  // Direct initialization with parenthesis.
+  std::unique_ptr PDir3 = std::unique_ptr{new DPair(3, T)};
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir3 = std::make_unique(3, T);
+
+  // Direct initialization with braces.
+  std::unique_ptr PDir4 = std::unique_ptr{new DPair{4, T}};
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir4 = std::make_unique(4, T);
+
+  // Aggregate initialization.
+  std::unique_ptr PAggr2 = std::unique_ptr{new APair{T, 2}};
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PAggr2 = std::make_unique(APair{T, 2});
+
+
+  // Direct initialization with parenthesis, without arguments.
+  std::unique_ptr PDir5 = std::unique_ptr(new DPair());
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir5 = std::make_unique();
+
+  // Direct initialization with braces, without arguments.
+  std::unique_ptr PDir6 = std::unique_ptr(new DPair{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PDir6 = std::make_unique();
+
+  // Aggregate initialization without arguments.
+  std::unique_ptr PEmpty = std::unique_ptr(new Empty{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{});
+}

r249833 - Amending r249721 to properly handle pathological attribute-related names like __ and ____.

2015-10-09 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Fri Oct  9 08:53:24 2015
New Revision: 249833

URL: http://llvm.org/viewvc/llvm-project?rev=249833=rev
Log:
Amending r249721 to properly handle pathological attribute-related names like 
__ and .

Patch by Adrian Zgorzalek!

Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/Sema/attr-ownership.c

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=249833=249832=249833=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri Oct  9 08:53:24 2015
@@ -1311,8 +1311,8 @@ void Sema::AddAssumeAlignedAttr(SourceRa
 /// Normalize the attribute, __foo__ becomes foo.
 /// Returns true if normalization was applied.
 static bool normalizeName(StringRef ) {
-  if (AttrName.startswith("__") && AttrName.endswith("__")) {
-assert(AttrName.size() > 4 && "Name too short");
+  if (AttrName.size() > 4 && AttrName.startswith("__") &&
+  AttrName.endswith("__")) {
 AttrName = AttrName.drop_front(2).drop_back(2);
 return true;
   }

Modified: cfe/trunk/test/Sema/attr-ownership.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-ownership.c?rev=249833=249832=249833=diff
==
--- cfe/trunk/test/Sema/attr-ownership.c (original)
+++ cfe/trunk/test/Sema/attr-ownership.c Fri Oct  9 08:53:24 2015
@@ -19,6 +19,7 @@ void f13(int *i, int *j) __attribute__((
 void f14(int i, int j, int *k) __attribute__((ownership_holds(foo, 3))) 
__attribute__((ownership_takes(foo, 3)));  // expected-error 
{{'ownership_holds' and 'ownership_takes' attributes are not compatible}}
 
 void f15(int, int)
-  __attribute__((ownership_returns(foo, 1)))  // expected-note {{declared with 
index 1 here}}
-  __attribute__((ownership_returns(foo, 2))); // expected-error 
{{'ownership_returns' attribute index does not match; here it is 2}}
-void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) 
__attribute__((ownership_holds(foo, 1))); // OK, same index
+  __attribute__((ownership_returns(foo, 1)))  // expected-note {{declared with 
index 1 here}}
+  __attribute__((ownership_returns(foo, 2))); // expected-error 
{{'ownership_returns' attribute index does not match; here it is 2}}
+void f16(int *i, int *j) __attribute__((ownership_holds(foo, 1))) 
__attribute__((ownership_holds(foo, 1))); // OK, same index
+void f17(void*) __attribute__((ownership_takes(__, 1)));


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


r249830 - [VFS] Just normalize away .. and . in paths for in-memory file systems.

2015-10-09 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct  9 08:03:22 2015
New Revision: 249830

URL: http://llvm.org/viewvc/llvm-project?rev=249830=rev
Log:
[VFS] Just normalize away .. and . in paths for in-memory file systems.

This simplifies the code and gets us support for .. for free.

Modified:
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/VirtualFileSystem.cpp
cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp

Modified: cfe/trunk/include/clang/Basic/VirtualFileSystem.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/VirtualFileSystem.h?rev=249830=249829=249830=diff
==
--- cfe/trunk/include/clang/Basic/VirtualFileSystem.h (original)
+++ cfe/trunk/include/clang/Basic/VirtualFileSystem.h Fri Oct  9 08:03:22 2015
@@ -283,7 +283,7 @@ public:
   /// Add a buffer to the VFS with a path. The VFS does not own the buffer.
   void addFileNoOwn(const Twine , time_t ModificationTime,
 llvm::MemoryBuffer *Buffer);
-  StringRef toString() const;
+  std::string toString() const;
 
   llvm::ErrorOr status(const Twine ) override;
   llvm::ErrorOr

Modified: cfe/trunk/lib/Basic/VirtualFileSystem.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/VirtualFileSystem.cpp?rev=249830=249829=249830=diff
==
--- cfe/trunk/lib/Basic/VirtualFileSystem.cpp (original)
+++ cfe/trunk/lib/Basic/VirtualFileSystem.cpp Fri Oct  9 08:03:22 2015
@@ -10,6 +10,7 @@
 
//===--===//
 
 #include "clang/Basic/VirtualFileSystem.h"
+#include "clang/Basic/FileManager.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
@@ -482,7 +483,7 @@ InMemoryFileSystem::InMemoryFileSystem()
 
 InMemoryFileSystem::~InMemoryFileSystem() {}
 
-StringRef InMemoryFileSystem::toString() const {
+std::string InMemoryFileSystem::toString() const {
   return Root->toString(/*Indent=*/0);
 }
 
@@ -496,17 +497,14 @@ void InMemoryFileSystem::addFile(const T
   assert(!EC);
   (void)EC;
 
+  FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+  if (Path.empty())
+return;
+
   detail::InMemoryDirectory *Dir = Root.get();
   auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
   while (true) {
 StringRef Name = *I;
-// Skip over ".".
-// FIXME: Also handle "..".
-if (Name == ".") {
-  ++I;
-  continue;
-}
-
 detail::InMemoryNode *Node = Dir->getChild(Name);
 ++I;
 if (!Node) {
@@ -558,17 +556,12 @@ lookupInMemoryNode(const InMemoryFileSys
   assert(!EC);
   (void)EC;
 
+  FileManager::removeDotPaths(Path, /*RemoveDotDot=*/true);
+  if (Path.empty())
+return Dir;
+
   auto I = llvm::sys::path::begin(Path), E = llvm::sys::path::end(Path);
   while (true) {
-// Skip over ".".
-// FIXME: Also handle "..".
-if (*I == ".") {
-  ++I;
-  if (I == E)
-return Dir;
-  continue;
-}
-
 detail::InMemoryNode *Node = Dir->getChild(*I);
 ++I;
 if (!Node)

Modified: cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp?rev=249830=249829=249830=diff
==
--- cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp (original)
+++ cfe/trunk/unittests/Basic/VirtualFileSystemTest.cpp Fri Oct  9 08:03:22 2015
@@ -569,6 +569,7 @@ TEST_F(InMemoryFileSystemTest, OverlayFi
 TEST_F(InMemoryFileSystemTest, OpenFileForRead) {
   FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
   FS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c"));
+  FS.addFile("./d/../d", 0, MemoryBuffer::getMemBuffer("d"));
   auto File = FS.openFileForRead("/a");
   ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
   File = FS.openFileForRead("/a"); // Open again.
@@ -581,6 +582,8 @@ TEST_F(InMemoryFileSystemTest, OpenFileF
   ASSERT_EQ(File.getError(), errc::no_such_file_or_directory) << FS.toString();
   File = FS.openFileForRead("./c");
   ASSERT_EQ("c", (*(*File)->getBuffer("ignored"))->getBuffer());
+  File = FS.openFileForRead("e/../d");
+  ASSERT_EQ("d", (*(*File)->getBuffer("ignored"))->getBuffer());
 }
 
 TEST_F(InMemoryFileSystemTest, DirectoryIteration) {


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


r249831 - [VFS] Wire up driver VFS through tooling.

2015-10-09 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Fri Oct  9 08:03:25 2015
New Revision: 249831

URL: http://llvm.org/viewvc/llvm-project?rev=249831=rev
Log:
[VFS] Wire up driver VFS through tooling.

Sadly I don't currently have a way to tests this as the driver is always
initialized with the default triple and finding system headers is system
specific.

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

Modified: cfe/trunk/lib/Tooling/Tooling.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=249831=249830=249831=diff
==
--- cfe/trunk/lib/Tooling/Tooling.cpp (original)
+++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Oct  9 08:03:25 2015
@@ -46,10 +46,11 @@ FrontendActionFactory::~FrontendActionFa
 // it to be based on the same framework.
 
 /// \brief Builds a clang driver initialized for running clang tools.
-static clang::driver::Driver *newDriver(clang::DiagnosticsEngine *Diagnostics,
-const char *BinaryName) {
+static clang::driver::Driver *newDriver(
+clang::DiagnosticsEngine *Diagnostics, const char *BinaryName,
+IntrusiveRefCntPtr VFS) {
   clang::driver::Driver *CompilerDriver = new clang::driver::Driver(
-  BinaryName, llvm::sys::getDefaultTargetTriple(), *Diagnostics);
+  BinaryName, llvm::sys::getDefaultTargetTriple(), *Diagnostics, VFS);
   CompilerDriver->setTitle("clang_based_tool");
   return CompilerDriver;
 }
@@ -238,7 +239,7 @@ bool ToolInvocation::run() {
   DiagConsumer ? DiagConsumer : , false);
 
   const std::unique_ptr Driver(
-  newDriver(, BinaryName));
+  newDriver(, BinaryName, Files->getVirtualFileSystem()));
   // Since the input might only be virtual, don't check whether it exists.
   Driver->setCheckInputsExist(false);
   const std::unique_ptr Compilation(


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


Re: [PATCH] D12821: Allow for C's "writing off the end" idiom in __builtin_object_size

2015-10-09 Thread George Burgess IV via cfe-commits
george.burgess.iv updated this revision to Diff 36972.
george.burgess.iv marked 4 inline comments as done.
george.burgess.iv added a comment.

Addressed all feedback.

Also, updated object-size tests to use CHECK-LABEL instead of CHECK, because 
yay I’m learning how to do things properly.


http://reviews.llvm.org/D12821

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGen/object-size.c
  test/CodeGen/object-size.cpp

Index: test/CodeGen/object-size.cpp
===
--- test/CodeGen/object-size.cpp
+++ test/CodeGen/object-size.cpp
@@ -28,3 +28,37 @@
   // CHECK: store i32 4
   gi = __builtin_object_size((char*)(B*), 0);
 }
+
+// CHECK-LABEL: define void @_Z5test2v()
+void test2() {
+  struct A { char buf[16]; };
+  struct B : A {};
+  struct C { int i; B bs[1]; } *c;
+
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size(>bs[0], 0);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size(>bs[0], 1);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 true)
+  gi = __builtin_object_size(>bs[0], 2);
+  // CHECK: store i32 16
+  gi = __builtin_object_size(>bs[0], 3);
+
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size((A*)>bs[0], 0);
+  // CHECK: store i32 16
+  gi = __builtin_object_size((A*)>bs[0], 1);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 true)
+  gi = __builtin_object_size((A*)>bs[0], 2);
+  // CHECK: store i32 16
+  gi = __builtin_object_size((A*)>bs[0], 3);
+
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
+  gi = __builtin_object_size(>bs[0].buf[0], 0);
+  // CHECK: store i32 16
+  gi = __builtin_object_size(>bs[0].buf[0], 1);
+  // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 true)
+  gi = __builtin_object_size(>bs[0].buf[0], 2);
+  // CHECK: store i32 16
+  gi = __builtin_object_size(>bs[0].buf[0], 3);
+}
Index: test/CodeGen/object-size.c
===
--- test/CodeGen/object-size.c
+++ test/CodeGen/object-size.c
@@ -127,7 +127,7 @@
   strcpy(gp += 1, "Hi there");
 }
 
-// CHECK: @test17
+// CHECK-LABEL: @test17
 void test17() {
   // CHECK: store i32 -1
   gi = __builtin_object_size(gp++, 0);
@@ -139,15 +139,15 @@
   gi = __builtin_object_size(gp++, 3);
 }
 
-// CHECK: @test18
+// CHECK-LABEL: @test18
 unsigned test18(int cond) {
   int a[4], b[4];
   // CHECK: phi i32*
   // CHECK: call i64 @llvm.objectsize.i64
   return __builtin_object_size(cond ? a : b, 0);
 }
 
-// CHECK: @test19
+// CHECK-LABEL: @test19
 void test19() {
   struct {
 int a, b;
@@ -172,7 +172,7 @@
   gi = __builtin_object_size(, 3);
 }
 
-// CHECK: @test20
+// CHECK-LABEL: @test20
 void test20() {
   struct { int t[10]; } t[10];
 
@@ -186,7 +186,7 @@
   gi = __builtin_object_size([0].t[5], 3);
 }
 
-// CHECK: @test21
+// CHECK-LABEL: @test21
 void test21() {
   struct { int t; } t;
 
@@ -209,7 +209,7 @@
   gi = __builtin_object_size( + 1, 3);
 }
 
-// CHECK: @test22
+// CHECK-LABEL: @test22
 void test22() {
   struct { int t[10]; } t[10];
 
@@ -252,7 +252,7 @@
 
 struct Test23Ty { int a; int t[10]; };
 
-// CHECK: @test23
+// CHECK-LABEL: @test23
 void test23(struct Test23Ty *p) {
   // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
   gi = __builtin_object_size(p, 0);
@@ -285,7 +285,7 @@
 }
 
 // PR24493 -- ICE if __builtin_object_size called with NULL and (Type & 1) != 0
-// CHECK: @test24
+// CHECK-LABEL: @test24
 void test24() {
   // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* {{.*}}, i1 false)
   gi = __builtin_object_size((void*)0, 0);
@@ -299,7 +299,7 @@
   gi = __builtin_object_size((void*)0, 3);
 }
 
-// CHECK: @test25
+// CHECK-LABEL: @test25
 void test25() {
   // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* {{.*}}, i1 false)
   gi = __builtin_object_size((void*)0x1000, 0);
@@ -324,7 +324,7 @@
   gi = __builtin_object_size((void*)0 + 0x1000, 3);
 }
 
-// CHECK: @test26
+// CHECK-LABEL: @test26
 void test26() {
   struct { int v[10]; } t[10];
 
@@ -340,7 +340,7 @@
 
 struct Test27IncompleteTy;
 
-// CHECK: @test27
+// CHECK-LABEL: @test27
 void test27(struct Test27IncompleteTy *t) {
   // CHECK: call i64 @llvm.objectsize.i64.p0i8(i8* %{{.*}}, i1 false)
   gi = __builtin_object_size(t, 0);
@@ -367,7 +367,7 @@
 
 // The intent of this test is to ensure that __builtin_object_size treats ``
 // and `(T*)` identically, when used as the pointer argument.
-// CHECK: @test28
+// CHECK-LABEL: @test28
 void test28() {
   struct { int v[10]; } t[10];
 
@@ -391,3 +391,129 @@
   gi = __builtin_object_size(addCasts([1].v[1]), 3);
 #undef addCasts
 }
+
+struct DynStructVar {
+  char fst[16];
+  char snd[];
+};
+
+struct DynStruct0 {
+  char fst[16];
+  char snd[0];
+};
+
+struct DynStruct1 {
+  char fst[16];
+  char snd[1];
+};
+
+struct StaticStruct {
+  char fst[16];
+  char snd[2];
+};

r249872 - Fix whitespace, 80-column violations, embedded tabs for the

2015-10-09 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Fri Oct  9 13:39:59 2015
New Revision: 249872

URL: http://llvm.org/viewvc/llvm-project?rev=249872=rev
Log:
Fix whitespace, 80-column violations, embedded tabs for the
TargetInfo class.

Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=249872=249871=249872=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct  9 13:39:59 2015
@@ -108,9 +108,9 @@ public:
   virtual ~TargetInfo();
 
   /// \brief Retrieve the target options.
-  TargetOptions () const { 
+  TargetOptions () const {
 assert(TargetOpts && "Missing target options");
-return *TargetOpts; 
+return *TargetOpts;
   }
 
   ///=== Target Data Type Query Methods 
---===//
@@ -316,7 +316,9 @@ public:
   unsigned getLongLongAlign() const { return LongLongAlign; }
 
   /// \brief Determine whether the __int128 type is supported on this target.
-  virtual bool hasInt128Type() const { return getPointerWidth(0) >= 64; } // 
FIXME
+  virtual bool hasInt128Type() const {
+return getPointerWidth(0) >= 64;
+  } // FIXME
 
   /// \brief Return the alignment that is suitable for storing any
   /// object with a fundamental alignment requirement.
@@ -632,7 +634,7 @@ public:
 }
 
 /// \brief Indicate that this is an input operand that is tied to
-/// the specified output operand. 
+/// the specified output operand.
 ///
 /// Copy over the various constraint information from the output.
 void setTiedOperand(unsigned N, ConstraintInfo ) {
@@ -814,7 +816,7 @@ public:
   // \brief Validate the contents of the __builtin_cpu_supports(const char*)
   // argument.
   virtual bool validateCpuSupports(StringRef Name) const { return false; }
-  
+
   // \brief Returns maximal number of args passed in registers.
   unsigned getRegParmMax() const {
 assert(RegParmMax < 7 && "RegParmMax value is larger than AST can handle");
@@ -898,7 +900,7 @@ public:
   };
 
   /// \brief Determines whether a given calling convention is valid for the
-  /// target. A calling convention can either be accepted, produce a warning 
+  /// target. A calling convention can either be accepted, produce a warning
   /// and be substituted with the default calling convention, or (someday)
   /// produce an error (such as using thiscall on a non-instance function).
   virtual CallingConvCheckResult checkCallingConvention(CallingConv CC) const {

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=249872=249871=249872=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Oct  9 13:39:59 2015
@@ -287,9 +287,9 @@ void TargetInfo::adjust(const LangOption
 LongLongWidth = LongLongAlign = 128;
 HalfWidth = HalfAlign = 16;
 FloatWidth = FloatAlign = 32;
-
-// Embedded 32-bit targets (OpenCL EP) might have double C type 
-// defined as float. Let's not override this as it might lead 
+
+// Embedded 32-bit targets (OpenCL EP) might have double C type
+// defined as float. Let's not override this as it might lead
 // to generating illegal code that uses 64bit doubles.
 if (DoubleWidth != FloatWidth) {
   DoubleWidth = DoubleAlign = 64;
@@ -339,7 +339,7 @@ static StringRef removeGCCRegisterPrefix
 /// Sema.
 bool TargetInfo::isValidClobber(StringRef Name) const {
   return (isValidGCCRegisterName(Name) ||
- Name == "memory" || Name == "cc");
+  Name == "memory" || Name == "cc");
 }
 
 /// isValidGCCRegisterName - Returns whether the passed in string
@@ -379,11 +379,11 @@ bool TargetInfo::isValidGCCRegisterName(
   for (unsigned i = 0; i < NumAddlNames; i++)
 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
   if (!AddlNames[i].Names[j])
-   break;
+break;
   // Make sure the register that the additional name is for is within
   // the bounds of the register names from above.
   if (AddlNames[i].Names[j] == Name && AddlNames[i].RegNum < NumNames)
-   return true;
+return true;
   }
 
   // Now check aliases.
@@ -432,11 +432,11 @@ TargetInfo::getNormalizedGCCRegisterName
   for (unsigned i = 0; i < NumAddlNames; i++)
 for (unsigned j = 0; j < llvm::array_lengthof(AddlNames[i].Names); j++) {
   if (!AddlNames[i].Names[j])
-   break;
+break;
   // Make sure the register that the additional name is for is within
   // the bounds of the register names from above.
   if (AddlNames[i].Names[j] == Name && 

r249871 - constify the feature vector going into initFeatureMap as it shouldn't

2015-10-09 Thread Eric Christopher via cfe-commits
Author: echristo
Date: Fri Oct  9 13:39:55 2015
New Revision: 249871

URL: http://llvm.org/viewvc/llvm-project?rev=249871=rev
Log:
constify the feature vector going into initFeatureMap as it shouldn't
change the set of features.

Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=249871=249870=249871=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Oct  9 13:39:55 2015
@@ -753,7 +753,7 @@ public:
   /// \return False on error (invalid features).
   virtual bool initFeatureMap(llvm::StringMap ,
   DiagnosticsEngine , StringRef CPU,
-  std::vector ) const;
+  const std::vector ) 
const;
 
   /// \brief Get the ABI currently in use.
   virtual StringRef getABI() const { return StringRef(); }

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=249871=249870=249871=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Oct  9 13:39:55 2015
@@ -312,9 +312,9 @@ void TargetInfo::adjust(const LangOption
   }
 }
 
-bool TargetInfo::initFeatureMap(llvm::StringMap ,
-DiagnosticsEngine , StringRef CPU,
-std::vector ) const {
+bool TargetInfo::initFeatureMap(
+llvm::StringMap , DiagnosticsEngine , StringRef CPU,
+const std::vector ) const {
   for (const auto  : FeatureVec) {
 const char *Name = F.c_str();
 // Apply the feature via the target.

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=249871=249870=249871=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Oct  9 13:39:55 2015
@@ -887,9 +887,10 @@ public:
   void getTargetDefines(const LangOptions ,
 MacroBuilder ) const override;
 
-  bool initFeatureMap(llvm::StringMap , DiagnosticsEngine 
,
-  StringRef CPU,
-  std::vector ) const override;
+  bool
+  initFeatureMap(llvm::StringMap , DiagnosticsEngine ,
+ StringRef CPU,
+ const std::vector ) const override;
 
   bool handleTargetFeatures(std::vector ,
 DiagnosticsEngine ) override;
@@ -1253,7 +1254,7 @@ void PPCTargetInfo::getTargetDefines(con
 // go ahead and error since the customer has expressed a somewhat incompatible
 // set of options.
 static bool ppcUserFeaturesCheck(DiagnosticsEngine ,
- std::vector ) {
+ const std::vector ) {
 
   if (std::find(FeaturesVec.begin(), FeaturesVec.end(), "-vsx") !=
   FeaturesVec.end()) {
@@ -1275,9 +1276,9 @@ static bool ppcUserFeaturesCheck(Diagnos
   return true;
 }
 
-bool PPCTargetInfo::initFeatureMap(llvm::StringMap ,
-   DiagnosticsEngine , StringRef CPU,
-   std::vector ) 
const {
+bool PPCTargetInfo::initFeatureMap(
+llvm::StringMap , DiagnosticsEngine , StringRef CPU,
+const std::vector ) const {
   Features["altivec"] = llvm::StringSwitch(CPU)
 .Case("7400", true)
 .Case("g4", true)
@@ -2400,9 +2401,10 @@ public:
   // initFeatureMap which calls this repeatedly.
   static void setFeatureEnabledImpl(llvm::StringMap ,
 StringRef Name, bool Enabled);
-  bool initFeatureMap(llvm::StringMap , DiagnosticsEngine 
,
-  StringRef CPU,
-  std::vector ) const override;
+  bool
+  initFeatureMap(llvm::StringMap , DiagnosticsEngine ,
+ StringRef CPU,
+ const std::vector ) const override;
   bool hasFeature(StringRef Feature) const override;
   bool handleTargetFeatures(std::vector ,
 DiagnosticsEngine ) override;
@@ -2530,7 +2532,7 @@ bool X86TargetInfo::setFPMath(StringRef
 
 bool X86TargetInfo::initFeatureMap(
 llvm::StringMap , DiagnosticsEngine , StringRef CPU,
-std::vector ) const {
+const std::vector ) const {
   // FIXME: This *really* should not be here.
   // X86_64 always has SSE2.
   if (getTriple().getArch() == llvm::Triple::x86_64)
@@ -4427,10 +4429,11 @@ public:
   }
 
   // FIXME: This should be based on Arch attributes, not CPU names.
-  bool initFeatureMap(llvm::StringMap , DiagnosticsEngine 
,
-  StringRef CPU,
- 

Re: [PATCH] D13446: [PATCH] Add checker discouraging definition of variadic function definitions in C++

2015-10-09 Thread Daniel Berlin via cfe-commits
dberlin added a subscriber: dberlin.


Comment at: docs/clang-tidy/checks/cert-variadic-function-def.rst:13
@@ +12,2 @@
+`DCL50-CPP. Do not define a C-style variadic function
+`_.

I'm sure this is oversight on CERT's part, but their website actually has terms 
of use (click the terms of use at the bottom of the page) that says this can't 
be copied/reused, and here you are, copying it.
It explicit says: "
Use of the Service. You may only display the content of the Service for your 
own personal use (i.e., non-commercial use) and may not otherwise copy, 
reproduce, alter, modify, create derivative works, or publicly display any 
content. "

Before this is accepted, someone should email cert and say "hey, uh, yeah, this 
seems bad", and get them to okay you doing this.
I'm sure they'll go and fix this.



http://reviews.llvm.org/D13446



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


Re: [PATCH] D13446: [PATCH] Add checker discouraging definition of variadic function definitions in C++

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 3:09 PM, Daniel Berlin  wrote:
> dberlin added a subscriber: dberlin.
>
> 
> Comment at: docs/clang-tidy/checks/cert-variadic-function-def.rst:13
> @@ +12,2 @@
> +`DCL50-CPP. Do not define a C-style variadic function
> +`_.
> 
> I'm sure this is oversight on CERT's part, but their website actually has 
> terms of use (click the terms of use at the bottom of the page) that says 
> this can't be copied/reused, and here you are, copying it.
> It explicit says: "
> Use of the Service. You may only display the content of the Service for your 
> own personal use (i.e., non-commercial use) and may not otherwise copy, 
> reproduce, alter, modify, create derivative works, or publicly display any 
> content. "
>
> Before this is accepted, someone should email cert and say "hey, uh, yeah, 
> this seems bad", and get them to okay you doing this.
> I'm sure they'll go and fix this.

That's an excellent point, I will bring it up internally (I work for
CERT) and report back.

~Aaron

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


Re: [PATCH] D13444: [clang-tidy] Clocky module and multiple check from my repository

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 2:45 PM, Alexander Kornienko  wrote:
>
> On 6 Oct 2015 22:50, "Aaron Ballman"  wrote:
>>
>> On Tue, Oct 6, 2015 at 8:56 AM, Piotr Zegar  wrote:
>> > ClockMan abandoned this revision.
>> > ClockMan added a comment.
>> >
>> > As a 'corporation' in which I work has doubts that checks developed by
>> > my after work, but tested on copyright protected code should be released to
>> > public under my 'name'. I will drop "push request", until everything will
>> > clarify.
>>
>> I look forward to seeing a new patch at some point. I agree with
>> Eugene that any future patch should be split out into distinct patches
>> that focus on just one check at a time.
>>
>> > As for author name in module: For me is a: must-have, as I plan to
>> > extend these checks and develop more.
>> > As a author name in check name: I'm thinking about some "tags", so check
>> > could be registered under multiple names: clocky-object-copy-in-range-for
>> > and performance-object-copy-in-range-for.
>>
>> I would be opposed to using an author name in anything that is
>> user-facing. We group the checkers either by functionality
>> ("modernize-*" and "readability-*"), by organizational name
>> ("google-*" and "llvm-*"),
>
> Both "google" and "llvm" are not about organizations, but about specific
> styles, well thought out, documented, and verified for consistency by a
> significant amount of code using these styles. These module names are in no
> way meant to give credits to the organizations of their authors.

Thank you for stating this point more clearly than I did. My intent
was not to suggest that organizations are given credit for authorship.

~Aaron

>
>> or by publication name ("cert-* and
>> "cppcoreguidelines-*"). We actively discourage use of author names
>> even in our code comments.
>>
>> ~Aaron
>>
>> >
>> > Best regards,
>> > Clocky
>> >
>> >
>> > Repository:
>> >   rL LLVM
>> >
>> > http://reviews.llvm.org/D13444
>> >
>> >
>> >
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Tobias Langner via cfe-commits
Hi Aaron,

> 
>> - the second thing is this MaterializeTemporary advice that you gave. I 
>> don’t fully understand it (possibly due to a lack of understanding the AST 
>> and a lack of documentation of the proposed methods). Could you please flesh 
>> out your idea and why you think it is necessary? Or at least give an example 
>> where the current code does not work correctly.
> 
> 
> Consider code like:
> 
>  struct S {};
> 
>  S& g();
>  S h();
> 
>  void f() {
>throw g(); // Should diagnose, does not currently
>throw h(); // Should not diagnose, does not currently
>  }
> 
> "throw g();" isn't throwing a temporary because it's throwing from an lvalue 
> reference object (so the user may have a catch clause expecting the caught 
> object to be the same lvalue reference as what g() returns, except that's not 
> actually the case). If you instead check to see whether the throw expression 
> requires a temporary to be materialized, you'll find that g() will diagnose, 
> while h() still will not.
> 
> Does that help?
> 
yes. I added this to the test (you can find it here if required: 
https://github.com/iso8859-1/clang-tools-extra/blob/tobias-additional-checks/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp)
 and ran it through clang-query to check all throw statements. I found the 
following patterns:

Throw variants
y   throw->new = pointer from new
y/n throw->ImplicitCast->declrefexpr = throw named variable
n   throw->CXXConstructExpr (non-copy-constructor) = construction with normal 
parameter
n   throw->ImplicitCast->StringLiteral = throw string literal
n   throw->CXXConstructExpr (copy/move)->CallExpr (xvalue) = move
n   throw->CXXConstructExpr (copy/move)->MaterializeTemporary (xvalue)->Call
y   throw->CXXConstructExpr (copy/move)->ImplicitCast->CallExpr (lvalue)
n   throw->CXXConstructExpr (copy/move)->MaterializeTemporary (xvalue)->Call

the y or n or y/n means that we need to diagnose (the y/n depends on whether 
it’s a function parameter or catch parameter or not). When looking at the 
section with the copy construction, you’ll see that it depends on lvalue/xvalue 
(which you probably already knew). But MaterializeTemporary does not detect the 
T&& case.
My current thought is to go for “isLValue()” on Expr. It can be used for the 
CallExpr & the MaterializeTemporaryExpr alike and seems to capture the case 
where we want to diagnose for anonymous temporaries. What do you think?

Tobias

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


Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Tobias Langner via cfe-commits
randomcppprogrammer updated this revision to Diff 36977.
randomcppprogrammer marked 7 inline comments as done.
randomcppprogrammer added a comment.

new:

- diagnosis on throwing lvalues returned by function calls such as

struct S;
S& function();

void foo() {

  throw function();

}

- updated tests for this case
- updated some comments


http://reviews.llvm.org/D11328

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
  clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
  test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp

Index: test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp
@@ -0,0 +1,160 @@
+// RUN: %python %S/check_clang_tidy.py %s misc-throw-by-value-catch-by-reference %t
+
+
+class logic_error {
+public:
+  logic_error(const char *message) {}
+};
+
+typedef logic_error *logic_ptr;
+typedef logic_ptr logic_double_typedef;
+
+int lastException;
+
+template  struct remove_reference  {typedef T type;};
+template  struct remove_reference  {typedef T type;};
+template  struct remove_reference {typedef T type;};
+
+template 
+typename remove_reference::type&& move(T&& arg) {
+  return static_cast::type&&>(arg);
+}
+
+logic_error CreateException() { return logic_error("created"); }
+
+void testThrowFunc() {
+  throw new logic_error("by pointer");
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  logic_ptr tmp = new logic_error("by pointer");
+  throw tmp;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  throw logic_error("by value");
+  auto *literal = "test";
+  throw logic_error(literal);
+  throw "test string literal";
+  throw L"throw wide string literal";
+  const char *characters = 0;
+  throw characters;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  // CHECK-MESSAGES: :[[@LINE-2]]:9: warning: throw expression throws a pointer; it should throw a non-pointer value instead [misc-throw-by-value-catch-by-reference]
+  logic_error lvalue("lvalue");
+  throw lvalue;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  
+  throw move(lvalue);  
+  int  = lastException;
+  throw ex;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: throw expression should throw anonymous temporary values instead [misc-throw-by-value-catch-by-reference]
+  throw CreateException();
+}
+
+void throwReferenceFunc(logic_error ) {
+  throw ref;
+}
+
+void catchByPointer() {
+  try {
+testThrowFunc();
+  } catch (logic_error *e) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchByValue() {
+  try {
+testThrowFunc();
+  } catch (logic_error e) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchByReference() {
+  try {
+testThrowFunc();
+  } catch (logic_error ) {
+  }
+}
+
+void catchByConstReference() {
+  try {
+testThrowFunc();
+  } catch (const logic_error ) {
+  }
+}
+
+void catchTypedef() {
+  try {
+testThrowFunc();
+  } catch (logic_ptr) {
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: catch handler catches a pointer value; should throw a non-pointer value and catch by reference instead [misc-throw-by-value-catch-by-reference]
+  }
+}
+
+void catchAll() {
+  try {
+testThrowFunc();
+  } catch (...) {
+  }
+}
+
+void catchLiteral() {
+  try {
+testThrowFunc();
+  } catch (const char *) {
+  } catch (const wchar_t *) {
+// disabled for now until it is clear
+// how to enable them in the test
+//} catch (const char16_t*) {
+//} catch (const char32_t*) {
+  }
+}
+
+// catching fundamentals should not warn
+void catchFundamental() {
+  try {
+testThrowFunc();
+  } catch (int) {
+  } catch (double) {
+  } catch (unsigned long) {
+  }
+}
+
+struct TrivialType {
+  double x;
+  double y;
+};
+
+void catchTrivial() {
+  try {
+testThrowFunc();
+  } catch (TrivialType) {
+  }
+}
+
+typedef logic_error& fine;
+void additionalTests() {
+  try {
+  } catch (int i) { // ok
+throw i; // ok
+  } catch 

Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 3:31 PM, Tobias Langner
 wrote:
> Hi Aaron,
>
>>
>>> - the second thing is this MaterializeTemporary advice that you gave. I 
>>> don’t fully understand it (possibly due to a lack of understanding the AST 
>>> and a lack of documentation of the proposed methods). Could you please 
>>> flesh out your idea and why you think it is necessary? Or at least give an 
>>> example where the current code does not work correctly.
>>
>>
>> Consider code like:
>>
>>  struct S {};
>>
>>  S& g();
>>  S h();
>>
>>  void f() {
>>throw g(); // Should diagnose, does not currently
>>throw h(); // Should not diagnose, does not currently
>>  }
>>
>> "throw g();" isn't throwing a temporary because it's throwing from an lvalue 
>> reference object (so the user may have a catch clause expecting the caught 
>> object to be the same lvalue reference as what g() returns, except that's 
>> not actually the case). If you instead check to see whether the throw 
>> expression requires a temporary to be materialized, you'll find that g() 
>> will diagnose, while h() still will not.
>>
>> Does that help?
>>
> yes. I added this to the test (you can find it here if required: 
> https://github.com/iso8859-1/clang-tools-extra/blob/tobias-additional-checks/test/clang-tidy/misc-throw-by-value-catch-by-reference.cpp)
>  and ran it through clang-query to check all throw statements. I found the 
> following patterns:
>
> Throw variants
> y   throw->new = pointer from new
> y/n throw->ImplicitCast->declrefexpr = throw named variable
> n   throw->CXXConstructExpr (non-copy-constructor) = construction with normal 
> parameter
> n   throw->ImplicitCast->StringLiteral = throw string literal
> n   throw->CXXConstructExpr (copy/move)->CallExpr (xvalue) = move
> n   throw->CXXConstructExpr (copy/move)->MaterializeTemporary (xvalue)->Call
> y   throw->CXXConstructExpr (copy/move)->ImplicitCast->CallExpr (lvalue)
> n   throw->CXXConstructExpr (copy/move)->MaterializeTemporary (xvalue)->Call
>
> the y or n or y/n means that we need to diagnose (the y/n depends on whether 
> it’s a function parameter or catch parameter or not). When looking at the 
> section with the copy construction, you’ll see that it depends on 
> lvalue/xvalue (which you probably already knew). But MaterializeTemporary 
> does not detect the T&& case.
> My current thought is to go for “isLValue()” on Expr. It can be used for the 
> CallExpr & the MaterializeTemporaryExpr alike and seems to capture the case 
> where we want to diagnose for anonymous temporaries. What do you think?

That seems more comprehensive than what I was originally going for, so
I like it. I think that's a good approach, since an xvalue is an
eXpiring value (aka, temporary as far as this check is concerned), and
a prvalue is a pure rvalue (which is any rvalue that isn't an xvalue),
this should cover the cases we care about.

Thanks, great catch!

~Aaron

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


[libcxx] r249889 - Split out of .

2015-10-09 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct  9 14:56:37 2015
New Revision: 249889

URL: http://llvm.org/viewvc/llvm-project?rev=249889=rev
Log:
Split  out of .

Added:
libcxx/trunk/include/wchar.h
  - copied, changed from r249736, libcxx/trunk/include/cwchar
Modified:
libcxx/trunk/include/cwchar
libcxx/trunk/test/std/depr/depr.c.headers/wchar_h.pass.cpp

Modified: libcxx/trunk/include/cwchar
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwchar?rev=249889=249888=249889=diff
==
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/cwchar Fri Oct  9 14:56:37 2015
@@ -106,9 +106,6 @@ size_t wcsrtombs(char* restrict dst, con
 #include <__config>
 #include 
 #include 
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include  // pull in *swprintf defines
-#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
@@ -161,16 +158,13 @@ using ::wcscoll;
 using ::wcsncmp;
 using ::wcsxfrm;
 
-#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
-
+#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS
 using ::wcschr;
 using ::wcspbrk;
 using ::wcsrchr;
 using ::wcsstr;
 using ::wmemchr;
-
 #else
-
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
 
@@ -185,7 +179,6 @@ inline _LIBCPP_INLINE_VISIBILITY   w
 
 inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
 inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wmemchr(  wchar_t* __s, 
wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);}
-
 #endif
 
 using ::wcscspn;

Copied: libcxx/trunk/include/wchar.h (from r249736, libcxx/trunk/include/cwchar)
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wchar.h?p2=libcxx/trunk/include/wchar.h=libcxx/trunk/include/cwchar=249736=249889=249889=diff
==
--- libcxx/trunk/include/cwchar (original)
+++ libcxx/trunk/include/wchar.h Fri Oct  9 14:56:37 2015
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--- cwchar 
---===//
+//===--- wchar.h 
--===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,11 +8,19 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_CWCHAR
-#define _LIBCPP_CWCHAR
+#if defined(__need_wint_t) || defined(__need_mbstate_t)
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#pragma GCC system_header
+#endif
+
+#include_next 
+
+#elif !defined(_LIBCPP_WCHAR_H)
+#define _LIBCPP_WCHAR_H
 
 /*
-cwchar synopsis
+wchar.h synopsis
 
 Macros:
 
@@ -21,9 +29,6 @@ Macros:
 WCHAR_MIN
 WEOF
 
-namespace std
-{
-
 Types:
 
 mbstate_t
@@ -99,127 +104,33 @@ size_t mbsrtowcs(wchar_t* restrict dst,
 size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
  mbstate_t* restrict ps);
 
-}  // std
-
 */
 
 #include <__config>
-#include 
-#include 
-#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
-#include  // pull in *swprintf defines
-#endif // _LIBCPP_MSVCRT
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
-
-using ::mbstate_t;
-using ::size_t;
-using ::tm;
-using ::wint_t;
-using ::FILE;
-using ::fwprintf;
-using ::fwscanf;
-using ::swprintf;
-using ::vfwprintf;
-using ::vswprintf;
-#ifndef _LIBCPP_MSVCRT
-using ::swscanf;
-using ::vfwscanf;
-using ::vswscanf;
-#endif // _LIBCPP_MSVCRT
-using ::fgetwc;
-using ::fgetws;
-using ::fputwc;
-using ::fputws;
-using ::fwide;
-using ::getwc;
-using ::putwc;
-using ::ungetwc;
-using ::wcstod;
-#ifndef _LIBCPP_MSVCRT
-using ::wcstof;
-using ::wcstold;
-#endif // _LIBCPP_MSVCRT
-using ::wcstol;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-using ::wcstoll;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-using ::wcstoul;
-#ifndef _LIBCPP_HAS_NO_LONG_LONG
-using ::wcstoull;
-#endif // _LIBCPP_HAS_NO_LONG_LONG
-using ::wcscpy;
-using ::wcsncpy;
-using ::wcscat;
-using ::wcsncat;
-using ::wcscmp;
-using ::wcscoll;
-using ::wcsncmp;
-using ::wcsxfrm;
-
-#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
-
-using ::wcschr;
-using ::wcspbrk;
-using ::wcsrchr;
-using ::wcsstr;
-using ::wmemchr;
-
-#else
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
-inline _LIBCPP_INLINE_VISIBILITY   wchar_t* wcschr(  wchar_t* __s, 
wchar_t __c) {return ::wcschr(__s, __c);}
-
-inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcspbrk(const wchar_t* __s1, 
const wchar_t* __s2) {return ::wcspbrk(__s1, __s2);}
-inline _LIBCPP_INLINE_VISIBILITY  

Re: [PATCH] D12747: Implement [depr.c.headers]

2015-10-09 Thread Richard Smith via cfe-commits
As of r249890, all committed other than patches 12 (string.h) and 15 (more
tests).

On Thu, Oct 8, 2015 at 9:12 PM, Richard Smith  wrote:

> On Thu, Oct 8, 2015 at 6:58 PM, Richard Smith 
> wrote:
>
>> On Thu, Oct 8, 2015 at 6:25 PM, Eric Fiselier  wrote:
>>
>>> Patch #12 needs revision. A bunch of function definitions were moved
>>> out of the std namespace and into the global.
>>> That change is incorrect.
>>
>>
>> Slightly updated version attached. I should probably explain what's going
>> on here in more detail:
>>
>> Per [c.strings]p4-p13, we're supposed to replace C functions of the form
>>
>>   char *foo(const char*);
>>
>> with a pair of const-correct overloads of the form
>>
>>   char *foo(char *);
>>   const char *foo(const char*);
>>
>> Now, most C standard libraries will do this for us when included in C++
>> mode (because it's not possible for the C++ library to fix this up after
>> the fact). For the cases where we *don't* believe we have such a
>> considerate C library, we add one declaration to C's overload, to get:
>>
>>   char *foo(char*);
>>   char *foo(const char*)
>>
>> ... which doesn't really help much, but is the closest we can get to the
>> right set of declarations. The declarations we add just dispatch to the C
>> declarations.
>>
>> These new declarations *should* be in the global namespace when including
>> , and it makes sense for us to put them in the global namespace
>> when including  (otherwise, that header leaves us with a broken
>> overload set in the global namespace, containing just one of the two
>> expected functions).
>>
>> Anyway, most of the above is a description of what we did before. What's
>> new here is that we attempt to fix the overload set for both  and
>> for , not just for the latter. At the end of all these changes,
>> you'll see that all that the  headers do is to include the 
>> header and use using-declarations to pull the names into namespace std;
>> this is no exception to that pattern.
>>
>
> Per Eric and my discussion on IRC, the pattern used by  seems
> better here:
>
> If libc has left us with a bad overload set, don't try to fix the names in
> ::, just provide a complete set of overloads in namespace std.
>
> A patch for that approach is attached.
>
> On Thu, Oct 8, 2015 at 7:09 PM, Eric Fiselier  wrote:
>>> > Patch #11 LGTM. Any reason you removed the "#pragma diagnostic ignored
>>> > "-Wnonnull"" in test/std/depr/depr.c.headers/stdlib_h.pass.cpp?
>>> > I would like to leave it in so this test doesn't fail with older clang
>>> > versions.
>>> >
>>> > /Eric
>>> >
>>> > On Thu, Oct 8, 2015 at 6:47 PM, Eric Fiselier  wrote:
>>> >> Patch #10 LGTM.
>>> >>
>>> >> On Thu, Oct 8, 2015 at 4:28 PM, Richard Smith 
>>> wrote:
>>> >>> On Thu, Oct 8, 2015 at 11:50 AM, Marshall Clow <
>>> mclow.li...@gmail.com>
>>> >>> wrote:
>>> 
>>>  On Tue, Oct 6, 2015 at 3:57 PM, Richard Smith <
>>> rich...@metafoo.co.uk>
>>>  wrote:
>>> >
>>> > . This one is tricky:
>>> >
>>> > 1) There's an (undocumented) interface between the C standard
>>> library and
>>> > this header, where the macros __need_ptrdiff_t, __need_size_t,
>>> > __need_wchar_t, __need_NULL, __need_wint_t request just a piece of
>>> this
>>> > header rather than the whole thing. If we see any of those, just
>>> go straight
>>> > to the underlying header.
>>> 
>>> 
>>>  Ok, but in that case we don't get nullptr.  I suspect that's OK.
>>> 
>>> >
>>> > 2) We probably don't want  to include  (for
>>> > consistency with other headers)
>>> 
>>> 
>>>  No, we do not! :-)
>>> 
>>> >
>>> > , but  must provide a ::nullptr_t (which we don't want
>>> >  to provide). So neither header includes the other.
>>> Instead, both
>>> > include <__nullptr> for std::nullptr_t, and we duplicate the
>>> definition of
>>> > max_align_t between them, in the case where the compiler's
>>> 
>>> > doesn't provide it.
>>> >
>>> > If you prefer, I could make  include  to avoid
>>> the
>>> > duplication of the max_align_t logic.
>>> 
>>> 
>>>  No; this is a minor annoyance, and layer jumping (
>>> including
>>>  ) is a major annoyance - and I'm pretty sure that that
>>> would come
>>>  back to bite us in the future.
>>> 
>>>  Looks ok to me.
>>> >>>
>>> >>>
>>> >>> Thanks, everything up to and including patch 09 is now committed.
>>>
>>
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r249890 - Split out of .

2015-10-09 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Fri Oct  9 14:57:37 2015
New Revision: 249890

URL: http://llvm.org/viewvc/llvm-project?rev=249890=rev
Log:
Split  out of .

Added:
libcxx/trunk/include/wctype.h
  - copied, changed from r249736, libcxx/trunk/include/cwctype
Modified:
libcxx/trunk/include/cwctype

Modified: libcxx/trunk/include/cwctype
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cwctype?rev=249890=249889=249890=diff
==
--- libcxx/trunk/include/cwctype (original)
+++ libcxx/trunk/include/cwctype Fri Oct  9 14:57:37 2015
@@ -63,41 +63,23 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 using ::wint_t;
 using ::wctrans_t;
 using ::wctype_t;
-#undef iswalnum
 using ::iswalnum;
-#undef iswalpha
 using ::iswalpha;
-#undef iswblank
 using ::iswblank;
-#undef iswcntrl
 using ::iswcntrl;
-#undef iswdigit
 using ::iswdigit;
-#undef iswgraph
 using ::iswgraph;
-#undef iswlower
 using ::iswlower;
-#undef iswprint
 using ::iswprint;
-#undef iswpunct
 using ::iswpunct;
-#undef iswspace
 using ::iswspace;
-#undef iswupper
 using ::iswupper;
-#undef iswxdigit
 using ::iswxdigit;
-#undef iswctype
 using ::iswctype;
-#undef wctype
 using ::wctype;
-#undef towlower
 using ::towlower;
-#undef towupper
 using ::towupper;
-#undef towctrans
 using ::towctrans;
-#undef wctrans
 using ::wctrans;
 
 _LIBCPP_END_NAMESPACE_STD

Copied: libcxx/trunk/include/wctype.h (from r249736, 
libcxx/trunk/include/cwctype)
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/wctype.h?p2=libcxx/trunk/include/wctype.h=libcxx/trunk/include/cwctype=249736=249890=249890=diff
==
--- libcxx/trunk/include/cwctype (original)
+++ libcxx/trunk/include/wctype.h Fri Oct  9 14:57:37 2015
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-//===--- cwctype 
--===//
+//===--- wctype.h 
-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -8,19 +8,16 @@
 //
 
//===--===//
 
-#ifndef _LIBCPP_CWCTYPE
-#define _LIBCPP_CWCTYPE
+#ifndef _LIBCPP_WCTYPE_H
+#define _LIBCPP_WCTYPE_H
 
 /*
-cwctype synopsis
+wctype.h synopsis
 
 Macros:
 
 WEOF
 
-namespace std
-{
-
 Types:
 
 wint_t
@@ -46,60 +43,37 @@ wint_t towupper(wint_t wc);
 wint_t towctrans(wint_t wc, wctrans_t desc);
 wctrans_t wctrans(const char* property);
 
-}  // std
-
 */
 
 #include <__config>
-#include 
-#include 
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
 #pragma GCC system_header
 #endif
 
-_LIBCPP_BEGIN_NAMESPACE_STD
+#include_next 
+
+#ifdef __cplusplus
 
-using ::wint_t;
-using ::wctrans_t;
-using ::wctype_t;
 #undef iswalnum
-using ::iswalnum;
 #undef iswalpha
-using ::iswalpha;
 #undef iswblank
-using ::iswblank;
 #undef iswcntrl
-using ::iswcntrl;
 #undef iswdigit
-using ::iswdigit;
 #undef iswgraph
-using ::iswgraph;
 #undef iswlower
-using ::iswlower;
 #undef iswprint
-using ::iswprint;
 #undef iswpunct
-using ::iswpunct;
 #undef iswspace
-using ::iswspace;
 #undef iswupper
-using ::iswupper;
 #undef iswxdigit
-using ::iswxdigit;
 #undef iswctype
-using ::iswctype;
 #undef wctype
-using ::wctype;
 #undef towlower
-using ::towlower;
 #undef towupper
-using ::towupper;
 #undef towctrans
-using ::towctrans;
 #undef wctrans
-using ::wctrans;
 
-_LIBCPP_END_NAMESPACE_STD
+#endif  // __cplusplus
 
-#endif  // _LIBCPP_CWCTYPE
+#endif  // _LIBCPP_WCTYPE_H


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


Re: [PATCH] D11328: [clang-tidy] new "throw-by-value-catch-by-reference" check for clang-tidy

2015-10-09 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM! Please run your patch through clang-format before committing (just to fix 
the last bits of style and whitespace issues; no additional review required).

Thank you for your hard work on this! As a cleanup once this goes in: we should 
add some user-facing documentation to docs\clang-tidy\checks for it. We can 
even take what's in ThrowByValueCatchByReferenceCheck.h and use that (then link 
to it from the header file instead of duplicating the words).


http://reviews.llvm.org/D11328



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


Re: r249831 - [VFS] Wire up driver VFS through tooling.

2015-10-09 Thread Manuel Klimek via cfe-commits
On Fri, Oct 9, 2015 at 3:05 PM Benjamin Kramer via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: d0k
> Date: Fri Oct  9 08:03:25 2015
> New Revision: 249831
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249831=rev
> Log:
> [VFS] Wire up driver VFS through tooling.
>
> Sadly I don't currently have a way to tests this as the driver is always
> initialized with the default triple and finding system headers is system
> specific.
>

 If necessary, we might be able to put in a target triple via command line
flags (hopefully)


>
> Modified:
> cfe/trunk/lib/Tooling/Tooling.cpp
>
> Modified: cfe/trunk/lib/Tooling/Tooling.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Tooling.cpp?rev=249831=249830=249831=diff
>
> ==
> --- cfe/trunk/lib/Tooling/Tooling.cpp (original)
> +++ cfe/trunk/lib/Tooling/Tooling.cpp Fri Oct  9 08:03:25 2015
> @@ -46,10 +46,11 @@ FrontendActionFactory::~FrontendActionFa
>  // it to be based on the same framework.
>
>  /// \brief Builds a clang driver initialized for running clang tools.
> -static clang::driver::Driver *newDriver(clang::DiagnosticsEngine
> *Diagnostics,
> -const char *BinaryName) {
> +static clang::driver::Driver *newDriver(
> +clang::DiagnosticsEngine *Diagnostics, const char *BinaryName,
> +IntrusiveRefCntPtr VFS) {
>clang::driver::Driver *CompilerDriver = new clang::driver::Driver(
> -  BinaryName, llvm::sys::getDefaultTargetTriple(), *Diagnostics);
> +  BinaryName, llvm::sys::getDefaultTargetTriple(), *Diagnostics, VFS);
>CompilerDriver->setTitle("clang_based_tool");
>return CompilerDriver;
>  }
> @@ -238,7 +239,7 @@ bool ToolInvocation::run() {
>DiagConsumer ? DiagConsumer : , false);
>
>const std::unique_ptr Driver(
> -  newDriver(, BinaryName));
> +  newDriver(, BinaryName, Files->getVirtualFileSystem()));
>// Since the input might only be virtual, don't check whether it exists.
>Driver->setCheckInputsExist(false);
>const std::unique_ptr Compilation(
>
>
> ___
> 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: [PATCH] D12726: [analyzer] A fix for symbolic element region index lifetime.

2015-10-09 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 36946.
NoQ marked 4 inline comments as done.
NoQ added a comment.

Thanks for the review! Fixed all comments. I don't notice any significant 
performance hit with this patch (+/- 2% on the whole Android codebase runs).

I guess i won't break this into separate reviews, because less work =)

The loop through super-regions is necessary for supporting the test proposed by 
Jordan Rose, which is now added. Not sure what other tests are worth adding; 
together with specific tests on ReturnPtrRange, we're covering all three places 
that were patched; maybe i could move these tests to symbol-reaper.c as well, 
but i guess it's more worth it to test the actual analyzer output than 
artificially dumped internals(?) Not sure.

The change in Environment.cpp was removed because it's now handled 
automatically by markLive().


http://reviews.llvm.org/D12726

Files:
  docs/analyzer/DebugChecks.rst
  include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h
  lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  lib/StaticAnalyzer/Core/RegionStore.cpp
  lib/StaticAnalyzer/Core/SymbolManager.cpp
  test/Analysis/return-ptr-range.cpp
  test/Analysis/symbol-reaper.c

Index: test/Analysis/symbol-reaper.c
===
--- test/Analysis/symbol-reaper.c
+++ test/Analysis/symbol-reaper.c
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=debug.ExprInspection -verify %s
+
+void clang_analyzer_warnOnDeadSymbol(int);
+
+int conjure_index();
+
+void test_that_expr_inspection_works() {
+  do {
+int x = conjure_index();
+clang_analyzer_warnOnDeadSymbol(x);
+  } while(0); // expected-warning{{SYMBOL DEAD}}
+}
+
+int arr[3];
+void test_element_index_lifetime() {
+  do {
+int x = conjure_index();
+clang_analyzer_warnOnDeadSymbol(x);
+arr[x] = 1;
+if (x) {}
+  } while (0); // no-warning
+}
+
+struct S1 {
+  int field;
+};
+struct S2 {
+  struct S1 array[5];
+} s2;
+void test_element_index_lifetime_with_complicated_hierarchy_of_regions() {
+  do {
+int x = conjure_index();
+clang_analyzer_warnOnDeadSymbol(x);
+s2.array[x].field = 1;
+if (x) {}
+  } while (0); // no-warning
+}
Index: test/Analysis/return-ptr-range.cpp
===
--- test/Analysis/return-ptr-range.cpp
+++ test/Analysis/return-ptr-range.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.security.ReturnPtrRange -verify %s
+
+int arr[10];
+int *ptr;
+
+int conjure_index();
+
+int *test_element_index_lifetime() {
+  do {
+int x = conjure_index();
+ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+}
+
+int *test_element_index_lifetime_with_local_ptr() {
+  int *local_ptr;
+  do {
+int x = conjure_index();
+local_ptr = arr + x;
+if (x != 20)
+  return arr; // no-warning
+  } while (0);
+  return local_ptr; // expected-warning{{Returned pointer value points outside the original object (potential buffer overflow)}}
+}
Index: lib/StaticAnalyzer/Core/SymbolManager.cpp
===
--- lib/StaticAnalyzer/Core/SymbolManager.cpp
+++ lib/StaticAnalyzer/Core/SymbolManager.cpp
@@ -391,6 +391,18 @@
 
 void SymbolReaper::markLive(const MemRegion *region) {
   RegionRoots.insert(region);
+  // Mark the element index in all superregions as live.
+  markElementIndicesLive(region);
+}
+
+void SymbolReaper::markElementIndicesLive(const MemRegion *region) {
+  for (auto SR = dyn_cast(region); SR;
+   SR = dyn_cast(SR->getSuperRegion()))
+if (auto ER = dyn_cast(SR)) {
+  SVal Idx = ER->getIndex();
+  for (auto SI = Idx.symbol_begin(), SE = Idx.symbol_end(); SI != SE; ++SI)
+markLive(*SI);
+}
 }
 
 void SymbolReaper::markInUse(SymbolRef sym) {
Index: lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- lib/StaticAnalyzer/Core/RegionStore.cpp
+++ lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -2344,8 +2344,12 @@
   if (const SymbolicRegion *SymR = dyn_cast(baseR))
 SymReaper.markLive(SymR->getSymbol());
 
-  for (ClusterBindings::iterator I = C->begin(), E = C->end(); I != E; ++I)
+  for (ClusterBindings::iterator I = C->begin(), E = C->end(); I != E; ++I) {
+// Element index of a binding key is live.
+SymReaper.markElementIndicesLive(I.getKey().getRegion());
+
 VisitBinding(I.getData());
+  }
 }
 
 void removeDeadBindingsWorker::VisitBinding(SVal V) {
@@ -2366,6 +2370,8 @@
   // If V is a region, then add it to the worklist.
   if (const MemRegion *R = V.getAsRegion()) {
 AddToWorkList(R);
+// Element index of a binding value is live.
+SymReaper.markElementIndicesLive(R);
 
 // All regions captured by a block are also live.
 

Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-09 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good. Do you have commit rights? If no, please have someone commit this 
for you. I won't be able to help with this soon, unfortunately.


Repository:
  rL LLVM

http://reviews.llvm.org/D13440



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


Re: [PATCH] D13440: [clang-tidy] Python script for easy check rename

2015-10-09 Thread Aaron Ballman via cfe-commits
On Fri, Oct 9, 2015 at 11:21 AM, Alexander Kornienko  wrote:
> alexfh accepted this revision.
> alexfh added a comment.
> This revision is now accepted and ready to land.
>
> Looks good. Do you have commit rights? If no, please have someone commit this 
> for you. I won't be able to help with this soon, unfortunately.

If not, I can commit.

~Aaron

>
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D13440
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D13582: [DEBUG INFO] Emit debug info for type used in explicit cast only.

2015-10-09 Thread David Blaikie via cfe-commits
On Fri, Oct 9, 2015 at 2:26 AM, Alexey Bataev via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> ABataev created this revision.
> ABataev added a reviewer: echristo.
> ABataev added a subscriber: cfe-commits.
>
> Currently debug info for types used in explicit cast only is not emitted.
> It happened after a patch for better alignment handling.


You mean a patch related to alignment regressed this functionality? Do you
have the specific revision number of that change (since it sounds like you
tracked it down)?


> This patch fixes this bug.
>
> http://reviews.llvm.org/D13582
>
> Files:
>   lib/CodeGen/CGExpr.cpp
>   test/CodeGenCXX/debug-info-explicit-cast.cpp
>
> Index: lib/CodeGen/CGExpr.cpp
> ===
> --- lib/CodeGen/CGExpr.cpp
> +++ lib/CodeGen/CGExpr.cpp
> @@ -799,6 +799,10 @@
>  if (E->getType()->isVariablyModifiedType())
>EmitVariablyModifiedType(E->getType());
>
> +if (isa(CE))
> +  if (CGDebugInfo *DI = getDebugInfo())
> +DI->EmitExplicitCastType(E->getType());
> +
>  switch (CE->getCastKind()) {
>  // Non-converting casts (but not C's implicit conversion from void*).
>  case CK_BitCast:
> Index: test/CodeGenCXX/debug-info-explicit-cast.cpp
> ===
> --- test/CodeGenCXX/debug-info-explicit-cast.cpp
> +++ test/CodeGenCXX/debug-info-explicit-cast.cpp
> @@ -0,0 +1,18 @@
> +// RUN: %clangxx -c -target x86_64-unknown-unknown -g %s -emit-llvm -S -o
> - | FileCheck %s
> +struct Foo {
> +  int a;
> +  Foo() : a(1){};
> +};
> +
> +struct Bar {
> +  int b;
> +  Bar() : b(2){};
> +};
> +
> +int main() {
> +  Bar *pb = new Bar;
> +
> +  return reinterpret_cast(pb)->a;
> +}
> +
> +// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo",
>
>
>
> ___
> 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