[libcxx] r313344 - typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Sep 14 22:42:39 2017
New Revision: 313344

URL: http://llvm.org/viewvc/llvm-project?rev=313344=rev
Log:
typeinfo: provide a partial implementation for Win32

The RTTI structure is different on Windows when building under MS ABI.
Update the definition to reflect this. The structure itself contains an
area for caching the undecorated name (which is 0-initialized). The
decorated name has a bitfield followed by the linkage name. When
std::type_info::name is invoked for the first time, the runtime should
undecorate the name, cache it, and return the undecorated name. This
requires access to an implementation of __unDName. For now, return
the raw name.

This uses the fnv-1a hash to hash the name of the RTTI. We could use an
alternate hash (murmur? city?), but, this was the quickest to throw
together.

Modified:
libcxx/trunk/include/typeinfo
libcxx/trunk/src/support/runtime/exception_msvc.ipp
libcxx/trunk/src/typeinfo.cpp

Modified: libcxx/trunk/include/typeinfo
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/typeinfo?rev=313344=313343=313344=diff
==
--- libcxx/trunk/include/typeinfo (original)
+++ libcxx/trunk/include/typeinfo Thu Sep 14 22:42:39 2017
@@ -69,18 +69,17 @@ public:
 #pragma GCC system_header
 #endif
 
-#if defined(_LIBCPP_ABI_MICROSOFT)
-#include 
-#elif defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
+#if !defined(_LIBCPP_ABI_MICROSOFT)
+#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
 #else
 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
 #endif
+#endif
 
 namespace std  // purposefully not using versioning namespace
 {
 
-#if !defined(_LIBCPP_ABI_MICROSOFT)
 class _LIBCPP_EXCEPTION_ABI type_info
 {
 type_info& operator=(const type_info&);
@@ -92,7 +91,17 @@ class _LIBCPP_EXCEPTION_ABI type_info
 { return __builtin_strcmp(name(), __arg.name()); }
 #endif
 
+#if defined(_LIBCPP_ABI_MICROSOFT)
+mutable struct {
+  const char *__undecorated_name;
+  const char __decorated_name[1];
+} __data;
+
+int __compare(const struct type_info &__rhs) const _NOEXCEPT;
+#endif // _LIBCPP_ABI_MICROSOFT
+
 protected:
+#if !defined(_LIBCPP_ABI_MICROSOFT)
 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
 // A const char* with the non-unique RTTI bit possibly set.
 uintptr_t __type_name;
@@ -106,11 +115,27 @@ protected:
 _LIBCPP_INLINE_VISIBILITY
 explicit type_info(const char* __n) : __type_name(__n) {}
 #endif
+#endif // ! _LIBCPP_ABI_MICROSOFT
 
 public:
 _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
 virtual ~type_info();
 
+#if defined(_LIBCPP_ABI_MICROSOFT)
+const char *name() const _NOEXCEPT;
+
+_LIBCPP_INLINE_VISIBILITY
+bool before(const type_info& __arg) const _NOEXCEPT {
+  return __compare(__arg) < 0;
+}
+
+size_t hash_code() const _NOEXCEPT;
+
+_LIBCPP_INLINE_VISIBILITY
+bool operator==(const type_info& __arg) const _NOEXCEPT {
+  return __compare(__arg) == 0;
+}
+#else
 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
 _LIBCPP_INLINE_VISIBILITY
 const char* name() const _NOEXCEPT
@@ -167,6 +192,7 @@ public:
 bool operator==(const type_info& __arg) const _NOEXCEPT
 { return __type_name == __arg.__type_name; }
 #endif
+#endif // _LIBCPP_ABI_MICROSOFT
 
 _LIBCPP_INLINE_VISIBILITY
 bool operator!=(const type_info& __arg) const _NOEXCEPT
@@ -191,8 +217,6 @@ public:
 virtual const char* what() const _NOEXCEPT;
 };
 
-#endif // !_LIBCPP_ABI_MICROSOFT
-
 }  // std
 
 _LIBCPP_BEGIN_NAMESPACE_STD

Modified: libcxx/trunk/src/support/runtime/exception_msvc.ipp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/runtime/exception_msvc.ipp?rev=313344=313343=313344=diff
==
--- libcxx/trunk/src/support/runtime/exception_msvc.ipp (original)
+++ libcxx/trunk/src/support/runtime/exception_msvc.ipp Thu Sep 14 22:42:39 2017
@@ -86,4 +86,32 @@ bad_array_length::what() const _NOEXCEPT
 return "bad_array_length";
 }
 
+bad_cast::bad_cast() _NOEXCEPT
+{
+}
+
+bad_cast::~bad_cast() _NOEXCEPT
+{
+}
+
+const char *
+bad_cast::what() const _NOEXCEPT
+{
+  return "std::bad_cast";
+}
+
+bad_typeid::bad_typeid() _NOEXCEPT
+{
+}
+
+bad_typeid::~bad_typeid() _NOEXCEPT
+{
+}
+
+const char *
+bad_typeid::what() const _NOEXCEPT
+{
+  return "std::bad_typeid";
+}
+
 } // namespace std

Modified: libcxx/trunk/src/typeinfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/typeinfo.cpp?rev=313344=313343=313344=diff
==
--- libcxx/trunk/src/typeinfo.cpp (original)
+++ libcxx/trunk/src/typeinfo.cpp Thu Sep 14 22:42:39 2017
@@ -9,11 +9,48 @@
 
 #include "typeinfo"
 
+#if defined(_LIBCPP_ABI_MICROSOFT)
+#include 
+
+int std::type_info::__compare(const type_info &__rhs) const _NOEXCEPT {
+  if (&__data == &__rhs.__data)
+return 

[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd marked 4 inline comments as done.
compnerd added a comment.

Also added `_NOEXCEPT` to `__compare`.


https://reviews.llvm.org/D28212



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


[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added inline comments.



Comment at: include/typeinfo:100
+int __compare(const struct type_info &__rhs);
+#endif // _LIBCPP_ABI_MICROSOFT
+

Drop the `struct`; it causes compilation errors.

This needs to be marked `const`.



Comment at: src/typeinfo.cpp:15
+  if (&__data == &__rhs.__data)
+return 0;
+  return strcmp(&__data.__decorated_name[1], 
&__rhs.__data.__decorated_name[1]);

Drop the `struct` and add the `const`.



Comment at: src/typeinfo.cpp:21
+  // TODO(compnerd) cache demangled &__data.__decorated_name[1]
+  return &__data.__decorated_name[1];
+}

You need a `const` here.



Comment at: src/typeinfo.cpp:36
+value ^= static_cast(static_cast(*c));
+value *= fnv_prime;
+  }

The `->` should be `.`


https://reviews.llvm.org/D28212



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


[clang-tools-extra] r313335 - Revert "[lit] Force site configs to run before source-tree configs"

2017-09-14 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Sep 14 19:56:40 2017
New Revision: 313335

URL: http://llvm.org/viewvc/llvm-project?rev=313335=rev
Log:
Revert "[lit] Force site configs to run before source-tree configs"

This patch is still breaking several multi-stage compiler-rt bots.
I already know what the fix is, but I want to get the bots green
for now and then try re-applying in the morning.

Modified:
clang-tools-extra/trunk/test/Unit/lit.cfg
clang-tools-extra/trunk/test/lit.cfg

Modified: clang-tools-extra/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/Unit/lit.cfg?rev=313335=313334=313335=diff
==
--- clang-tools-extra/trunk/test/Unit/lit.cfg (original)
+++ clang-tools-extra/trunk/test/Unit/lit.cfg Thu Sep 14 19:56:40 2017
@@ -9,9 +9,10 @@ config.suffixes = [] # Seems not to matt
 
 # Test Source and Exec root dirs both point to the same directory where google
 # test binaries are built.
-
-config.test_source_root = config.extra_tools_obj_dir
-config.test_exec_root = config.test_source_root
+extra_tools_obj_dir = getattr(config, 'extra_tools_obj_dir', None)
+if extra_tools_obj_dir is not None:
+  config.test_source_root = extra_tools_obj_dir
+  config.test_exec_root = config.test_source_root
 
 # All GoogleTests are named to have 'Tests' as their suffix. The '.' option is
 # a special value for GoogleTest indicating that it should look through the
@@ -19,6 +20,18 @@ config.test_exec_root = config.test_sour
 # ;-separated list of subdirectories).
 config.test_format = lit.formats.GoogleTest('.', 'Tests')
 
+# If the site-specific configuration wasn't loaded (e.g. the build system 
failed
+# to create it or the user is running a test file directly) try to come up with
+# sane config options.
+if config.test_exec_root is None:
+  # Look for a --param=extra_tools_unit_site_config option.
+  site_cfg = lit_config.params.get('extra_tools_unit_site_config', None)
+  if site_cfg and os.path.exists(site_cfg):
+  lit_config.load_config(config, site_cfg)
+  raise SystemExit
+
+  # FIXME: Support out-of-tree builds? See clang/test/Unit/lit.cfg if we care.
+
 shlibpath_var = ''
 if platform.system() == 'Linux':
 shlibpath_var = 'LD_LIBRARY_PATH'
@@ -28,11 +41,17 @@ elif platform.system() == 'Windows':
 shlibpath_var = 'PATH'
 
 # Point the dynamic loader at dynamic libraries in 'lib'.
-shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
+shlibdir = getattr(config, 'shlibdir', None)
+if not shlibdir:
+lit_config.fatal('No shlibdir set!')
+llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
+if not llvm_libs_dir:
+lit_config.fatal('No LLVM libs dir set!')
+shlibpath = os.path.pathsep.join((shlibdir, llvm_libs_dir,
  config.environment.get(shlibpath_var,'')))
 
 # Win32 seeks DLLs along %PATH%.
-if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
-shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
+if sys.platform in ['win32', 'cygwin'] and os.path.isdir(shlibdir):
+shlibpath = os.path.pathsep.join((shlibdir, shlibpath))
 
 config.environment[shlibpath_var] = shlibpath

Modified: clang-tools-extra/trunk/test/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/lit.cfg?rev=313335=313334=313335=diff
==
--- clang-tools-extra/trunk/test/lit.cfg (original)
+++ clang-tools-extra/trunk/test/lit.cfg Thu Sep 14 19:56:40 2017
@@ -54,7 +54,9 @@ config.excludes = ['Inputs']
 config.test_source_root = os.path.dirname(__file__)
 
 # test_exec_root: The root path where tests should be run.
-config.test_exec_root = os.path.join(config.clang_tools_binary_dir, 'test')
+clang_tools_binary_dir = getattr(config, 'clang_tools_binary_dir', None)
+if clang_tools_binary_dir is not None:
+config.test_exec_root = os.path.join(clang_tools_binary_dir, 'test')
 
 # Clear some environment variables that might affect Clang.
 #
@@ -86,19 +88,92 @@ for name in possibly_dangerous_env_vars:
 del config.environment[name]
 
 # Tweak the PATH to include the tools dir and the scripts dir.
-path = os.path.pathsep.join((
-config.clang_tools_dir, config.llvm_tools_dir, 
config.environment['PATH']))
-config.environment['PATH'] = path
-
-path = os.path.pathsep.join((config.clang_libs_dir, config.llvm_libs_dir,
-  config.environment.get('LD_LIBRARY_PATH','')))
-config.environment['LD_LIBRARY_PATH'] = path
+if clang_tools_binary_dir is not None:
+clang_tools_dir = getattr(config, 'clang_tools_dir', None)
+if not clang_tools_dir:
+lit_config.fatal('No Clang tools dir set!')
+llvm_tools_dir = getattr(config, 'llvm_tools_dir', None)
+if not llvm_tools_dir:
+lit_config.fatal('No LLVM tools dir set!')
+path = os.path.pathsep.join((
+

r313335 - Revert "[lit] Force site configs to run before source-tree configs"

2017-09-14 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Sep 14 19:56:40 2017
New Revision: 313335

URL: http://llvm.org/viewvc/llvm-project?rev=313335=rev
Log:
Revert "[lit] Force site configs to run before source-tree configs"

This patch is still breaking several multi-stage compiler-rt bots.
I already know what the fix is, but I want to get the bots green
for now and then try re-applying in the morning.

Modified:
cfe/trunk/runtime/CMakeLists.txt
cfe/trunk/test/Unit/lit.cfg
cfe/trunk/test/lit.cfg

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=313335=313334=313335=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Thu Sep 14 19:56:40 2017
@@ -77,7 +77,6 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND E
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
-   -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
${COMPILER_RT_PASSTHROUGH_VARIABLES}

Modified: cfe/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.cfg?rev=313335=313334=313335=diff
==
--- cfe/trunk/test/Unit/lit.cfg (original)
+++ cfe/trunk/test/Unit/lit.cfg Thu Sep 14 19:56:40 2017
@@ -17,11 +17,14 @@ config.suffixes = []
 
 # test_source_root: The root path where tests are located.
 # test_exec_root: The root path where tests should be run.
-config.test_exec_root = os.path.join(config.clang_obj_root, 'unittests')
-config.test_source_root = config.test_exec_root
+clang_obj_root = getattr(config, 'clang_obj_root', None)
+if clang_obj_root is not None:
+config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
+config.test_source_root = config.test_exec_root
 
 # testFormat: The test format to use to interpret tests.
-config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, 'Tests')
+llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
+config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
 
 # Propagate the temp directory. Windows requires this because it uses \Windows\
 # if none of these are present.
@@ -35,6 +38,55 @@ for symbolizer in ['ASAN_SYMBOLIZER_PATH
 if symbolizer in os.environ:
 config.environment[symbolizer] = os.environ[symbolizer]
 
+###
+
+# Check that the object root is known.
+if config.test_exec_root is None:
+# Otherwise, we haven't loaded the site specific configuration (the user is
+# probably trying to run on a test file directly, and either the site
+# configuration hasn't been created by the build system, or we are in an
+# out-of-tree build situation).
+
+# Check for 'clang_unit_site_config' user parameter, and use that if 
available.
+site_cfg = lit_config.params.get('clang_unit_site_config', None)
+if site_cfg and os.path.exists(site_cfg):
+lit_config.load_config(config, site_cfg)
+raise SystemExit
+
+# Try to detect the situation where we are using an out-of-tree build by
+# looking for 'llvm-config'.
+#
+# FIXME: I debated (i.e., wrote and threw away) adding logic to
+# automagically generate the lit.site.cfg if we are in some kind of fresh
+# build situation. This means knowing how to invoke the build system
+# though, and I decided it was too much magic.
+
+llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
+if not llvm_config:
+lit_config.fatal('No site specific configuration available!')
+
+# Get the source and object roots.
+llvm_src_root = subprocess.check_output(['llvm-config', 
'--src-root']).strip()
+llvm_obj_root = subprocess.check_output(['llvm-config', 
'--obj-root']).strip()
+clang_src_root = os.path.join(llvm_src_root, "tools", "clang")
+clang_obj_root = os.path.join(llvm_obj_root, "tools", "clang")
+
+# Validate that we got a tree which points to here, using the standard
+# tools/clang layout.
+this_src_root = os.path.join(os.path.dirname(__file__),'..','..')
+if os.path.realpath(clang_src_root) != os.path.realpath(this_src_root):
+lit_config.fatal('No site specific configuration available!')
+
+# Check that the site specific configuration exists.
+site_cfg = os.path.join(clang_obj_root, 'test', 'Unit', 'lit.site.cfg')
+if not os.path.exists(site_cfg):
+lit_config.fatal('No site specific configuration available!')
+
+# Okay, that worked. Notify the user of the automagic, and reconfigure.
+lit_config.note('using out-of-tree build at %r' % clang_obj_root)
+

[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 115349.
EricWF added a comment.

- Improve test.


https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp

Index: test/SemaCXX/source_location.cpp
===
--- /dev/null
+++ test/SemaCXX/source_location.cpp
@@ -0,0 +1,475 @@
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// expected-no-diagnostics
+
+#define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
+#define CURRENT_FROM_MACRO() SL::current()
+#define FORWARD(...) __VA_ARGS__
+
+namespace std {
+namespace experimental {
+struct source_location {
+private:
+  unsigned int __m_line = 0;
+  unsigned int __m_col = 0;
+  const char *__m_file = nullptr;
+  const char *__m_func = nullptr;
+public:
+  static constexpr source_location current(
+  const char *__file = __builtin_FILE(),
+  const char *__func = __builtin_FUNCTION(),
+  unsigned int __line = __builtin_LINE(),
+  unsigned int __col = __builtin_COLUMN()) noexcept {
+source_location __loc;
+__loc.__m_line = __line;
+__loc.__m_col = __col;
+__loc.__m_file = __file;
+__loc.__m_func = __func;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_line; }
+  constexpr unsigned int column() const noexcept { return __m_col; }
+  constexpr const char *file() const noexcept { return __m_file; }
+  constexpr const char *function() const noexcept { return __m_func; }
+};
+} // namespace experimental
+} // namespace std
+
+using SL = std::experimental::source_location;
+
+#include "Inputs/source-location-file.h"
+namespace SLF = source_location_file;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+template 
+constexpr T identity(T t) {
+  return t;
+}
+
+template 
+struct Pair {
+  T first;
+  U second;
+};
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+// test types
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+
+// test noexcept
+static_assert(noexcept(__builtin_LINE()));
+static_assert(noexcept(__builtin_COLUMN()));
+static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FUNCTION()));
+
+//===--===//
+//__builtin_LINE()
+//===--===//
+
+namespace test_line {
+
+static_assert(SL::current().line() == __LINE__);
+static_assert(SL::current().line() == CURRENT_FROM_MACRO().line());
+
+static constexpr SL GlobalS = SL::current();
+
+static_assert(GlobalS.line() == __LINE__ - 2);
+
+// clang-format off
+constexpr bool test_line_fn() {
+  constexpr SL S = SL::current();
+  static_assert(S.line() == (__LINE__ - 1), "");
+  // The start of the call expression to `current()` begins at the token `SL`
+  constexpr int ExpectLine = __LINE__ + 3;
+  constexpr SL S2
+  =
+  SL // Call expression starts here
+  ::
+  current
+  (
+
+  )
+  ;
+  static_assert(S2.line() == ExpectLine, "");
+
+  static_assert(
+  FORWARD(
+ __builtin_LINE
+(
+)
+  )
+== __LINE__ - 1, "");
+  static_assert(\
+\
+  __builtin_LINE()\
+\
+  == __LINE__ - 2, "");
+  static_assert(\
+  _\
+_builtin_LINE()
+  == __LINE__ - 2, "");
+
+  return 

[PATCH] D37035: Implement __builtin_LINE() et. al. to support source location capture.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF updated this revision to Diff 115342.
EricWF marked 8 inline comments as done.
EricWF added a comment.

- Cleanup and address the inline comments I added earlier.


https://reviews.llvm.org/D37035

Files:
  docs/LanguageExtensions.rst
  include/clang/AST/Expr.h
  include/clang/AST/ExprCXX.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/Stmt.h
  include/clang/Basic/StmtNodes.td
  include/clang/Basic/TokenKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprCXX.cpp
  lib/AST/ExprClassification.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/ItaniumMangle.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGExprComplex.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Parse/ParseExpr.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExceptionSpec.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/CodeGenCXX/builtin_FUNCTION.cpp
  test/CodeGenCXX/builtin_LINE.cpp
  test/CodeGenCXX/debug-info-line.cpp
  test/Parser/builtin_source_location.c
  test/Sema/source_location.c
  test/SemaCXX/Inputs/source-location-file.h
  test/SemaCXX/source_location.cpp

Index: test/SemaCXX/source_location.cpp
===
--- /dev/null
+++ test/SemaCXX/source_location.cpp
@@ -0,0 +1,475 @@
+// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify %s
+// expected-no-diagnostics
+
+#define assert(...) ((__VA_ARGS__) ? ((void)0) : throw 42)
+#define CURRENT_FROM_MACRO() SL::current()
+#define FORWARD(...) __VA_ARGS__
+
+namespace std {
+namespace experimental {
+struct source_location {
+private:
+  unsigned int __m_line = 0;
+  unsigned int __m_col = 0;
+  const char *__m_file = nullptr;
+  const char *__m_func = nullptr;
+public:
+  static constexpr source_location current(
+  const char *__file = __builtin_FILE(),
+  const char *__func = __builtin_FUNCTION(),
+  unsigned int __line = __builtin_LINE(),
+  unsigned int __col = __builtin_COLUMN()) noexcept {
+source_location __loc;
+__loc.__m_line = __line;
+__loc.__m_col = __col;
+__loc.__m_file = __file;
+__loc.__m_func = __func;
+return __loc;
+  }
+  constexpr source_location() = default;
+  constexpr source_location(source_location const &) = default;
+  constexpr unsigned int line() const noexcept { return __m_line; }
+  constexpr unsigned int column() const noexcept { return __m_col; }
+  constexpr const char *file() const noexcept { return __m_file; }
+  constexpr const char *function() const noexcept { return __m_func; }
+};
+} // namespace experimental
+} // namespace std
+
+using SL = std::experimental::source_location;
+
+#include "Inputs/source-location-file.h"
+namespace SLF = source_location_file;
+
+constexpr bool is_equal(const char *LHS, const char *RHS) {
+  while (*LHS != 0 && *RHS != 0) {
+if (*LHS != *RHS)
+  return false;
+++LHS;
+++RHS;
+  }
+  return *LHS == 0 && *RHS == 0;
+}
+
+template 
+constexpr T identity(T t) {
+  return t;
+}
+
+template 
+struct Pair {
+  T first;
+  U second;
+};
+
+template 
+constexpr bool is_same = false;
+template 
+constexpr bool is_same = true;
+
+// test types
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+static_assert(is_same);
+
+// test noexcept
+static_assert(noexcept(__builtin_LINE()));
+static_assert(noexcept(__builtin_COLUMN()));
+static_assert(noexcept(__builtin_FILE()));
+static_assert(noexcept(__builtin_FUNCTION()));
+
+//===--===//
+//__builtin_LINE()
+//===--===//
+
+namespace test_line {
+
+static_assert(SL::current().line() == __LINE__);
+static_assert(SL::current().line() == CURRENT_FROM_MACRO().line());
+
+static constexpr SL GlobalS = SL::current();
+
+static_assert(GlobalS.line() == __LINE__ - 2);
+
+// clang-format off
+constexpr bool test_line_fn() {
+  constexpr SL S = SL::current();
+  static_assert(S.line() == (__LINE__ - 1), "");
+  // The start of the call expression to `current()` begins at the token `SL`
+  constexpr int ExpectLine = __LINE__ + 3;
+  constexpr SL S2
+  =
+  SL // Call expression starts here
+  ::
+  current
+  (
+
+  )
+  ;
+  static_assert(S2.line() == ExpectLine, "");
+
+  static_assert(
+  FORWARD(
+ __builtin_LINE
+(
+)
+  )
+== __LINE__ - 1, "");
+  static_assert(\
+\
+  __builtin_LINE()\
+\
+  == __LINE__ - 2, "");
+  

[PATCH] D37538: [libc++] Remove problematic ADL in container implementations.

2017-09-14 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

dlj and I discussed this offline somewhat, and dlj made the interesting point 
that using ADL *at all* within the implementation of the standard library 
brings with it the risk that your implementation will not function correctly if 
a user-declared operator could be at least as good a match as your intended 
callee.

As an example, consider: https://godbolt.org/g/rgFTME -- as far as I can see, 
that code follows all the rules for safe and correct use of the C++ standard 
library. And yet it does not compile with either libc++ or libstdc++, because 
both internally use ADL to find the `operator!=` for `vector::iterator` within 
their implementation of `vector::erase`. Any ADL call seems likely to suffer 
from this problem; moreover, you can observe that `vector::iterator` fails 
to even satisfy the input iterator requirements, because `a != b` is not a 
valid expression for iterators `a` and `b`.

I think the above example is actually demonstrating a bug in the standard: such 
user code is unreasonable and it's not sensible to expect the standard library 
to cope with it.


https://reviews.llvm.org/D37538



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


[PATCH] D37881: [Sema] Prevent InstantiateClass from checking unrelated exception specs.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

I don't like name `SavePendingDelayedStateRAII` as too vague. Hope you'll be 
able to suggest something better or I'll have better ideas later.


https://reviews.llvm.org/D37881



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


[PATCH] D37881: [Sema] Prevent InstantiateClass from checking unrelated exception specs.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.

Sema::InstantiateClass should check only exception specs added during
class instantiation and ignore already present delayed specs. This fixes
a case where we instantiate a class before parsing member initializers,
check exceptions for a different class and fail to find a member
initializer. Which is required for comparing exception specs for
explicitly-defaulted and implicit default constructor. With the fix we
are still checking exception specs but only after member initializers
are present.

Removing errors in crash-unparsed-exception.cpp is acceptable according
to discussion in PR24000 because other compilers accept code in
crash-unparsed-exception.cpp as valid.

rdar://problem/34167492

Cc Dimitry Andric due to participation in discussion about PR24000.


https://reviews.llvm.org/D37881

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/crash-unparsed-exception.cpp
  clang/test/SemaTemplate/default-arguments-cxx0x.cpp

Index: clang/test/SemaTemplate/default-arguments-cxx0x.cpp
===
--- clang/test/SemaTemplate/default-arguments-cxx0x.cpp
+++ clang/test/SemaTemplate/default-arguments-cxx0x.cpp
@@ -87,3 +87,30 @@
 A<1> m_target;
   };
 }
+
+// rdar://problem/34167492
+// Template B is instantiated during checking if defaulted A copy constructor
+// is constexpr. For this we check if S copy constructor is constexpr. And
+// for this we check S constructor template with default argument that mentions
+// template B. In  turn, template instantiation triggers checking defaulted
+// members exception spec. The problem is that it checks defaulted members not
+// for instantiated class only, but all defaulted members so far. In this case
+// we try to check exception spec for A default constructor which requires
+// initializer for the field _a. But initializers are added after constexpr
+// check so we reject the code because cannot find _a initializer.
+namespace rdar34167492 {
+  template  struct B { using type = bool; };
+
+  template  struct S {
+S() noexcept;
+
+template ::type = true>
+S(const S&) noexcept;
+  };
+
+  class A {
+A() noexcept = default;
+A(const A&) noexcept = default;
+S _a{};
+  };
+}
Index: clang/test/SemaTemplate/crash-unparsed-exception.cpp
===
--- clang/test/SemaTemplate/crash-unparsed-exception.cpp
+++ clang/test/SemaTemplate/crash-unparsed-exception.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify -fcxx-exceptions -fexceptions %s
+// expected-no-diagnostics
 
 struct A {
   virtual ~A();
@@ -11,7 +12,7 @@
 ~D() throw();
   };
   struct E : A {
-D d; //expected-error{{exception specification is not available until end of class definition}}
+D d;
   };
-  B b; //expected-note{{in instantiation of template class 'B' requested here}}
+  B b;
 };
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -2026,12 +2026,10 @@
   bool MergeWithParentScope = !Instantiation->isDefinedOutsideFunctionOrMethod();
   LocalInstantiationScope Scope(*this, MergeWithParentScope);
 
-  // All dllexported classes created during instantiation should be fully
-  // emitted after instantiation completes. We may not be ready to emit any
-  // delayed classes already on the stack, so save them away and put them back
-  // later.
-  decltype(DelayedDllExportClasses) ExportedClasses;
-  std::swap(ExportedClasses, DelayedDllExportClasses);
+  // Some delayed state created during instantiation should be fully processed
+  // after instantiation completes. We may not be ready to handle any delayed
+  // state already on the stack, so save it now and put it back later.
+  SavePendingDelayedStateRAII SavedPendingDelayedState(*this);
 
   // Pull attributes from the pattern onto the instantiation.
   InstantiateAttrs(TemplateArgs, Pattern, Instantiation);
@@ -2118,9 +2116,6 @@
   // default arg exprs for default constructors if necessary now.
   ActOnFinishCXXNonNestedClass(Instantiation);
 
-  // Put back the delayed exported classes that we moved out of the way.
-  std::swap(ExportedClasses, DelayedDllExportClasses);
-
   // Instantiate late parsed attributes, and attach them to their decls.
   // See Sema::InstantiateAttrs
   for (LateInstantiatedAttrVec::iterator I = LateAttrs.begin(),
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -10490,6 +10490,36 @@
   SmallVector DelayedDllExportClasses;
 
 private:
+  class SavePendingDelayedStateRAII {
+  public:
+SavePendingDelayedStateRAII(Sema ) : S(S) { swapSavedState(); }
+

[PATCH] D37089: [Sema] Error out early for tags defined inside an enumeration.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai marked an inline comment as done.
vsapsai added inline comments.



Comment at: clang/test/Sema/enum.c:128
+// PR28903
+struct PR28903 { // expected-warning {{empty struct is a GNU extension}}
+  enum {

rnk wrote:
> This is a simpler test case that fixes the extraneous diagnostics:
>   struct PR28903 {
> enum {
>   E1 = (enum {  // expected-error-re {{...}}
>   E2, E3 = E2
> })0
> } e;
>   };
> 
Removed extraneous diagnostics in slightly different way. Keep enum constants 
prefixed with PR28903 because in C struct doesn't create a scope for enum 
constants and I want to avoid polluting test namespace with common names like 
E1, E2, E3.


https://reviews.llvm.org/D37089



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


[PATCH] D37089: [Sema] Error out early for tags defined inside an enumeration.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai updated this revision to Diff 115333.
vsapsai added a comment.

- Remove extraneous diagnostics in test case per Reid Kleckner feedback.


https://reviews.llvm.org/D37089

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/enum.c
  clang/test/SemaCXX/enum.cpp


Index: clang/test/SemaCXX/enum.cpp
===
--- clang/test/SemaCXX/enum.cpp
+++ clang/test/SemaCXX/enum.cpp
@@ -110,3 +110,13 @@
 // expected-warning@-2 {{not an integral constant expression}}
 // expected-note@-3 {{value 28958703552 is outside the range of representable 
values}}
 #endif
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at 
{{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})
+  };
+};
Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -123,3 +123,14 @@
 // PR24610
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag 
type that does not match previous declaration}}
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'enum PR28903::(anonymous at 
{{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})0
+  };
+  int makeStructNonEmpty;
+};
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13928,6 +13928,12 @@
 Invalid = true;
   }
 
+  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
+Diag(New->getLocation(), diag::err_type_defined_in_enum)
+  << Context.getTagDeclType(New);
+Invalid = true;
+  }
+
   // Maybe add qualifier info.
   if (SS.isNotEmpty()) {
 if (SS.isSet()) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1333,6 +1333,8 @@
   "%0 cannot be defined in a type alias template">;
 def err_type_defined_in_condition : Error<
   "%0 cannot be defined in a condition">;
+def err_type_defined_in_enum : Error<
+  "%0 cannot be defined in an enumeration">;
 
 def note_pure_virtual_function : Note<
   "unimplemented pure virtual method %0 in %1">;


Index: clang/test/SemaCXX/enum.cpp
===
--- clang/test/SemaCXX/enum.cpp
+++ clang/test/SemaCXX/enum.cpp
@@ -110,3 +110,13 @@
 // expected-warning@-2 {{not an integral constant expression}}
 // expected-note@-3 {{value 28958703552 is outside the range of representable values}}
 #endif
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'PR28903::(anonymous enum at {{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})
+  };
+};
Index: clang/test/Sema/enum.c
===
--- clang/test/Sema/enum.c
+++ clang/test/Sema/enum.c
@@ -123,3 +123,14 @@
 // PR24610
 enum Color { Red, Green, Blue }; // expected-note{{previous use is here}}
 typedef struct Color NewColor; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}
+
+// PR28903
+struct PR28903 {
+  enum {
+PR28903_A = (enum { // expected-error-re {{'enum PR28903::(anonymous at {{.*}})' cannot be defined in an enumeration}}
+  PR28903_B,
+  PR28903_C = PR28903_B
+})0
+  };
+  int makeStructNonEmpty;
+};
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -13928,6 +13928,12 @@
 Invalid = true;
   }
 
+  if (!Invalid && TUK == TUK_Definition && DC->getDeclKind() == Decl::Enum) {
+Diag(New->getLocation(), diag::err_type_defined_in_enum)
+  << Context.getTagDeclType(New);
+Invalid = true;
+  }
+
   // Maybe add qualifier info.
   if (SS.isNotEmpty()) {
 if (SS.isSet()) {
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1333,6 +1333,8 @@
   "%0 cannot be defined in a type alias template">;
 def err_type_defined_in_condition : Error<
   "%0 cannot be defined in a condition">;
+def err_type_defined_in_enum : Error<
+  "%0 cannot be defined in an enumeration">;
 
 def note_pure_virtual_function : Note<
   "unimplemented pure virtual method %0 in %1">;
___
cfe-commits mailing 

[PATCH] D37538: [libc++] Remove problematic ADL in container implementations.

2017-09-14 Thread David L. Jones via Phabricator via cfe-commits
dlj added a comment.

In https://reviews.llvm.org/D37538#871515, @EricWF wrote:

> @dlj I went ahead and committed the fixes to `std::allocator_traits` in 
> r313324, because I think we agree those are bugs, and I didn't want this 
> discussion to hold up that fix. I hope you don't mind.


Nope, not a problem.


https://reviews.llvm.org/D37538



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


[PATCH] D37308: Fix the __interface inheritence rules to work better with IUnknown and IDispatch

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

lgtm


https://reviews.llvm.org/D37308



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


[PATCH] D37538: [libc++] Remove problematic ADL in container implementations.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

@dlj I went ahead and committed the fixes to `std::allocator_traits` in 
r313324, because I think we agree those are bugs, and I didn't want this 
discussion to hold up that fix. I hope you don't mind.


https://reviews.llvm.org/D37538



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


[libcxx] r313324 - Fix accidental ADL in std::allocator_traits meta-programming.

2017-09-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 14 17:31:38 2017
New Revision: 313324

URL: http://llvm.org/viewvc/llvm-project?rev=313324=rev
Log:
Fix accidental ADL in std::allocator_traits meta-programming.

There were a number of cases where __double_underscore functions,
for example __has_construct_test, were called without being qualified,
causing ADL to occur. This patch qualifies those calls to avoid this
problem.

Thanks to David L. Jones for point out the issue initially.

Added:

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/incomplete_type_helper.h
Modified:
libcxx/trunk/include/memory

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/deallocate.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/max_size.pass.cpp

libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp

Modified: libcxx/trunk/include/memory
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=313324=313323=313324=diff
==
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Thu Sep 14 17:31:38 2017
@@ -1302,7 +1302,7 @@ struct __allocator_traits_rebind<_Alloc<
 template 
 auto
 __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
--> decltype(__a.allocate(__sz, __p), true_type());
+-> decltype((void)__a.allocate(__sz, __p), true_type());
 
 template 
 auto
@@ -1313,7 +1313,7 @@ template (),
+decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
   declval<_SizeType>(),
   declval<_ConstVoidPtr>())),
 true_type>::value>
@@ -1346,7 +1346,7 @@ template (),
+decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
   declval<_Pointer>(),
   declval<_Args>()...)),
 true_type>::value>
@@ -1367,7 +1367,7 @@ template 
 struct __has_destroy
 : integral_constant(),
+decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
 declval<_Pointer>())),
 true_type>::value>
 {
@@ -1387,7 +1387,7 @@ template 
 struct __has_max_size
 : integral_constant())),
+decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
 true_type>::value>
 {
 };
@@ -1406,7 +1406,7 @@ template 
 struct __has_select_on_container_copy_construction
 : integral_constant())),
+
decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
 true_type>::value>
 {
 };

Modified: 
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp?rev=313324=313323=313324=diff
==
--- 
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate.pass.cpp
 Thu Sep 14 17:31:38 2017
@@ -20,6 +20,8 @@
 #include 
 #include 
 
+#include "incomplete_type_helper.h"
+
 template 
 struct A
 {
@@ -34,6 +36,14 @@ struct A
 
 int main()
 {
+  {
 A a;
 assert(std::allocator_traits::allocate(a, 10) == 
reinterpret_cast(static_cast(0xDEADBEEF)));
+  }
+  {
+typedef IncompleteHolder* VT;
+typedef A Alloc;
+Alloc a;
+assert(std::allocator_traits::allocate(a, 10) == 
reinterpret_cast(static_cast(0xDEADBEEF)));
+  }
 }

Modified: 
libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/allocator.traits/allocator.traits.members/allocate_hint.pass.cpp?rev=313324=313323=313324=diff
==
--- 

[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd updated this revision to Diff 115326.

https://reviews.llvm.org/D28212

Files:
  include/typeinfo
  src/support/runtime/exception_msvc.ipp
  src/typeinfo.cpp

Index: src/typeinfo.cpp
===
--- src/typeinfo.cpp
+++ src/typeinfo.cpp
@@ -9,11 +9,48 @@

 #include "typeinfo"

+#if defined(_LIBCPP_ABI_MICROSOFT)
+#include 
+
+int std::type_info::__compare(const struct type_info &__rhs) {
+  if (&__data == &__rhs.__data)
+return 0;
+  return strcmp(&__data.__decorated_name[1], &__rhs.__data.__decorated_name[1]);
+}
+
+const char *std::type_info::name() _NOEXCEPT {
+  // TODO(compnerd) cache demangled &__data.__decorated_name[1]
+  return &__data.__decorated_name[1];
+}
+
+size_t std::type_info::hash_code() const _NOEXCEPT {
+#if defined(_WIN64)
+  constexpr size_t fnv_offset_basis = 14695981039346656037ull;
+  constexpr size_t fnv_prime = 10995116282110ull;
+#else
+  constexpr size_t fnv_offset_basis = 2166136261ull;
+  constexpr size_t fnv_prime = 16777619ull;
+#endif
+
+  size_t value = fnv_offset_basis;
+  for (const char* c = &__data->__decorated_name[1]; *c; ++c) {
+value ^= static_cast(static_cast(*c));
+value *= fnv_prime;
+  }
+
+#if defined(_WIN64)
+  value ^= value >> 32;
+#endif
+
+  return value;
+}
+#endif // _LIBCPP_ABI_MICROSOFT
+
 // FIXME: Remove __APPLE__ default here once buildit is gone.
-#if (!defined(_LIBCPP_ABI_MICROSOFT) && !defined(LIBCXX_BUILDING_LIBCXXABI) && \
-!defined(LIBCXXRT) && !defined(__GLIBCXX__) && \
-!defined(__APPLE__)) || \
-defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY) // FIXME: remove this configuration.
+// FIXME: Remove the _LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY configuration.
+#if (!defined(LIBCXX_BUILDING_LIBCXXABI) && !defined(LIBCXXRT) &&  \
+ !defined(__GLIBCXX__) && !defined(__APPLE__)) ||  \
+defined(_LIBCPP_BUILDING_HAS_NO_ABI_LIBRARY)
 std::type_info::~type_info()
 {
 }
Index: src/support/runtime/exception_msvc.ipp
===
--- src/support/runtime/exception_msvc.ipp
+++ src/support/runtime/exception_msvc.ipp
@@ -86,4 +86,32 @@
 return "bad_array_length";
 }

+bad_cast::bad_cast() _NOEXCEPT
+{
+}
+
+bad_cast::~bad_cast() _NOEXCEPT
+{
+}
+
+const char *
+bad_cast::what() const _NOEXCEPT
+{
+  return "std::bad_cast";
+}
+
+bad_typeid::bad_typeid() _NOEXCEPT
+{
+}
+
+bad_typeid::~bad_typeid() _NOEXCEPT
+{
+}
+
+const char *
+bad_typeid::what() const _NOEXCEPT
+{
+  return "std::bad_typeid";
+}
+
 } // namespace std
Index: include/typeinfo
===
--- include/typeinfo
+++ include/typeinfo
@@ -69,18 +69,17 @@
 #pragma GCC system_header
 #endif

-#if defined(_LIBCPP_ABI_MICROSOFT)
-#include 
-#elif defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
+#if !defined(_LIBCPP_ABI_MICROSOFT)
+#if defined(_LIBCPP_NONUNIQUE_RTTI_BIT)
 #define _LIBCPP_HAS_NONUNIQUE_TYPEINFO
 #else
 #define _LIBCPP_HAS_UNIQUE_TYPEINFO
 #endif
+#endif

 namespace std  // purposefully not using versioning namespace
 {

-#if !defined(_LIBCPP_ABI_MICROSOFT)
 class _LIBCPP_EXCEPTION_ABI type_info
 {
 type_info& operator=(const type_info&);
@@ -92,7 +91,17 @@
 { return __builtin_strcmp(name(), __arg.name()); }
 #endif

+#if defined(_LIBCPP_ABI_MICROSOFT)
+mutable struct {
+  const char *__undecorated_name;
+  const char __decorated_name[1];
+} __data;
+
+int __compare(const struct type_info &__rhs);
+#endif // _LIBCPP_ABI_MICROSOFT
+
 protected:
+#if !defined(_LIBCPP_ABI_MICROSOFT)
 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
 // A const char* with the non-unique RTTI bit possibly set.
 uintptr_t __type_name;
@@ -106,11 +115,27 @@
 _LIBCPP_INLINE_VISIBILITY
 explicit type_info(const char* __n) : __type_name(__n) {}
 #endif
+#endif // ! _LIBCPP_ABI_MICROSOFT

 public:
 _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
 virtual ~type_info();

+#if defined(_LIBCPP_ABI_MICROSOFT)
+const char *name() const _NOEXCEPT;
+
+_LIBCPP_INLINE_VISIBILITY
+bool before(const type_info& __arg) const _NOEXCEPT {
+  return __compare(__arg) < 0;
+}
+
+size_t hash_code() const _NOEXCEPT;
+
+_LIBCPP_INLINE_VISIBILITY
+bool operator==(const type_info& __arg) const _NOEXCEPT {
+  return __compare(__arg) == 0;
+}
+#else
 #if defined(_LIBCPP_HAS_NONUNIQUE_TYPEINFO)
 _LIBCPP_INLINE_VISIBILITY
 const char* name() const _NOEXCEPT
@@ -167,6 +192,7 @@
 bool operator==(const type_info& __arg) const _NOEXCEPT
 { return __type_name == __arg.__type_name; }
 #endif
+#endif // _LIBCPP_ABI_MICROSOFT

 _LIBCPP_INLINE_VISIBILITY
 bool operator!=(const type_info& __arg) const _NOEXCEPT
@@ -191,8 +217,6 @@
 virtual const char* what() const _NOEXCEPT;
 };

-#endif // !_LIBCPP_ABI_MICROSOFT
-
 }  // std

 _LIBCPP_BEGIN_NAMESPACE_STD
___
cfe-commits mailing 

[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd commandeered this revision.
compnerd edited reviewers, added: smeenai; removed: compnerd.
compnerd added inline comments.



Comment at: include/typeinfo:100
+
+  static const char *__name(const struct type_info::__data *__data);
+  static size_t __hash(const struct type_info::__data *__data);

EricWF wrote:
> These should probably have `_LIBCPP_FUNC_VIS` visibility declarations 
> attached to them.
Wont bother due to out-of-line definition



Comment at: include/typeinfo:101
+  static const char *__name(const struct type_info::__data *__data);
+  static size_t __hash(const struct type_info::__data *__data);
+  static int __compare(const struct type_info::__data* __lls,

EricWF wrote:
> Is there a reason why `__name` and `__hash` need wrappers? Can't we just 
> provide out-of-line definitions for `name()` and `hash_code()` directly?
I don't remember why ... we can address that when we hit it.  Going to 
out-of-line them.



Comment at: include/typeinfo:200
 #endif
+#endif
 

EricWF wrote:
> Comment on `#endif` please.
Sure!



Comment at: include/typeinfo:109
 protected:
+#if defined(_LIBCPP_HAS_MS_ABI_TYPEINFO)
+#else

smeenai wrote:
> compnerd wrote:
> > EricWF wrote:
> > > Don't we need a constructor here?
> > No, we do not need a constructor since the emitted object is already a well 
> > formed object instance.
> I believe @EricWF was referring to the internal constructors that take a 
> `const char *`. Do we need one of those for the Microsoft typeinfo?
No, no such constructor is needed with MS ABI AFAIK.  Construction of the type 
does not invoke a constructor and libc++ does not create instances of this.



Comment at: src/typeinfo.cpp:28-32
+  static constexpr const size_t fnv_offset_basis = 14695981039346656037;
+  static constexpr const size_t fnv_prime = 10995116282110;
+#else
+  static constexpr const size_t fnv_offset_basis = 2166136261;
+  static constexpr const size_t fnv_prime = 16777619;

EricWF wrote:
> compnerd wrote:
> > rnk wrote:
> > > compnerd wrote:
> > > > majnemer wrote:
> > > > > majnemer wrote:
> > > > > > Why make these static? Seems strange to use that storage duration.
> > > > > These literals are ill-formed, I think you need a ULL suffix here.
> > > > Oh, just to ensure that they are handled as literal constants.  I can 
> > > > drop the static if you like, since the compiler should do the right 
> > > > thing anyways.
> > > Isn't `constexpr const` redundant?
> > Yeah, intentional.  I should be using `_LIBCPP_CONSTEXPR` just incase the 
> > compiler doesn't support constexpr.
> All supported compiler provide `constexpr` when building the dylib, so you 
> can assume we have it.
> 
> I have no strong objection to the redundancy, but I'm not opposed to removing 
> either `const` or `constexpr`.
Removed `static` and `const`.


https://reviews.llvm.org/D28212



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


[PATCH] D37322: [Sema] Correct typos in LHS, RHS before building a binop expression.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Thanks for the review.


Repository:
  rL LLVM

https://reviews.llvm.org/D37322



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


[PATCH] D37322: [Sema] Correct typos in LHS, RHS before building a binop expression.

2017-09-14 Thread Volodymyr Sapsai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313323: [Sema] Correct typos in LHS, RHS before building a 
binop expression. (authored by vsapsai).

Changed prior to commit:
  https://reviews.llvm.org/D37322?vs=113348=115323#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37322

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/SemaObjC/typo-correction.m
  cfe/trunk/test/SemaObjCXX/typo-correction.mm

Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -11269,6 +11269,26 @@
   return nullptr;
 }
 
+static std::pair
+CorrectDelayedTyposInBinOp(Sema , BinaryOperatorKind Opc, Expr *LHSExpr,
+   Expr *RHSExpr) {
+  ExprResult LHS = LHSExpr, RHS = RHSExpr;
+  if (!S.getLangOpts().CPlusPlus) {
+// C cannot handle TypoExpr nodes on either side of a binop because it
+// doesn't handle dependent types properly, so make sure any TypoExprs have
+// been dealt with before checking the operands.
+LHS = S.CorrectDelayedTyposInExpr(LHS);
+RHS = S.CorrectDelayedTyposInExpr(RHS, [Opc, LHS](Expr *E) {
+  if (Opc != BO_Assign)
+return ExprResult(E);
+  // Avoid correcting the RHS to the same Expr as the LHS.
+  Decl *D = getDeclFromExpr(E);
+  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
+});
+  }
+  return std::make_pair(LHS, RHS);
+}
+
 /// CreateBuiltinBinOp - Creates a new built-in binary operation with
 /// operator @p Opc at location @c TokLoc. This routine only supports
 /// built-in operations; ActOnBinOp handles overloaded operators.
@@ -11301,21 +11321,9 @@
   ExprValueKind VK = VK_RValue;
   ExprObjectKind OK = OK_Ordinary;
 
-  if (!getLangOpts().CPlusPlus) {
-// C cannot handle TypoExpr nodes on either side of a binop because it
-// doesn't handle dependent types properly, so make sure any TypoExprs have
-// been dealt with before checking the operands.
-LHS = CorrectDelayedTyposInExpr(LHSExpr);
-RHS = CorrectDelayedTyposInExpr(RHSExpr, [Opc, LHS](Expr *E) {
-  if (Opc != BO_Assign)
-return ExprResult(E);
-  // Avoid correcting the RHS to the same Expr as the LHS.
-  Decl *D = getDeclFromExpr(E);
-  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
-});
-if (!LHS.isUsable() || !RHS.isUsable())
-  return ExprError();
-  }
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
 
   if (getLangOpts().OpenCL) {
 QualType LHSTy = LHSExpr->getType();
@@ -11729,6 +11737,13 @@
 ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc,
 BinaryOperatorKind Opc,
 Expr *LHSExpr, Expr *RHSExpr) {
+  ExprResult LHS, RHS;
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
+  LHSExpr = LHS.get();
+  RHSExpr = RHS.get();
+
   // We want to end up calling one of checkPseudoObjectAssignment
   // (if the LHS is a pseudo-object), BuildOverloadedBinOp (if
   // both expressions are overloadable or either is type-dependent),
Index: cfe/trunk/test/SemaObjCXX/typo-correction.mm
===
--- cfe/trunk/test/SemaObjCXX/typo-correction.mm
+++ cfe/trunk/test/SemaObjCXX/typo-correction.mm
@@ -36,3 +36,22 @@
   float a = ((InvalidNameInIvarAndPropertyBase*)node)->_a; // expected-error {{use of undeclared identifier 'node'}}
   float b = ((InvalidNameInIvarAndPropertyBase*)node)._b; // expected-error {{use of undeclared identifier 'node'}}
 }
+
+// rdar://problem/33102722
+// Typo correction for a property when it has as correction candidates
+// synthesized ivar and a class name, both at the same edit distance.
+@class TypoCandidate;
+
+@interface PropertyType : NSObject
+@property int x;
+@end
+
+@interface InterfaceC : NSObject
+@property(assign) PropertyType *typoCandidate; // expected-note {{'_typoCandidate' declared here}}
+@end
+
+@implementation InterfaceC
+-(void)method {
+  typoCandidate.x = 0; // expected-error {{use of undeclared identifier 'typoCandidate'; did you mean '_typoCandidate'?}}
+}
+@end
Index: cfe/trunk/test/SemaObjC/typo-correction.m
===
--- cfe/trunk/test/SemaObjC/typo-correction.m
+++ cfe/trunk/test/SemaObjC/typo-correction.m
@@ -51,3 +51,23 @@
 }
 @end
 
+// rdar://problem/33102722
+// Typo correction for a property when it has as correction candidates
+// synthesized ivar and a class name, both at the same edit distance.
+@class TypoCandidate;
+
+__attribute__ (( __objc_root_class__ ))
+@interface PropertyType
+@property int x;
+@end
+
+__attribute__ (( __objc_root_class__ 

r313323 - [Sema] Correct typos in LHS, RHS before building a binop expression.

2017-09-14 Thread Volodymyr Sapsai via cfe-commits
Author: vsapsai
Date: Thu Sep 14 17:08:37 2017
New Revision: 313323

URL: http://llvm.org/viewvc/llvm-project?rev=313323=rev
Log:
[Sema] Correct typos in LHS, RHS before building a binop expression.

Specifically, typo correction should be done before dispatching between
different kinds of binary operations like pseudo-object assignment,
overloaded binary operation, etc.

Without this change we hit an assertion

Assertion failed: 
(!LHSExpr->hasPlaceholderType(BuiltinType::PseudoObject)), function 
CheckAssignmentOperands

when in Objective-C we reference a property without `self` and there are
2 equally good typo correction candidates: ivar and a class name. In
this case LHS expression in `BuildBinOp` is

CXXDependentScopeMemberExpr
`-TypoExpr

and instead of handling Obj-C property assignment as pseudo-object
assignment, we call `CreateBuiltinBinOp` which corrects typo to

ObjCPropertyRefExpr ''

but cannot handle pseudo-objects and asserts about it (indirectly,
through `CheckAssignmentOperands`).

rdar://problem/33102722

Reviewers: rsmith, ahatanak, majnemer

Reviewed By: ahatanak

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaObjC/typo-correction.m
cfe/trunk/test/SemaObjCXX/typo-correction.mm

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=313323=313322=313323=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 14 17:08:37 2017
@@ -11269,6 +11269,26 @@ static NamedDecl *getDeclFromExpr(Expr *
   return nullptr;
 }
 
+static std::pair
+CorrectDelayedTyposInBinOp(Sema , BinaryOperatorKind Opc, Expr *LHSExpr,
+   Expr *RHSExpr) {
+  ExprResult LHS = LHSExpr, RHS = RHSExpr;
+  if (!S.getLangOpts().CPlusPlus) {
+// C cannot handle TypoExpr nodes on either side of a binop because it
+// doesn't handle dependent types properly, so make sure any TypoExprs have
+// been dealt with before checking the operands.
+LHS = S.CorrectDelayedTyposInExpr(LHS);
+RHS = S.CorrectDelayedTyposInExpr(RHS, [Opc, LHS](Expr *E) {
+  if (Opc != BO_Assign)
+return ExprResult(E);
+  // Avoid correcting the RHS to the same Expr as the LHS.
+  Decl *D = getDeclFromExpr(E);
+  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
+});
+  }
+  return std::make_pair(LHS, RHS);
+}
+
 /// CreateBuiltinBinOp - Creates a new built-in binary operation with
 /// operator @p Opc at location @c TokLoc. This routine only supports
 /// built-in operations; ActOnBinOp handles overloaded operators.
@@ -11301,21 +11321,9 @@ ExprResult Sema::CreateBuiltinBinOp(Sour
   ExprValueKind VK = VK_RValue;
   ExprObjectKind OK = OK_Ordinary;
 
-  if (!getLangOpts().CPlusPlus) {
-// C cannot handle TypoExpr nodes on either side of a binop because it
-// doesn't handle dependent types properly, so make sure any TypoExprs have
-// been dealt with before checking the operands.
-LHS = CorrectDelayedTyposInExpr(LHSExpr);
-RHS = CorrectDelayedTyposInExpr(RHSExpr, [Opc, LHS](Expr *E) {
-  if (Opc != BO_Assign)
-return ExprResult(E);
-  // Avoid correcting the RHS to the same Expr as the LHS.
-  Decl *D = getDeclFromExpr(E);
-  return (D && D == getDeclFromExpr(LHS.get())) ? ExprError() : E;
-});
-if (!LHS.isUsable() || !RHS.isUsable())
-  return ExprError();
-  }
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, 
RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
 
   if (getLangOpts().OpenCL) {
 QualType LHSTy = LHSExpr->getType();
@@ -11729,6 +11737,13 @@ static ExprResult BuildOverloadedBinOp(S
 ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc,
 BinaryOperatorKind Opc,
 Expr *LHSExpr, Expr *RHSExpr) {
+  ExprResult LHS, RHS;
+  std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, 
RHSExpr);
+  if (!LHS.isUsable() || !RHS.isUsable())
+return ExprError();
+  LHSExpr = LHS.get();
+  RHSExpr = RHS.get();
+
   // We want to end up calling one of checkPseudoObjectAssignment
   // (if the LHS is a pseudo-object), BuildOverloadedBinOp (if
   // both expressions are overloadable or either is type-dependent),

Modified: cfe/trunk/test/SemaObjC/typo-correction.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/typo-correction.m?rev=313323=313322=313323=diff
==
--- cfe/trunk/test/SemaObjC/typo-correction.m (original)
+++ cfe/trunk/test/SemaObjC/typo-correction.m Thu Sep 14 17:08:37 2017
@@ -51,3 +51,23 @@ __attribute__ (( __objc_root_class__ ))
 }
 @end
 
+// 

[PATCH] D37538: [libc++] Remove problematic ADL in container implementations.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added inline comments.



Comment at: include/deque:1167-1168
 allocator_type& __a = __alloc();
-for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
-__alloc_traits::destroy(__a, _VSTD::addressof(*__i));
+for (iterator __i = begin(), __e = end(); __i.__ptr_ != __e.__ptr_; 
__i.operator++())
+__alloc_traits::destroy(__a, _VSTD::addressof(__i.operator*()));
 size() = 0;

dlj wrote:
> EricWF wrote:
> > rsmith wrote:
> > > The other changes all look like obvious improvements to me. This one is a 
> > > little more subtle, but if we want types like `deque > > *>` to be destructible, I think we need to do something equivalent to 
> > > this.
> > That's really yucky! I'm OK with this, but I really don't like it.
> > 
> > Fundamentally this can't work, at least not generically. When the allocator 
> > produces a fancy pointer type, the operator lookups need to be performed 
> > using ADL.
> > 
> > In this specific case, we control the iterator type, but this isn't always 
> > true. for example like in `__split_buffer`, which uses the allocators 
> > pointer type as an iterator.
> > 
> > @dlj I updated your test case to demonstrate the fancy-pointer problem: 
> > https://gist.github.com/EricWF/b465fc475f55561ba972b6dd87e7e7ea
> > 
> > So I think we have a couple choices:
> > 
> > (1) Do nothing, since we can't universally support the behavior, so we 
> > shouldn't attempt to support any form of this behavior.
> > (2) Fix only the non-fancy pointer case (which is what this patch does).
> > (3) Attempt to fix *all* cases, including the fancy-pointer ones. This 
> > won't be possible, but perhaps certain containers can tolerate incomplete 
> > fancy pointers?
> > 
> > Personally I'm leaning towards (1), since we can't claim to support the use 
> > case, at least not universally. If we select (1) we should probably encode 
> > the restriction formally in standardese.
> > 
> > 
> So I think there are at least a couple of issues here, but first I want to 
> get clarification on this point:
> 
> > Do nothing, since we can't universally support the behavior, so we 
> > shouldn't attempt to support any form of this behavior.
> 
> To me, this sounds like it could be equivalent to the statement "someone 
> might do a bad job of implementing type-erasure for fancy pointers, so we 
> should never attempt to preserve type erasure of any pointers." Now, that 
> statement seems tenuous //at best// (and a straw man on a slippery slope 
> otherwise), so I'm guessing that's not quite what you meant. ;-)
> 
> That said, it does sort of make sense to ignore deque for now, so I'll drop 
> it from the patch; but for other containers, I don't really see the argument.
> 
> As for #3: I'm able to make (most of) your gist pass for everything but 
> deque... calls to _VSTD::__to_raw_pointer are enough to avoid ADL around 
> operators, although a few other changes are needed, too. That probably makes 
> sense to do as a follow-up.
> 
> As for deque in particular, I think there may just be some missing functions 
> on the __deque_iterator, but it probably warrants a closer look before adding 
> to the interface.
> To me, this sounds like it could be equivalent to the statement "someone 
> might do a bad job of implementing type-erasure for fancy pointers, so we 
> should never attempt to preserve type erasure of any pointers." Now, that 
> statement seems tenuous at best (and a straw man on a slippery slope 
> otherwise), so I'm guessing that's not quite what you meant. ;-)

I'm not sure it's even possible to type-erase fancy pointers in a way your 
suggesting. Fundamentally I think they need to carry around the pointee type. 
So this problem isn't so easily explained away or made the fault of the user. 
Or am I missing something?

The library is allowed, and in this case required, to perform operator lookup 
via ADL. full stop.  That's how the STL is expected to interact with user 
types. Even after fixing the accidental ADL caused by `__foo` functions, we 
haven't and can't "fix" the rest. So now the question becomes "How far should 
libc++ go to avoid legal ADL lookup when it's possible"?

Whatever we decide, we are agreeing to "support" (or not support) a set of 
behavior, and I have a complex about claiming to "support" bizarre use cases 
like this. To support something we need to be able to (1) articulate exactly 
what behavior is supported, and (2) that the behavior won't regress.

I don't think we can provide guarantee (2) since future changes may require the 
use of ADL lookup in a way we can't avoid, for example in the same way that 
`__split_buffer` does. So that's a strike against the possibility of claiming 
"support".

One possibility is "The default constructor and destructor of containers X, Y, 
Z do not perform ADL lookup (Constructors A, B, C do not support this behavior) 
".  Admittedly it was easier than I thought to fix `__hash_table` 

r313320 - Fix reStructuredText warning.

2017-09-14 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Thu Sep 14 16:58:18 2017
New Revision: 313320

URL: http://llvm.org/viewvc/llvm-project?rev=313320=rev
Log:
Fix reStructuredText warning.

Modified:
cfe/trunk/docs/Modules.rst

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=313320=313319=313320=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Sep 14 16:58:18 2017
@@ -669,7 +669,7 @@ Note that, if ``Derived.h`` includes ``B
   all of them).
 
 Re-export Declaration
-~~
+~
 An *export-as-declaration* specifies that the current module will have
 its interface re-exported by the named module.
 


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


r313319 - [MSan] Specify use-after-dtor default value in header.

2017-09-14 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Thu Sep 14 16:53:56 2017
New Revision: 313319

URL: http://llvm.org/viewvc/llvm-project?rev=313319=rev
Log:
[MSan] Specify use-after-dtor default value in header.

Modified:
cfe/trunk/lib/Driver/SanitizerArgs.cpp

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=313319=313318=313319=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Sep 14 16:53:56 2017
@@ -491,9 +491,11 @@ SanitizerArgs::SanitizerArgs(const ToolC
 MsanUseAfterDtor =
 Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
  options::OPT_fno_sanitize_memory_use_after_dtor,
- false);
+ MsanUseAfterDtor);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
+  } else {
+MsanUseAfterDtor = false;
   }
 
   if (AllAddedKinds & Thread) {


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


[PATCH] D35388: [libc++] Give extern templates default visibility on gcc

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Filed https://bugs.llvm.org/show_bug.cgi?id=34614 about the silent attribute 
ignoring.


https://reviews.llvm.org/D35388



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


r313318 - Minor cleanups to address feedback from Bruno. NFC

2017-09-14 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Thu Sep 14 16:40:51 2017
New Revision: 313318

URL: http://llvm.org/viewvc/llvm-project?rev=313318=rev
Log:
Minor cleanups to address feedback from Bruno. NFC

Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=313318=313317=313318=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Sep 14 16:40:51 2017
@@ -670,22 +670,21 @@ Note that, if ``Derived.h`` includes ``B
 
 Re-export Declaration
 ~~
-An *export-as-declaration* specifies that the current module is a private
-module whose interface will be re-exported by the named public module.
+An *export-as-declaration* specifies that the current module will have
+its interface re-exported by the named module.
 
 .. parsed-literal::
 
   *export-as-declaration*:
 ``export_as`` *identifier*
 
-The *export-as-declaration* names the public module that the current
-(private) module will be re-exported through. Only top-level modules
+The *export-as-declaration* names the module that the current
+module will be re-exported through. Only top-level modules
 can be re-exported, and any given module may only be re-exported
-through a single public module.
+through a single module.
 
-**Example:** In the following example, the (private) module
-``MyFrameworkCore`` will be re-exported via the public module
-``MyFramework``:
+**Example:** In the following example, the module ``MyFrameworkCore``
+will be re-exported via the module ``MyFramework``:
 
 .. parsed-literal::
 

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=313318=313317=313318=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Sep 14 16:40:51 2017
@@ -2797,7 +2797,6 @@ void ASTWriter::WriteSubmodules(Module *
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));// Macro name
   unsigned ExportAsAbbrev = Stream.EmitAbbrev(std::move(Abbrev));
 
-
   // Write the submodule metadata block.
   RecordData::value_type Record[] = {
   getNumberOfModules(WritingModule),


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


r313315 - Diagnostic specific failed condition in a static_assert.

2017-09-14 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Thu Sep 14 16:38:42 2017
New Revision: 313315

URL: http://llvm.org/viewvc/llvm-project?rev=313315=rev
Log:
Diagnostic specific failed condition in a static_assert.

When a static_assert fails, dig out a specific condition to diagnose,
using the same logic that we use to find the enable_if condition to
diagnose.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/SemaCXX/static-assert.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=313315=313314=313315=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Sep 14 16:38:42 
2017
@@ -1219,6 +1219,8 @@ def warn_messaging_unqualified_id : Warn
 def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
 def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;
+def err_static_assert_requirement_failed : Error<
+  "static_assert failed due to requirement '%0'%select{ %2|}1">;
 def ext_static_assert_no_message : ExtWarn<
   "static_assert with no message is a C++17 extension">, InGroup;
 def warn_cxx14_compat_static_assert_no_message : Warning<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=313315=313314=313315=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Sep 14 16:38:42 2017
@@ -2783,6 +2783,14 @@ public:
   EnableIfAttr *CheckEnableIf(FunctionDecl *Function, ArrayRef Args,
   bool MissingImplicitThis = false);
 
+  /// Find the failed Boolean condition within a given Boolean
+  /// constant expression, and describe it with a string.
+  ///
+  /// \param AllowTopLevelCond Whether to allow the result to be the
+  /// complete top-level condition.
+  std::pair
+  findFailedBooleanCondition(Expr *Cond, bool AllowTopLevelCond);
+
   /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any
   /// non-ArgDependent DiagnoseIfAttrs.
   ///

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=313315=313314=313315=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep 14 16:38:42 2017
@@ -13296,8 +13296,20 @@ Decl *Sema::BuildStaticAssertDeclaration
   llvm::raw_svector_ostream Msg(MsgBuffer);
   if (AssertMessage)
 AssertMessage->printPretty(Msg, nullptr, getPrintingPolicy());
-  Diag(StaticAssertLoc, diag::err_static_assert_failed)
-<< !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
+
+  Expr *InnerCond = nullptr;
+  std::string InnerCondDescription;
+  std::tie(InnerCond, InnerCondDescription) =
+findFailedBooleanCondition(Converted.get(),
+   /*AllowTopLevelCond=*/false);
+  if (InnerCond) {
+Diag(StaticAssertLoc, diag::err_static_assert_requirement_failed)
+  << InnerCondDescription << !AssertMessage
+  << Msg.str() << InnerCond->getSourceRange();
+  } else {
+Diag(StaticAssertLoc, diag::err_static_assert_failed)
+  << !AssertMessage << Msg.str() << AssertExpr->getSourceRange();
+  }
   Failed = true;
 }
   }

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=313315=313314=313315=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Sep 14 16:38:42 2017
@@ -2863,11 +2863,9 @@ static Expr *lookThroughRangesV3Conditio
   return Cond;
 }
 
-/// Find the failed subexpression within enable_if, and describe it
-/// with a string.
-static std::pair
-findFailedEnableIfCondition(Sema , Expr *Cond) {
-  Cond = lookThroughRangesV3Condition(S.PP, Cond);
+std::pair
+Sema::findFailedBooleanCondition(Expr *Cond, bool AllowTopLevelCond) {
+  Cond = lookThroughRangesV3Condition(PP, Cond);
 
   // Separate out all of the terms in a conjunction.
   SmallVector Terms;
@@ -2876,27 +2874,37 @@ findFailedEnableIfCondition(Sema , Exp
   // Determine which term failed.
   Expr *FailedCond = nullptr;
   for (Expr *Term : Terms) {
+Expr *TermAsWritten = Term->IgnoreParenImpCasts();
+
+// Literals are uninteresting.
+if (isa(TermAsWritten) ||
+  

r313317 - Add /System/Library/PrivateFrameworks as a header search path.

2017-09-14 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Thu Sep 14 16:38:44 2017
New Revision: 313317

URL: http://llvm.org/viewvc/llvm-project?rev=313317=rev
Log:
Add /System/Library/PrivateFrameworks as a header search path.

Addresses rdar://problem/34438708.

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

Modified: cfe/trunk/lib/Frontend/InitHeaderSearch.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitHeaderSearch.cpp?rev=313317=313316=313317=diff
==
--- cfe/trunk/lib/Frontend/InitHeaderSearch.cpp (original)
+++ cfe/trunk/lib/Frontend/InitHeaderSearch.cpp Thu Sep 14 16:38:44 2017
@@ -484,6 +484,7 @@ void InitHeaderSearch::AddDefaultInclude
 if (triple.isOSDarwin()) {
   AddPath("/System/Library/Frameworks", System, true);
   AddPath("/Library/Frameworks", System, true);
+  AddPath("/System/Library/PrivateFrameworks", System, true);
 }
   }
 }


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


r313316 - [Module map] Introduce a private module re-export directive.

2017-09-14 Thread Douglas Gregor via cfe-commits
Author: dgregor
Date: Thu Sep 14 16:38:44 2017
New Revision: 313316

URL: http://llvm.org/viewvc/llvm-project?rev=313316=rev
Log:
[Module map] Introduce a private module re-export directive.

Introduce a new "export_as" directive for top-level modules, which
indicates that the current module is a "private" module whose symbols
will eventually be exported through the named "public" module. This is
in support of a common pattern in the Darwin ecosystem where a single
public framework is constructed of several private frameworks, with
(currently) header duplication and some support from the linker.

Addresses rdar://problem/34438420.

Added:
cfe/trunk/test/Modules/Inputs/export_as_test.modulemap
cfe/trunk/test/Modules/export_as_test.c
Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/Basic/Module.cpp
cfe/trunk/lib/Lex/ModuleMap.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=313316=313315=313316=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Sep 14 16:38:44 2017
@@ -323,11 +323,12 @@ Module map files use a simplified form o
 
 .. parsed-literal::
 
-  ``config_macros`` ``export`` ``private``
+  ``config_macros`` ``export_as``  ``private``
   ``conflict``  ``framework``  ``requires``
   ``exclude``   ``header`` ``textual``
   ``explicit``  ``link``   ``umbrella``
   ``extern````module`` ``use``
+  ``export``
 
 Module map file
 ---
@@ -387,6 +388,7 @@ Modules can have a number of different k
 *umbrella-dir-declaration*
 *submodule-declaration*
 *export-declaration*
+*export-as-declaration*
 *use-declaration*
 *link-declaration*
 *config-macros-declaration*
@@ -666,6 +668,31 @@ Note that, if ``Derived.h`` includes ``B
   compatibility for programs that rely on transitive inclusion (i.e.,
   all of them).
 
+Re-export Declaration
+~~
+An *export-as-declaration* specifies that the current module is a private
+module whose interface will be re-exported by the named public module.
+
+.. parsed-literal::
+
+  *export-as-declaration*:
+``export_as`` *identifier*
+
+The *export-as-declaration* names the public module that the current
+(private) module will be re-exported through. Only top-level modules
+can be re-exported, and any given module may only be re-exported
+through a single public module.
+
+**Example:** In the following example, the (private) module
+``MyFrameworkCore`` will be re-exported via the public module
+``MyFramework``:
+
+.. parsed-literal::
+
+  module MyFrameworkCore {
+export_as MyFramework
+  }
+
 Use declaration
 ~~~
 A *use-declaration* specifies another module that the current top-level module

Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=313316=313315=313316=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Sep 14 16:38:44 2017
@@ -674,6 +674,13 @@ def err_mmap_invalid_header_attribute_va
   "expected integer literal as value for header attribute '%0'">;
 def err_mmap_expected_header_attribute : Error<
   "expected a header attribute name ('size' or 'mtime')">;
+def err_mmap_conflicting_export_as : Error<
+  "conflicting re-export of module '%0' as '%1' or '%2'">;
+def warn_mmap_redundant_export_as : Warning<
+  "module '%0' already re-exported as '%1'">,
+  InGroup;
+def err_mmap_submodule_export_as : Error<
+  "only top-level modules can be re-exported as public">;
 
 def warn_auto_module_import : Warning<
   "treating #%select{include|import|include_next|__include_macros}0 as an "

Modified: cfe/trunk/include/clang/Basic/Module.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=313316=313315=313316=diff
==
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Thu Sep 14 16:38:44 2017
@@ -99,6 +99,10 @@ public:
 
   /// \brief The name of the umbrella entry, as written in the module map.
   std::string UmbrellaAsWritten;
+
+  /// \brief The module through which entities defined in this module will
+  /// eventually be exposed, for use in "private" modules.
+  std::string ExportAsModule;
   
 private:
   /// \brief The submodules of this module, indexed by name.

Modified: 

[PATCH] D35388: [libc++] Give extern templates default visibility on gcc

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

Good point. It looks like clang actually ignores the attributes in that case as 
well; it just doesn't warn you about it :D

Take a look at https://godbolt.org/g/CJTD6c to see what I mean. Note the 
`.hidden c::f()` in both the gcc and clang outputs.


https://reviews.llvm.org/D35388



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313314: [MSan] Add flag to disable use-after-dtor. (authored 
by morehouse).

Changed prior to commit:
  https://reviews.llvm.org/D37867?vs=115295=115317#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D37867

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/Driver/fsanitize.c


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -851,6 +851,9 @@
 def fsanitize_memory_use_after_dtor : Flag<["-"], 
"fsanitize-memory-use-after-dtor">,
  Group,
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,
+ HelpText<"Disable use-after-destroy 
detection in MemorySanitizer">;
 def fsanitize_address_field_padding : Joined<["-"], 
"fsanitize-address-field-padding=">,
 Group,
 HelpText<"Level of field padding for 
AddressSanitizer">;
Index: cfe/trunk/test/Driver/fsanitize.c
===
--- cfe/trunk/test/Driver/fsanitize.c
+++ cfe/trunk/test/Driver/fsanitize.c
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 
'-fsanitize-memory-track-origins=3'
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
+// CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -fno-sanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// CHECK-USE-AFTER-DTOR-OFF-NOT: -cc1{{.*}}memory-use-after-dtor
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-field-padding=0 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-FIELD-PADDING-0
 // CHECK-ASAN-FIELD-PADDING-0-NOT: -fsanitize-address-field-padding
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -830,7 +830,9 @@
   Opts.SanitizeMemoryTrackOrigins =
   getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, 
Diags);
   Opts.SanitizeMemoryUseAfterDtor =
-  Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
+  Args.hasFlag(OPT_fsanitize_memory_use_after_dtor,
+   OPT_fno_sanitize_memory_use_after_dtor,
+   false);
   Opts.SanitizeMinimalRuntime = Args.hasArg(OPT_fsanitize_minimal_runtime);
   Opts.SanitizeCfiCrossDso = Args.hasArg(OPT_fsanitize_cfi_cross_dso);
   Opts.SanitizeStats = Args.hasArg(OPT_fsanitize_stats);
Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -489,7 +489,9 @@
   }
 }
 MsanUseAfterDtor =
-Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor);
+Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   }


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ 

r313314 - [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Matt Morehouse via cfe-commits
Author: morehouse
Date: Thu Sep 14 16:14:37 2017
New Revision: 313314

URL: http://llvm.org/viewvc/llvm-project?rev=313314=rev
Log:
[MSan] Add flag to disable use-after-dtor.

Summary: Flag is -fno-sanitize-use-after-dtor.

Reviewers: vitalybuka, eugenis, kcc

Reviewed By: vitalybuka, eugenis

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/Driver/fsanitize.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=313314=313313=313314=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Sep 14 16:14:37 2017
@@ -851,6 +851,9 @@ def fno_sanitize_memory_track_origins :
 def fsanitize_memory_use_after_dtor : Flag<["-"], 
"fsanitize-memory-use-after-dtor">,
  Group,
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,
+ HelpText<"Disable use-after-destroy 
detection in MemorySanitizer">;
 def fsanitize_address_field_padding : Joined<["-"], 
"fsanitize-address-field-padding=">,
 Group,
 HelpText<"Level of field padding for 
AddressSanitizer">;

Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=313314=313313=313314=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Sep 14 16:14:37 2017
@@ -489,7 +489,9 @@ SanitizerArgs::SanitizerArgs(const ToolC
   }
 }
 MsanUseAfterDtor =
-Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor);
+Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   }

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=313314=313313=313314=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Sep 14 16:14:37 2017
@@ -830,7 +830,9 @@ static bool ParseCodeGenArgs(CodeGenOpti
   Opts.SanitizeMemoryTrackOrigins =
   getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, 
Diags);
   Opts.SanitizeMemoryUseAfterDtor =
-  Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
+  Args.hasFlag(OPT_fsanitize_memory_use_after_dtor,
+   OPT_fno_sanitize_memory_use_after_dtor,
+   false);
   Opts.SanitizeMinimalRuntime = Args.hasArg(OPT_fsanitize_minimal_runtime);
   Opts.SanitizeCfiCrossDso = Args.hasArg(OPT_fsanitize_cfi_cross_dso);
   Opts.SanitizeStats = Args.hasArg(OPT_fsanitize_stats);

Modified: cfe/trunk/test/Driver/fsanitize.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize.c?rev=313314=313313=313314=diff
==
--- cfe/trunk/test/Driver/fsanitize.c (original)
+++ cfe/trunk/test/Driver/fsanitize.c Thu Sep 14 16:14:37 2017
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 
'-fsanitize-memory-track-origins=3'
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
+// CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 

[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added a comment.

In https://reviews.llvm.org/D37860#871368, @eugenis wrote:

> Looking at __sanitizer_dtor_callback implementation, this change will add a 
> (fast) stack unwind in every destructor. In extreme cases (like a tight loop 
> doing string operations) it could be bad for performance. I've seen ~15% 
> AFAIR.


I haven't looked at performance, but I'll take a look at your internal bug.  
Until that is resolved, this can be on hold.


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse updated this revision to Diff 115312.
morehouse edited the summary of this revision.
morehouse added a comment.

- Move the new flag to https://reviews.llvm.org/D37867
- Address Vitaly's comments.


https://reviews.llvm.org/D37860

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/CodeGenCXX/sanitize-no-dtor-callback.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/test/msan/dtor-member.cc
  compiler-rt/test/msan/use-after-dtor.cc

Index: compiler-rt/test/msan/use-after-dtor.cc
===
--- compiler-rt/test/msan/use-after-dtor.cc
+++ compiler-rt/test/msan/use-after-dtor.cc
@@ -1,14 +1,17 @@
 // RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
 
 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
 
 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
+// RUN: FileCheck %s --check-prefix=CHECK-UAD < %t.out
 
 // RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
-// RUN: FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
+// RUN: FileCheck %s --check-prefixes=CHECK-UAD,CHECK-ORIGINS < %t.out
+
+// RUN: %clangxx_msan %s -fno-sanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-UAD-OFF < %t.out
 
 #include 
 #include 
@@ -32,14 +35,17 @@
   Simple *s = new() Simple();
   s->~Simple();
 
+  fprintf(stderr, "\n");  // Need output to parse for CHECK-UAD-OFF case
   return s->x_;
 
-  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-  // CHECK: {{#0 0x.* in main.*use-after-dtor.cc:}}[[@LINE-3]]
+  // CHECK-UAD: WARNING: MemorySanitizer: use-of-uninitialized-value
+  // CHECK-UAD: {{#0 0x.* in main.*use-after-dtor.cc:}}[[@LINE-3]]
+  // CHECK-UAD-OFF-NOT: WARNING: MemorySanitizer: use-of-uninitialized-value
 
   // CHECK-ORIGINS: Memory was marked as uninitialized
   // CHECK-ORIGINS: {{#0 0x.* in __sanitizer_dtor_callback}}
   // CHECK-ORIGINS: {{#1 0x.* in Simple::~Simple}}
 
-  // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*main}}
+  // CHECK-UAD: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*main}}
+  // CHECK-UAD-OFF-NOT: SUMMARY: MemorySanitizer: use-of-uninitialized-value
 }
Index: compiler-rt/test/msan/dtor-member.cc
===
--- compiler-rt/test/msan/dtor-member.cc
+++ compiler-rt/test/msan/dtor-member.cc
@@ -7,7 +7,7 @@
 // RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1  %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
 
-// RUN: %clangxx_msan %s -fsanitize=memory -o %t && MSAN_OPTIONS=poison_in_dtor=1  %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -fsanitize=memory -fno-sanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1  %run %t >%t.out 2>&1
 // RUN: FileCheck %s --check-prefix=CHECK-NO-FLAG < %t.out
 
 // RUN: %clangxx_msan -fsanitize=memory -fsanitize-memory-use-after-dtor %s -o %t && MSAN_OPTIONS=poison_in_dtor=0 %run %t >%t.out 2>&1
Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -174,11 +174,11 @@
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
 // CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-use-after-dtor -fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
 // CHECK-USE-AFTER-DTOR-OFF-NOT: -cc1{{.*}}memory-use-after-dtor
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 

[PATCH] D32520: Support __fp16 vectors

2017-09-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 115304.
ahatanak added a comment.

Rebase.


https://reviews.llvm.org/D32520

Files:
  include/clang/Sema/Sema.h
  lib/CodeGen/CGExprScalar.cpp
  lib/Sema/SemaExpr.cpp
  test/CodeGen/fp16vec-ops.c
  test/Sema/fp16vec-sema.c

Index: test/Sema/fp16vec-sema.c
===
--- /dev/null
+++ test/Sema/fp16vec-sema.c
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef __fp16 half4 __attribute__ ((vector_size (8)));
+typedef float float4 __attribute__ ((vector_size (16)));
+typedef short short4 __attribute__ ((vector_size (8)));
+typedef int int4 __attribute__ ((vector_size (16)));
+
+half4 hv0, hv1;
+float4 fv0, fv1;
+short4 sv0;
+int4 iv0;
+
+void testFP16Vec(int c) {
+  hv0 = hv0 + hv1;
+  hv0 = hv0 - hv1;
+  hv0 = hv0 * hv1;
+  hv0 = hv0 / hv1;
+  hv0 = c ? hv0 : hv1;
+  hv0 += hv1;
+  hv0 -= hv1;
+  hv0 *= hv1;
+  hv0 /= hv1;
+  sv0 = hv0 == hv1;
+  sv0 = hv0 != hv1;
+  sv0 = hv0 < hv1;
+  sv0 = hv0 > hv1;
+  sv0 = hv0 <= hv1;
+  sv0 = hv0 >= hv1;
+  sv0 = hv0 || hv1; // expected-error{{logical expression with vector types 'half4' (vector of 4 '__fp16' values) and 'half4' is only supported in C++}}
+  sv0 = hv0 && hv1; // expected-error{{logical expression with vector types 'half4' (vector of 4 '__fp16' values) and 'half4' is only supported in C++}}
+
+  // Implicit conversion between half vectors and float vectors are not allowed.
+  hv0 = fv0; // expected-error{{assigning to}}
+  fv0 = hv0; // expected-error{{assigning to}}
+  hv0 = (half4)fv0; // expected-error{{invalid conversion between}}
+  fv0 = (float4)hv0; // expected-error{{invalid conversion between}}
+  hv0 = fv0 + fv1; // expected-error{{assigning to}}
+  fv0 = hv0 + hv1; // expected-error{{assigning to}}
+  hv0 = hv0 + fv1; // expected-error{{cannot convert between vector}}
+  hv0 = c ? hv0 : fv1; // expected-error{{cannot convert between vector}}
+  sv0 = hv0 == fv1; // expected-error{{cannot convert between vector}}
+  sv0 = hv0 < fv1; // expected-error{{cannot convert between vector}}
+  sv0 = hv0 || fv1; // expected-error{{cannot convert between vector}} expected-error{{invalid operands to binary expression}}
+  iv0 = hv0 == hv1; // expected-error{{assigning to}}
+
+  // FIXME: clang currently disallows using these operators on vectors, which is
+  // allowed by gcc.
+  sv0 = !hv0; // expected-error{{invalid argument type}}
+  hv0++; // expected-error{{cannot increment value of type}}
+  ++hv0; // expected-error{{cannot increment value of type}}
+}
Index: test/CodeGen/fp16vec-ops.c
===
--- /dev/null
+++ test/CodeGen/fp16vec-ops.c
@@ -0,0 +1,162 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple arm64-apple-ios9 -emit-llvm -o - -fallow-half-arguments-and-returns %s | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_cc1 -triple armv7-apple-ios9 -emit-llvm -o - -fallow-half-arguments-and-returns %s | FileCheck %s --check-prefix=CHECK
+
+typedef __fp16 half4 __attribute__ ((vector_size (8)));
+typedef short short4 __attribute__ ((vector_size (8)));
+
+half4 hv0, hv1;
+short4 sv0;
+
+// CHECK-LABEL: testFP16Vec0
+// CHECK: %[[V0:.*]] = load <4 x half>, <4 x half>* @hv0, align 8
+// CHECK: %[[CONV:.*]] = fpext <4 x half> %[[V0]] to <4 x float>
+// CHECK: %[[V1:.*]] = load <4 x half>, <4 x half>* @hv1, align 8
+// CHECK: %[[CONV1:.*]] = fpext <4 x half> %[[V1]] to <4 x float>
+// CHECK: %[[ADD:.*]] = fadd <4 x float> %[[CONV]], %[[CONV1]]
+// CHECK: %[[CONV2:.*]] = fptrunc <4 x float> %[[ADD]] to <4 x half>
+// CHECK: store <4 x half> %[[CONV2]], <4 x half>* @hv0, align 8
+// CHECK: %[[V2:.*]] = load <4 x half>, <4 x half>* @hv0, align 8
+// CHECK: %[[CONV3:.*]] = fpext <4 x half> %[[V2]] to <4 x float>
+// CHECK: %[[V3:.*]] = load <4 x half>, <4 x half>* @hv1, align 8
+// CHECK: %[[CONV4:.*]] = fpext <4 x half> %[[V3]] to <4 x float>
+// CHECK: %[[SUB:.*]] = fsub <4 x float> %[[CONV3]], %[[CONV4]]
+// CHECK: %[[CONV5:.*]] = fptrunc <4 x float> %[[SUB]] to <4 x half>
+// CHECK: store <4 x half> %[[CONV5]], <4 x half>* @hv0, align 8
+// CHECK: %[[V4:.*]] = load <4 x half>, <4 x half>* @hv0, align 8
+// CHECK: %[[CONV6:.*]] = fpext <4 x half> %[[V4]] to <4 x float>
+// CHECK: %[[V5:.*]] = load <4 x half>, <4 x half>* @hv1, align 8
+// CHECK: %[[CONV7:.*]] = fpext <4 x half> %[[V5]] to <4 x float>
+// CHECK: %[[MUL:.*]] = fmul <4 x float> %[[CONV6]], %[[CONV7]]
+// CHECK: %[[CONV8:.*]] = fptrunc <4 x float> %[[MUL]] to <4 x half>
+// CHECK: store <4 x half> %[[CONV8]], <4 x half>* @hv0, align 8
+// CHECK: %[[V6:.*]] = load <4 x half>, <4 x half>* @hv0, align 8
+// CHECK: %[[CONV9:.*]] = fpext <4 x half> %[[V6]] to <4 x float>
+// CHECK: %[[V7:.*]] = load <4 x half>, <4 x half>* @hv1, align 8
+// CHECK: %[[CONV10:.*]] = fpext <4 x half> %[[V7]] to <4 x float>
+// CHECK: %[[DIV:.*]] = fdiv <4 x float> %[[CONV9]], %[[CONV10]]
+// CHECK: %[[CONV11:.*]] = 

[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

Looking at __sanitizer_dtor_callback implementation, this change will add a 
(fast) stack unwind in every destructor. In extreme cases (like a tight loop 
doing string operations) it could be bad for performance. I've seen ~15% AFAIR.


https://reviews.llvm.org/D37860



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


[PATCH] D37873: [WebAssembly] Fix wasm-toolchain.c tests

2017-09-14 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313307: [WebAssembly] Fix wasm-toolchain.c tests (authored 
by sbc).

Repository:
  rL LLVM

https://reviews.llvm.org/D37873

Files:
  cfe/trunk/test/Driver/wasm-toolchain.c


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,18 +27,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "-o" "a.out"
 
-// A basic C link command-line with optimization. WebAssembly is somewhat
-// special in enabling --gc-sections by default.
+// A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" 
"crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" 
"crtn.o" "-o" "a.out"
-
-// Ditto, but ensure that a user --no-gc-sections comes after the
-// default --gc-sections.
-
-// RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown 
--sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck 
-check-prefix=NO_GC_SECTIONS %s
-// NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" 
"crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-allow-undefined-file" 
"wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" 
"-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "-o" "a.out"


Index: cfe/trunk/test/Driver/wasm-toolchain.c
===
--- cfe/trunk/test/Driver/wasm-toolchain.c
+++ cfe/trunk/test/Driver/wasm-toolchain.c
@@ -27,18 +27,10 @@
 
 // RUN: %clang -### -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK %s
 // LINK: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "-o" "a.out"
 
-// A basic C link command-line with optimization. WebAssembly is somewhat
-// special in enabling --gc-sections by default.
+// A basic C link command-line with optimization.
 
 // RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo %s 2>&1 | FileCheck -check-prefix=LINK_OPT %s
 // LINK_OPT: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" "crti.o" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
-
-// Ditto, but ensure that a user --no-gc-sections comes after the
-// default --gc-sections.
-
-// RUN: %clang -### -O2 -no-canonical-prefixes -target wasm32-unknown-unknown --sysroot=/foo -Wl,--no-gc-sections %s 2>&1 | FileCheck -check-prefix=NO_GC_SECTIONS %s
-// NO_GC_SECTIONS: clang{{.*}}" "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
-// NO_GC_SECTIONS: lld{{.*}}" "-flavor" "wasm" "--gc-sections" "-L/foo/lib" "crt1.o" "crti.o" "--no-gc-sections" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "crtn.o" "-o" "a.out"
+// LINK_OPT: lld{{.*}}" "-flavor" "wasm" "-L/foo/lib" "[[temp]]" "-allow-undefined-file" "wasm.syms" "-lc" "-lcompiler_rt" "-o" "a.out"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37302: [Headers] Define *_HAS_SUBNORM for FLT, DBL, LDBL

2017-09-14 Thread Pirama Arumuga Nainar via Phabricator via cfe-commits
pirama added a comment.

@bruno Any suggestion on how to update test/Headers/float-darwin,c* so make it 
check the include_next?  I am unable to find the darwin-specific float.h inside 
an XCode installation directory.

- Oops, my earlier comment had the wrong test name


https://reviews.llvm.org/D37302



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:494
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&

false -> MsanUseAfterDtor


https://reviews.llvm.org/D37867



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis accepted this revision.
eugenis added a comment.

Oh right, I was looking at https://reviews.llvm.org/D37860.


https://reviews.llvm.org/D37867



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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In https://reviews.llvm.org/D37867#871353, @eugenis wrote:

> Have you looked at performance?


Not the answer to your question, but this patch just adds negative flag without 
changing defaults.


https://reviews.llvm.org/D37867



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


[libcxxabi] r313308 - Fix ASAN build with older compiler-rt versions.

2017-09-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 14 15:37:34 2017
New Revision: 313308

URL: http://llvm.org/viewvc/llvm-project?rev=313308=rev
Log:
Fix ASAN build with older compiler-rt versions.

compiler-rt recently added the __asan_handle_no_return() function that libc++abi
needs to use, however older versions of compiler-rt don't declare this interface
publicly and that breaks the libc++abi build.

This patch attempts to fix the issues by declaring the asan function explicitly,
so we don't depend on compiler-rt to provide the declaration.

Modified:
libcxxabi/trunk/src/cxa_exception.cpp

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=313308=313307=313308=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Thu Sep 14 15:37:34 2017
@@ -20,7 +20,7 @@
 #include "fallback_malloc.h"
 
 #if __has_feature(address_sanitizer)
-#include 
+extern "C" void __asan_handle_no_return(void);
 #endif
 
 // +---+-+---+
@@ -222,8 +222,7 @@ __cxa_throw(void *thrown_object, std::ty
 
 exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
 
-#if __has_feature(address_sanitizer) && \
-  defined(SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN)
+#if __has_feature(address_sanitizer)
 // Inform the ASan runtime that now might be a good time to clean stuff up.
 __asan_handle_no_return();
 #endif


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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

Have you looked at performance?


https://reviews.llvm.org/D37867



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


[PATCH] D37871: [ASAN] Add macro denoting availability of new `__asan_handle_no_return()` function.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF added a comment.

In https://reviews.llvm.org/D37871#871325, @eugenis wrote:

> This function was added to the header recently, but it has been provided by 
> ASan runtime library since the beginning. Why not simply declare it in 
> libc++abi?


I didn't know that. I'll come up with a separate patch set for that then.


https://reviews.llvm.org/D37871



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


[PATCH] D37871: [ASAN] Add macro denoting availability of new `__asan_handle_no_return()` function.

2017-09-14 Thread Evgenii Stepanov via Phabricator via cfe-commits
eugenis added a comment.

This function was added to the header recently, but it has been provided by 
ASan runtime library since the beginning. Why not simply declare it in 
libc++abi?


https://reviews.llvm.org/D37871



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


[libcxxabi] r313304 - [libc++abi] Fix ASAN build with older compiler-rt versions.

2017-09-14 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 14 15:19:28 2017
New Revision: 313304

URL: http://llvm.org/viewvc/llvm-project?rev=313304=rev
Log:
[libc++abi] Fix ASAN build with older compiler-rt versions.

Summary:
compiler-rt recently added the `__asan_handle_no_return()` function that 
libc++abi needs to use, however older versions of compiler-rt don't provide 
this interface and that breaks the libc++abi build.

This patch attempts to fix the issues by using a macro to detect if 
`asan_interface.h` is new enough to provide the function.

See D37871

Reviewers: phosek, vitalybuka

Reviewed By: phosek, vitalybuka

Subscribers: dberris, cfe-commits

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

Modified:
libcxxabi/trunk/src/cxa_exception.cpp

Modified: libcxxabi/trunk/src/cxa_exception.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception.cpp?rev=313304=313303=313304=diff
==
--- libcxxabi/trunk/src/cxa_exception.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception.cpp Thu Sep 14 15:19:28 2017
@@ -222,7 +222,8 @@ __cxa_throw(void *thrown_object, std::ty
 
 exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
 
-#if __has_feature(address_sanitizer)
+#if __has_feature(address_sanitizer) && \
+  defined(SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN)
 // Inform the ASan runtime that now might be a good time to clean stuff up.
 __asan_handle_no_return();
 #endif


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


[PATCH] D37871: [ASAN] Add macro denoting availability of new `__asan_handle_no_return()` function.

2017-09-14 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D37871



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


[PATCH] D37872: [libc++abi] Fix ASAN build with older compiler-rt versions.

2017-09-14 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D37872



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


[PATCH] D37089: [Sema] Error out early for tags defined inside an enumeration.

2017-09-14 Thread Doug Gregor via Phabricator via cfe-commits
doug.gregor accepted this revision.
doug.gregor added a comment.
This revision is now accepted and ready to land.

Looks good to me; sorry for the delay.


https://reviews.llvm.org/D37089



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


[PATCH] D37871: [ASAN] Add macro denoting availability of new `__asan_handle_no_return()` function.

2017-09-14 Thread Marshall Clow via Phabricator via cfe-commits
mclow.lists added a comment.

This looks fine to me (along with https://reviews.llvm.org/D37872)


https://reviews.llvm.org/D37871



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


[PATCH] D37872: [libc++abi] Fix ASAN build with older compiler-rt versions.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.
Herald added a subscriber: dberris.

compiler-rt recently added the `__asan_handle_no_return()` function that 
libc++abi needs to use, however older versions of compiler-rt don't provide 
this interface and that breaks the libc++abi build.

This patch attempts to fix the issues by using a macro to detect if 
`asan_interface.h` is new enough to provide the function.

See https://reviews.llvm.org/D37871


https://reviews.llvm.org/D37872

Files:
  src/cxa_exception.cpp


Index: src/cxa_exception.cpp
===
--- src/cxa_exception.cpp
+++ src/cxa_exception.cpp
@@ -222,7 +222,8 @@
 
 exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
 
-#if __has_feature(address_sanitizer)
+#if __has_feature(address_sanitizer) && \
+  defined(SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN)
 // Inform the ASan runtime that now might be a good time to clean stuff up.
 __asan_handle_no_return();
 #endif


Index: src/cxa_exception.cpp
===
--- src/cxa_exception.cpp
+++ src/cxa_exception.cpp
@@ -222,7 +222,8 @@
 
 exception_header->unwindHeader.exception_cleanup = exception_cleanup_func;
 
-#if __has_feature(address_sanitizer)
+#if __has_feature(address_sanitizer) && \
+  defined(SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN)
 // Inform the ASan runtime that now might be a good time to clean stuff up.
 __asan_handle_no_return();
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37871: [ASAN] Add macro denoting availability of new `__asan_handle_no_return()` function.

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF created this revision.

Libc++abi attempts to use the newly added `__asan_handle_no_return()` when 
built under ASAN. Unfortunately older versions of compiler-rt do not provide 
this symbol, and so libc++abi needs a way to detect if `asan_interface.h` 
actually provides the function.

This patch adds the macro `SANITIZER_ASAN_HAS_HANDLE_NO_RETURN` which can be 
used to detect the availability of the new function.


https://reviews.llvm.org/D37871

Files:
  include/sanitizer/asan_interface.h


Index: include/sanitizer/asan_interface.h
===
--- include/sanitizer/asan_interface.h
+++ include/sanitizer/asan_interface.h
@@ -148,6 +148,10 @@
   // before things like _exit and execl to avoid false positives on stack.
   void __asan_handle_no_return(void);
 
+  // Required to allow ASAN versions of libc++abi to build against older
+  // versions of compiler-rt that do not provide this interface.
+# define SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif


Index: include/sanitizer/asan_interface.h
===
--- include/sanitizer/asan_interface.h
+++ include/sanitizer/asan_interface.h
@@ -148,6 +148,10 @@
   // before things like _exit and execl to avoid false positives on stack.
   void __asan_handle_no_return(void);
 
+  // Required to allow ASAN versions of libc++abi to build against older
+  // versions of compiler-rt that do not provide this interface.
+# define SANITIZER_ASAN_INTERFACE_HAS_HANDLE_NO_RETURN
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse updated this revision to Diff 115295.
morehouse added a comment.

- Use hasFlag() in CompilerInvocation.cpp as well.


https://reviews.llvm.org/D37867

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 
'-fsanitize-memory-track-origins=3'
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
+// CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -fno-sanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// CHECK-USE-AFTER-DTOR-OFF-NOT: -cc1{{.*}}memory-use-after-dtor
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-field-padding=0 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-FIELD-PADDING-0
 // CHECK-ASAN-FIELD-PADDING-0-NOT: -fsanitize-address-field-padding
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -829,7 +829,9 @@
   Opts.SanitizeMemoryTrackOrigins =
   getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, 
Diags);
   Opts.SanitizeMemoryUseAfterDtor =
-  Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
+  Args.hasFlag(OPT_fsanitize_memory_use_after_dtor,
+   OPT_fno_sanitize_memory_use_after_dtor,
+   false);
   Opts.SanitizeMinimalRuntime = Args.hasArg(OPT_fsanitize_minimal_runtime);
   Opts.SanitizeCfiCrossDso = Args.hasArg(OPT_fsanitize_cfi_cross_dso);
   Opts.SanitizeStats = Args.hasArg(OPT_fsanitize_stats);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -489,7 +489,9 @@
   }
 }
 MsanUseAfterDtor =
-Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor);
+Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -851,6 +851,9 @@
 def fsanitize_memory_use_after_dtor : Flag<["-"], 
"fsanitize-memory-use-after-dtor">,
  Group,
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,
+ HelpText<"Disable use-after-destroy 
detection in MemorySanitizer">;
 def fsanitize_address_field_padding : Joined<["-"], 
"fsanitize-address-field-padding=">,
 Group,
 HelpText<"Level of field padding for 
AddressSanitizer">;


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 

r313300 - Fix 2 stage build on some apple bots.

2017-09-14 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Sep 14 14:30:27 2017
New Revision: 313300

URL: http://llvm.org/viewvc/llvm-project?rev=313300=rev
Log:
Fix 2 stage build on some apple bots.

The recent lit refactor changed the location of the lit script
run by check targets from /utils/lit/lit.py to
/llvm-lit.py.  In some 2-stage build scenarios, the location
of  was not properly passed through to the second stage,
and it was looking for /llvm-lit.py instead, causing failures.

Fix suggested by Mike Edwards and Chris Bieneman @apple

Modified:
cfe/trunk/runtime/CMakeLists.txt

Modified: cfe/trunk/runtime/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/runtime/CMakeLists.txt?rev=313300=313299=313300=diff
==
--- cfe/trunk/runtime/CMakeLists.txt (original)
+++ cfe/trunk/runtime/CMakeLists.txt Thu Sep 14 14:30:27 2017
@@ -77,6 +77,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND E
-DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX}
+   -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_RUNTIME_OUTPUT_INTDIR}
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT:PATH=${CMAKE_OSX_SYSROOT}
${COMPILER_RT_PASSTHROUGH_VARIABLES}


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


[PATCH] D37867: [MSan] Add flag to disable use-after-dtor.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse created this revision.

Flag is -fno-sanitize-use-after-dtor.


https://reviews.llvm.org/D37867

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/fsanitize.c


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 
'-fsanitize-memory-track-origins=3'
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR
+// CHECK-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -fno-sanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | 
FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR-OFF
+// CHECK-USE-AFTER-DTOR-OFF-NOT: -cc1{{.*}}memory-use-after-dtor
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=address 
-fsanitize-address-field-padding=0 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-ASAN-FIELD-PADDING-0
 // CHECK-ASAN-FIELD-PADDING-0-NOT: -fsanitize-address-field-padding
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -828,6 +828,11 @@
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
   Opts.SanitizeMemoryTrackOrigins =
   getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, 
Diags);
+  if (Arg *A = Args.getLastArg(OPT_fsanitize_memory_use_after_dtor,
+   OPT_fno_sanitize_memory_use_after_dtor)) {
+Opts.SanitizeMemoryUseAfterDtor =
+A->getOption().matches(OPT_fsanitize_memory_use_after_dtor);
+  }
   Opts.SanitizeMemoryUseAfterDtor =
   Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
   Opts.SanitizeMinimalRuntime = Args.hasArg(OPT_fsanitize_minimal_runtime);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -489,7 +489,9 @@
   }
 }
 MsanUseAfterDtor =
-Args.hasArg(options::OPT_fsanitize_memory_use_after_dtor);
+Args.hasFlag(options::OPT_fsanitize_memory_use_after_dtor,
+ options::OPT_fno_sanitize_memory_use_after_dtor,
+ false);
 NeedPIE |= !(TC.getTriple().isOSLinux() &&
  TC.getTriple().getArch() == llvm::Triple::x86_64);
   }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -851,6 +851,9 @@
 def fsanitize_memory_use_after_dtor : Flag<["-"], 
"fsanitize-memory-use-after-dtor">,
  Group,
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,
+ HelpText<"Disable use-after-destroy 
detection in MemorySanitizer">;
 def fsanitize_address_field_padding : Joined<["-"], 
"fsanitize-address-field-padding=">,
 Group,
 HelpText<"Level of field padding for 
AddressSanitizer">;


Index: clang/test/Driver/fsanitize.c
===
--- clang/test/Driver/fsanitize.c
+++ clang/test/Driver/fsanitize.c
@@ -172,8 +172,14 @@
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=memory -fsanitize-memory-track-origins=3 -pie %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TRACK-ORIGINS-3
 // CHECK-TRACK-ORIGINS-3: error: invalid value '3' in 

[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

Woops. didn't mean to reject.


https://reviews.llvm.org/D28212



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


[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF requested changes to this revision.
EricWF added a comment.
This revision now requires changes to proceed.

- List Item



In https://reviews.llvm.org/D28212#871034, @smeenai wrote:

> @compnerd, @EricWF and I discussed this a bit on IRC yesterday.
>
> In this particular case, however, I don't believe those concerns apply. 
> `vcruntime_typeinfo.h` is only pulled in from MSVC's `typeinfo` header, so 
> it's not going to get pulled in unless explicitly requested, and therefore 
> there are no interoperability concerns. Additionally, the `type_info` 
> structure here is completely compatible with the one from the vcruntime 
> headers, since they both model the Microsoft ABI typeinfo structure. The only 
> behavior difference is that vcruntime's implementation will demangle the type 
> name, whereas this one won't, but we can address that in a follow-up. In 
> other words, I believe this change can go in independent of whatever decision 
> we reach for vcruntime interoperability in the general case.


I'm convinced. Kill away.

This patch LGTM other than the mentioned nits.




Comment at: include/typeinfo:95
+#if defined(_LIBCPP_ABI_MICROSOFT)
+  mutable struct __data {
+const char *__undecorated_name;

Perhaps the struct should have a different name than the instance of it.



Comment at: include/typeinfo:100
+
+  static const char *__name(const struct type_info::__data *__data);
+  static size_t __hash(const struct type_info::__data *__data);

These should probably have `_LIBCPP_FUNC_VIS` visibility declarations attached 
to them.



Comment at: include/typeinfo:101
+  static const char *__name(const struct type_info::__data *__data);
+  static size_t __hash(const struct type_info::__data *__data);
+  static int __compare(const struct type_info::__data* __lls,

Is there a reason why `__name` and `__hash` need wrappers? Can't we just 
provide out-of-line definitions for `name()` and `hash_code()` directly?



Comment at: include/typeinfo:200
 #endif
+#endif
 

Comment on `#endif` please.


https://reviews.llvm.org/D28212



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


[PATCH] D37322: [Sema] Correct typos in LHS, RHS before building a binop expression.

2017-09-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak accepted this revision.
ahatanak added a comment.
This revision is now accepted and ready to land.

I see. It looks like there is an ambiguity between 'new_anotation' and 
'new_annotations' that can't be resolved in ActOnMemberAccessExpr because they 
have the same distance from 'new_annotation'. This doesn't happen if the full 
expression (new_annotation->Swap) is typo-corrected because 'new_anotation' 
will be the only valid choice in that case.

I don't think there is a problem with creating CXXDependentScopeMemberExpr for 
ObjC property access, so this looks fine.


https://reviews.llvm.org/D37322



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


[PATCH] D37436: Initial implementation of C attributes (WG14 N2137)

2017-09-14 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 115279.
aaron.ballman added a comment.

Updated based on review feedback.

- Rename CAttributes to DoubleSquareBracketAttributes
- Added Objective-C test cases to demonstrate no regressed behavior (based on a 
use-case pointed out during review)
- Fixed regression with GNU-style attributes in enumerations

I still need to rename the cc1 flag, pending agreement on the name.


https://reviews.llvm.org/D37436

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/Attributes.h
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/AttributeList.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/Lexer.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/AttributeList.cpp
  clang/test/CXX/dcl.dcl/dcl.attr/dcl.align/p6.cpp
  clang/test/Misc/ast-dump-c-attr.c
  clang/test/Parser/c2x-attributes.c
  clang/test/Parser/c2x-attributes.m
  clang/test/Parser/cxx0x-attributes.cpp
  clang/test/Sema/attr-deprecated-c2x.c
  clang/utils/TableGen/ClangAttrEmitter.cpp

Index: clang/utils/TableGen/ClangAttrEmitter.cpp
===
--- clang/utils/TableGen/ClangAttrEmitter.cpp
+++ clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -58,7 +58,7 @@
 
 assert(V != "GCC" && "Given a GCC spelling, which means this hasn't been"
"flattened!");
-if (V == "CXX11" || V == "Pragma")
+if (V == "CXX11" || V == "C2x" || V == "Pragma")
   NS = Spelling.getValueAsString("Namespace");
 bool Unset;
 K = Spelling.getValueAsBitOrUnset("KnownToGCC", Unset);
@@ -1326,7 +1326,7 @@
 if (Variety == "GNU") {
   Prefix = " __attribute__((";
   Suffix = "))";
-} else if (Variety == "CXX11") {
+} else if (Variety == "CXX11" || Variety == "C2x") {
   Prefix = " [[";
   Suffix = "]]";
   std::string Namespace = Spellings[I].nameSpace();
@@ -2716,10 +2716,14 @@
   // If this is the C++11 variety, also add in the LangOpts test.
   if (Variety == "CXX11")
 Test += " && LangOpts.CPlusPlus11";
+  else if (Variety == "C2x")
+Test += " && LangOpts.DoubleSquareBracketsAttributes";
 } else if (Variety == "CXX11")
   // C++11 mode should be checked against LangOpts, which is presumed to be
   // present in the caller.
   Test = "LangOpts.CPlusPlus11";
+else if (Variety == "C2x")
+  Test = "LangOpts.DoubleSquareBracketsAttributes";
 
 std::string TestStr =
 !Test.empty() ? Test + " ? " + llvm::itostr(Version) + " : 0" : "1";
@@ -2740,7 +2744,7 @@
   // and declspecs. Then generate a big switch statement for each of them.
   std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
   std::vector Declspec, Microsoft, GNU, Pragma;
-  std::map CXX;
+  std::map CXX, C2x;
 
   // Walk over the list of all attributes, and split them out based on the
   // spelling variety.
@@ -2756,6 +2760,8 @@
 Microsoft.push_back(R);
   else if (Variety == "CXX11")
 CXX[SI.nameSpace()].push_back(R);
+  else if (Variety == "C2x")
+C2x[SI.nameSpace()].push_back(R);
   else if (Variety == "Pragma")
 Pragma.push_back(R);
 }
@@ -2775,20 +2781,25 @@
   OS << "case AttrSyntax::Pragma:\n";
   OS << "  return llvm::StringSwitch(Name)\n";
   GenerateHasAttrSpellingStringSwitch(Pragma, OS, "Pragma");
-  OS << "case AttrSyntax::CXX: {\n";
-  // C++11-style attributes are further split out based on the Scope.
-  for (auto I = CXX.cbegin(), E = CXX.cend(); I != E; ++I) {
-if (I != CXX.begin())
-  OS << " else ";
-if (I->first.empty())
-  OS << "if (!Scope || Scope->getName() == \"\") {\n";
-else
-  OS << "if (Scope->getName() == \"" << I->first << "\") {\n";
-OS << "  return llvm::StringSwitch(Name)\n";
-GenerateHasAttrSpellingStringSwitch(I->second, OS, "CXX11", I->first);
-OS << "}";
-  }
-  OS << "\n}\n";
+  auto fn = [](const char *Spelling, const char *Variety,
+  const std::map ) {
+OS << "case AttrSyntax::" << Variety << ": {\n";
+// C++11-style attributes are further split out based on the Scope.
+for (auto I = List.cbegin(), E = List.cend(); I != E; ++I) {
+  if (I != List.cbegin())
+OS << " else ";
+  if (I->first.empty())
+OS << "if (!Scope || Scope->getName() == \"\") {\n";
+  else
+OS << "if (Scope->getName() == \"" << I->first << "\") {\n";
+  OS << "  return llvm::StringSwitch(Name)\n";
+  GenerateHasAttrSpellingStringSwitch(I->second, OS, Spelling, I->first);
+  OS << "}";
+}
+OS << "\n}\n";
+  };
+  fn("CXX11", "CXX", CXX);
+  fn("C2x", "C", C2x);
   OS << "}\n";
 }
 
@@ -2809,10 +2820,11 @@
  << 

[PATCH] D37865: [Sema] Fix a pair of crashes when generating exception specifiers with an error'ed field for a template class' default ctor.

2017-09-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.

The two examples in the test would both cause a compiler assert when attempting 
to calculate 
the exception specifier for the default constructor for the template classes.  
The problem was
that dependents of this function expect that Field->getInClassInitializer 
(including canThrow) is
not nullptr.  However, if the template's initializer has an error, exactly that 
situation happens.

This patch simply sets the field to be invalid.


https://reviews.llvm.org/D37865

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/init-expr-crash.cpp


Index: test/SemaCXX/init-expr-crash.cpp
===
--- /dev/null
+++ test/SemaCXX/init-expr-crash.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+// Test reproduces a pair of crashes that were caused by code attempting
+// to materialize a default constructor's exception specifier.
+
+template  struct A {
+  static T tab[];
+
+  const int M = UNDEFINED; // expected-error {{use of undeclared identifier}}
+
+  int main()
+  {
+A a;
+
+return 0;
+  }
+};
+
+template  struct B {
+  static T tab[];
+
+  // expected-error@+1 {{invalid application of 'sizeof' to an incomplete 
type}}
+  const int N = sizeof(B::tab) / sizeof(char);
+
+  int main()
+  {
+B b;
+
+return 0;
+  }
+};
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12436,7 +12436,8 @@
   assert(Pattern && "We must have set the Pattern!");
 }
 
-if (InstantiateInClassInitializer(Loc, Field, Pattern,
+if (!Pattern->hasInClassInitializer() ||
+InstantiateInClassInitializer(Loc, Field, Pattern,
   getTemplateInstantiationArgs(Field))) {
   // Don't diagnose this again.
   Field->setInvalidDecl();


Index: test/SemaCXX/init-expr-crash.cpp
===
--- /dev/null
+++ test/SemaCXX/init-expr-crash.cpp
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+
+// Test reproduces a pair of crashes that were caused by code attempting
+// to materialize a default constructor's exception specifier.
+
+template  struct A {
+  static T tab[];
+
+  const int M = UNDEFINED; // expected-error {{use of undeclared identifier}}
+
+  int main()
+  {
+A a;
+
+return 0;
+  }
+};
+
+template  struct B {
+  static T tab[];
+
+  // expected-error@+1 {{invalid application of 'sizeof' to an incomplete type}}
+  const int N = sizeof(B::tab) / sizeof(char);
+
+  int main()
+  {
+B b;
+
+return 0;
+  }
+};
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -12436,7 +12436,8 @@
   assert(Pattern && "We must have set the Pattern!");
 }
 
-if (InstantiateInClassInitializer(Loc, Field, Pattern,
+if (!Pattern->hasInClassInitializer() ||
+InstantiateInClassInitializer(Loc, Field, Pattern,
   getTemplateInstantiationArgs(Field))) {
   // Don't diagnose this again.
   Field->setInvalidDecl();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36471: [StaticAnalyzer] Try to calculate arithmetic result when operand has a range of possible values

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

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D36471



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


[PATCH] D30295: [analyzer] clarify undef shift result when shift count is negative or exceeds the bit width

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

ping


Repository:
  rL LLVM

https://reviews.llvm.org/D30295



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: compiler-rt/test/msan/use-after-dtor.cc:13
 
 #include 
 #include 

morehouse wrote:
> vitalybuka wrote:
> > Probably we need one test which check that we stop detecting bugs with 
> > -fno-sanitize-memory-track-origins. Maybe this one or in separate file.
> Do you mean `-fno-sanitize-memory-use-after-dtor`?  See `dtor-member.cc` test.
Right.
use-after-dtor.cc seems more general than dtor-member.cc. So maybe having it 
here as well would be nice.


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse added inline comments.



Comment at: clang/include/clang/Driver/Options.td:854
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,

vitalybuka wrote:
> I'd recommend to split patch in two:
> 1. Add no-sanitize with tests
> 2. Flip default
Can do.



Comment at: clang/test/Driver/fsanitize.c:175
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR

vitalybuka wrote:
> Somewhere we need to have test that default is ON or OFF.
> Maybe here?
Line 177 tests that default is ON.



Comment at: compiler-rt/test/msan/use-after-dtor.cc:13
 
 #include 
 #include 

vitalybuka wrote:
> Probably we need one test which check that we stop detecting bugs with 
> -fno-sanitize-memory-track-origins. Maybe this one or in separate file.
Do you mean `-fno-sanitize-memory-use-after-dtor`?  See `dtor-member.cc` test.


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka requested changes to this revision.
vitalybuka added inline comments.
This revision now requires changes to proceed.



Comment at: clang/test/Driver/fsanitize.c:175
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor -pie %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-MSAN-USE-AFTER-DTOR
-// CHECK-MSAN-USE-AFTER-DTOR: -cc1{{.*}}-fsanitize-memory-use-after-dtor
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fsanitize-memory-use-after-dtor %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-USE-AFTER-DTOR
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory 
-fno-sanitize-memory-use-after-dtor -fsanitize-memory-use-after-dtor %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-USE-AFTER-DTOR

Somewhere we need to have test that default is ON or OFF.
Maybe here?


https://reviews.llvm.org/D37860



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


[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/include/clang/Driver/Options.td:854
  HelpText<"Enable use-after-destroy 
detection in MemorySanitizer">;
+def fno_sanitize_memory_use_after_dtor : Flag<["-"], 
"fno-sanitize-memory-use-after-dtor">,
+ Group,

I'd recommend to split patch in two:
1. Add no-sanitize with tests
2. Flip default



Comment at: clang/lib/Driver/SanitizerArgs.cpp:492
+if (Arg *A =
+Args.getLastArg(options::OPT_fsanitize_memory_use_after_dtor,
+options::OPT_fno_sanitize_memory_use_after_dtor)) {

Can you use parsing similar to AsanUseAfterScope at line 645



Comment at: compiler-rt/test/msan/dtor-bit-fields.cc:3
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory 
-fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 

Please keep -fsanitize-memory-use-after-dtor in dtor* tests.
We test the check itself here, not default value. So we don't flip it every 
time default switched.



Comment at: compiler-rt/test/msan/use-after-dtor.cc:13
 
 #include 
 #include 

Probably we need one test which check that we stop detecting bugs with 
-fno-sanitize-memory-track-origins. Maybe this one or in separate file.


https://reviews.llvm.org/D37860



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


[PATCH] D37308: Fix the __interface inheritence rules to work better with IUnknown and IDispatch

2017-09-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane updated this revision to Diff 115272.
erichkeane marked an inline comment as done.
erichkeane added a comment.

Fixed for @rnk s comments.


https://reviews.llvm.org/D37308

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/DeclCXX.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/SemaCXX/ms-iunknown-inline-def.cpp
  test/SemaCXX/ms-iunknown-outofline-def.cpp
  test/SemaCXX/ms-iunknown.cpp

Index: test/SemaCXX/ms-iunknown.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-iunknown.cpp
@@ -0,0 +1,39 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s 
+
+struct __declspec(uuid("---C000-0046")) IUnknown {
+  void foo();
+};
+struct IPropertyPageBase : public IUnknown {};
+struct IPropertyPage : public IPropertyPageBase {};
+__interface ISfFileIOPropertyPage : public IPropertyPage {};
+
+
+namespace NS {
+  struct __declspec(uuid("---C000-0046")) IUnknown {};
+  // expected-error@+1 {{interface type cannot inherit from}}
+  __interface IPropertyPageBase : public IUnknown {}; 
+}
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface IPropertyPageBase2 : public NS::IUnknown {}; 
+
+__interface temp_iface {};
+struct bad_base : temp_iface {};
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface bad_inherit : public bad_base{};
+
+struct mult_inher_base : temp_iface, IUnknown {};
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface bad_inherit2 : public mult_inher_base{};
+
+struct PageBase : public IUnknown {};
+struct Page3 : public PageBase {};
+struct Page4 : public PageBase {};
+__interface PropertyPage : public Page4 {};
+
+struct Page5 : public Page3, Page4{};
+// expected-error@+1 {{interface type cannot inherit from}}
+__interface PropertyPage2 : public Page5 {}; 
+
+__interface IF1 {};
+__interface PP : IUnknown, IF1{}; 
+__interface PP2 : PP, Page3, Page4{};
Index: test/SemaCXX/ms-iunknown-outofline-def.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-iunknown-outofline-def.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s 
+
+struct __declspec(uuid("---C000-0046")) IUnknown {
+  void foo();
+};
+
+__interface NoError : public IUnknown {};
+void IUnknown::foo() {}
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {}; 
Index: test/SemaCXX/ms-iunknown-inline-def.cpp
===
--- /dev/null
+++ test/SemaCXX/ms-iunknown-inline-def.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s 
+
+struct __declspec(uuid("---C000-0046")) IUnknown {
+  void foo() {}
+};
+
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {}; 
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -2388,7 +2388,7 @@
   if (const RecordType *Record = NewBaseType->getAs()) {
 const CXXRecordDecl *RD = cast(Record->getDecl());
 if (Class->isInterface() &&
-  (!RD->isInterface() ||
+  (!RD->isInterfaceLike() ||
KnownBase->getAccessSpecifier() != AS_public)) {
   // The Microsoft extension __interface does not permit bases that
   // are not themselves public interfaces.
Index: lib/AST/DeclCXX.cpp
===
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -1470,6 +1470,53 @@
   return false;
 }
 
+bool CXXRecordDecl::isInterfaceLike() const {
+  assert(hasDefinition() && "checking for interface-like without a definition");
+  // All __interfaces are inheritently interface-like.
+  if (isInterface())
+return true;
+
+  // Interface-like types cannot have a user declared constructor, destructor,
+  // friends, VBases, conversion functions, or fields.  Additionally, lambdas
+  // cannot be interface types.
+  if (isLambda() || hasUserDeclaredConstructor() ||
+  hasUserDeclaredDestructor() || !field_empty() || hasFriends() ||
+  getNumVBases() > 0 || conversion_end() - conversion_begin() > 0)
+return false;
+
+  // No interface-like type can have a method with a definition.
+  for (const auto *const Method : methods())
+if (Method->isDefined())
+  return false;
+
+  // Check "Special" types.
+  const auto *Uuid = getAttr();
+  if (Uuid && isStruct() && getDeclContext()->isTranslationUnit() &&
+  ((getName() == "IUnknown" &&
+Uuid->getGuid() == "---C000-0046") ||
+   (getName() == "IDispatch" &&
+Uuid->getGuid() == "00020400---C000-0046"))) {
+if (getNumBases() > 0)
+  return false;
+return true;
+  }
+
+  // FIXME: Any 

[PATCH] D28212: typeinfo: provide a partial implementation for Win32

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

@compnerd, @EricWF and I discussed this a bit on IRC yesterday.

My motivation here is that I'm using libc++ with other headers that clash badly 
with the vcruntime headers, which prevents me from using libc++'s 
`_LIBCPP_ABI_MICROSOFT` support. Reducing libc++'s dependencies on the 
vcruntime headers enables me to at least use parts of the Microsoft ABI support.

At the same time, @EricWF pointed out that most people will expect libc++ to 
play nicely with the vcruntime headers. In particular, `vcruntime_new.h` ends 
up getting pulled in from all sorts of places, which is why libc++ defers to 
that header instead of trying to provide its own new/delete declarations for 
`_LIBCPP_ABI_MICROSOFT`.

One option would be an alternate ABI configuration, which is basically 
"Microsoft ABI support without reliance on and interoperability with vcruntime 
headers". Another possibility would be for the libc++ headers to provide 
vcruntime-compatible declarations for `_LIBCPP_ABI_MICROSOFT`, which would 
allow us to remain compatible with the vcruntime headers without depending on 
them. I find the second option to be cleaner conceptually and would prefer it.

In this particular case, however, I don't believe those concerns apply. 
`vcruntime_typeinfo.h` is only pulled in from MSVC's `typeinfo` header, so it's 
not going to get pulled in unless explicitly requested, and therefore there are 
no interoperability concerns. Additionally, the `type_info` structure here is 
completely compatible with the one from the vcruntime headers, since they both 
model the Microsoft ABI typeinfo structure. The only behavior difference is 
that vcruntime's implementation will demangle the type name, whereas this one 
won't, but we can address that in a follow-up. In other words, I believe this 
change can go in independent of whatever decision we reach for vcruntime 
interoperability in the general case.


https://reviews.llvm.org/D28212



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


[clang-tools-extra] r313290 - Fix refactoring missed in previous commit r313270 which resulted in an undefined variable being used.

2017-09-14 Thread Douglas Yung via cfe-commits
Author: dyung
Date: Thu Sep 14 12:51:26 2017
New Revision: 313290

URL: http://llvm.org/viewvc/llvm-project?rev=313290=rev
Log:
Fix refactoring missed in previous commit r313270 which resulted in an 
undefined variable being used.

Modified:
clang-tools-extra/trunk/test/Unit/lit.cfg

Modified: clang-tools-extra/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/Unit/lit.cfg?rev=313290=313289=313290=diff
==
--- clang-tools-extra/trunk/test/Unit/lit.cfg (original)
+++ clang-tools-extra/trunk/test/Unit/lit.cfg Thu Sep 14 12:51:26 2017
@@ -32,7 +32,7 @@ shlibpath = os.path.pathsep.join((config
  config.environment.get(shlibpath_var,'')))
 
 # Win32 seeks DLLs along %PATH%.
-if sys.platform in ['win32', 'cygwin'] and os.path.isdir(shlibdir):
+if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
 shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
 
 config.environment[shlibpath_var] = shlibpath


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


[PATCH] D37861: preserving #pragma clang assume_nonnull in preprocessed output

2017-09-14 Thread Zbigniew Sarbinowski via Phabricator via cfe-commits
zibi created this revision.
Herald added subscribers: kbarton, nemanjai.

When #pragma clang assume_nonnull begin || end is present in the source it is 
completely gone from pre-processed output when compiled with -E or -P. This 
patch make sure the pragma is preserved. I included 1 test case which checks 
the presence of this pragma in pre-processor output.


https://reviews.llvm.org/D37861

Files:
  include/clang/Lex/PPCallbacks.h
  lib/Frontend/PrintPreprocessedOutput.cpp
  lib/Lex/Pragma.cpp
  test/Preprocessor/pragma_assume_nonnull.c

Index: test/Preprocessor/pragma_assume_nonnull.c
===
--- /dev/null
+++ test/Preprocessor/pragma_assume_nonnull.c
@@ -0,0 +1,31 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -E %s | FileCheck %s
+
+#ifndef NS_ASSUME_NONNULL_BEGIN
+#if __has_feature(assume_nonnull)
+#define NS_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
+#define NS_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
+#else
+#define NS_ASSUME_NONNULL_BEGIN
+#define NS_ASSUME_NONNULL_END
+#endif
+#endif
+
+// CHECK: #pragma clang assume_nonnull begin
+NS_ASSUME_NONNULL_BEGIN
+
+int bar(int * ip) { return *ip; }
+
+// CHECK: #pragma clang assume_nonnull end
+NS_ASSUME_NONNULL_END
+
+int foo(int * _Nonnull ip) { return *ip; }
+
+int main() {
+#if __has_feature(assume_nonnull)
+   return bar(0) + foo(0); // expected-warning 2 {{null passed to a callee that requires a non-null argument}}
+#else
+   return bar(0) + foo(0); // expected-warning {{null passed to a callee that requires a non-null argument}}
+#endif
+}
+
Index: lib/Lex/Pragma.cpp
===
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1725,21 +1725,26 @@
 
 // The start location we want after processing this.
 SourceLocation NewLoc;
+PPCallbacks *Callbacks = PP.getPPCallbacks();
 
 if (IsBegin) {
   // Complain about attempts to re-enter an audit.
   if (BeginLoc.isValid()) {
 PP.Diag(Loc, diag::err_pp_double_begin_of_assume_nonnull);
 PP.Diag(BeginLoc, diag::note_pragma_entered_here);
   }
   NewLoc = Loc;
+  if (Callbacks)
+Callbacks->PragmaAssumeNonNullBegin(NewLoc);
 } else {
   // Complain about attempts to leave an audit that doesn't exist.
   if (!BeginLoc.isValid()) {
 PP.Diag(Loc, diag::err_pp_unmatched_end_of_assume_nonnull);
 return;
   }
   NewLoc = SourceLocation();
+  if (Callbacks)
+Callbacks->PragmaAssumeNonNullEnd(NewLoc);
 }
 
 PP.setPragmaAssumeNonNullLoc(NewLoc);
Index: lib/Frontend/PrintPreprocessedOutput.cpp
===
--- lib/Frontend/PrintPreprocessedOutput.cpp
+++ lib/Frontend/PrintPreprocessedOutput.cpp
@@ -143,6 +143,8 @@
  ArrayRef Ids) override;
   void PragmaWarningPush(SourceLocation Loc, int Level) override;
   void PragmaWarningPop(SourceLocation Loc) override;
+  void PragmaAssumeNonNullBegin(SourceLocation Loc) override;
+  void PragmaAssumeNonNullEnd(SourceLocation Loc) override;
 
   bool HandleFirstTokOnLine(Token );
 
@@ -549,6 +551,22 @@
   setEmittedDirectiveOnThisLine();
 }
 
+void PrintPPOutputPPCallbacks::
+PragmaAssumeNonNullBegin(SourceLocation Loc) {
+  startNewLineIfNeeded();
+  MoveToLine(Loc);
+  OS << "#pragma " << "clang assume_nonnull begin";
+  setEmittedDirectiveOnThisLine();
+}
+
+void PrintPPOutputPPCallbacks::
+PragmaAssumeNonNullEnd(SourceLocation Loc) {
+  startNewLineIfNeeded();
+  MoveToLine(Loc);
+  OS << "#pragma " << "clang assume_nonnull end";
+  setEmittedDirectiveOnThisLine();
+}
+
 /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this
 /// is called for the first token on each new line.  If this really is the start
 /// of a new logical line, handle it and return true, otherwise return false.
Index: include/clang/Lex/PPCallbacks.h
===
--- include/clang/Lex/PPCallbacks.h
+++ include/clang/Lex/PPCallbacks.h
@@ -235,6 +235,14 @@
   virtual void PragmaWarningPop(SourceLocation Loc) {
   }
 
+  /// \brief Callback invoked when a \#pragma clang assume_nonnull begin directive
+  /// is read.
+  virtual void PragmaAssumeNonNullBegin(SourceLocation Loc) {}
+
+  /// \brief Callback invoked when a \#pragma clang assume_nonnull end directive
+  /// is read.
+  virtual void PragmaAssumeNonNullEnd(SourceLocation Loc) {}
+
   /// \brief Called by Preprocessor::HandleMacroExpandedIdentifier when a
   /// macro invocation is found.
   virtual void MacroExpands(const Token ,
@@ -443,6 +451,16 @@
 Second->PragmaWarningPop(Loc);
   }
 
+  void PragmaAssumeNonNullBegin(SourceLocation Loc) override {
+First->PragmaAssumeNonNullBegin(Loc);
+Second->PragmaAssumeNonNullBegin(Loc);
+  }
+
+  void PragmaAssumeNonNullEnd(SourceLocation Loc) override {
+

[PATCH] D37308: Fix the __interface inheritence rules to work better with IUnknown and IDispatch

2017-09-14 Thread Erich Keane via Phabricator via cfe-commits
erichkeane marked 4 inline comments as done.
erichkeane added a comment.

Thanks for the quick  response!  New patch coming soon.




Comment at: lib/AST/DeclCXX.cpp:1478
+
+  // No interface-like types can have a user declared constructor, destructor,
+  // friends, VBases, conersion functions, or fields.  Additionally, lambdas

rnk wrote:
> Maybe "Interface-like types cannot have ..."
> 
> Can an interface-like type have an explicitly defaulted copy ctor? That will 
> be user declared, but it will probably be trivial.
It cannot according to godbolt. https://godbolt.org/g/wZuNzT



Comment at: lib/AST/DeclCXX.cpp:1486-1489
+  // No interface-like type can have a method with a definition.
+  for (const auto *const Method : methods())
+if (Method->isDefined())
+  return false;

rnk wrote:
> Huh, so they can be declared, but they don't have to be pure.
Correct, and strange.  Annoyingly, it is possible to do:

  struct S : someIFace {
  void foo();
  };
__interface F  : public S {}; // This one is OK.
void S::foo();
__interface F2  : public S {}; // This one is NOT OK.



Comment at: lib/AST/DeclCXX.cpp:1516-1517
+const auto *Base = BS.getType()->getAsCXXRecordDecl();
+if (Base->isInterface())
+  continue;
+if (Base->isInterfaceLike()) {

rnk wrote:
> Are you sure you want this? MSVC rejects the test case that exercises this 
> case.
AM I sure?   Not anymore.  WAS I sure?  Pretty darn.  Thanks for the catch!



Comment at: test/SemaCXX/ms-iunknown-outofline-def.cpp:9-10
+void IUnknown::foo() {}
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {}; 

rnk wrote:
> Again, this is a pretty weird error. If the method isn't pure, there must be 
> a definition *somewhere* in the program, unless interface types are always 
> declared with novtable.
Yeah, I agree.  I have no idea if I can limit this to just pure functions, 
since I'm not totally sure about the use cases.  We have at least 1 test in our 
testbase that isn't virtual, but the context has been lost (might have been 
minimized from another repro).


https://reviews.llvm.org/D37308



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


[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-14 Thread Cameron via Phabricator via cfe-commits
cameron314 added inline comments.



Comment at: include/clang/Lex/Lexer.h:52
+  /// a BOM is present at the start of the file.
+  unsigned StartOffset;
+  /// \brief Size of the preamble in bytes.

ilya-biryukov wrote:
> cameron314 wrote:
> > ilya-biryukov wrote:
> > > We could simplify it further by removing `StartOffset`, leaving only 
> > > `Size`.
> > > If you look at the code, it always uses `StartOffset + Size` now, which 
> > > is effectively size with BOM.
> > > What do you think?
> > Yeah, I thought of that, but it's still nice to have the two separated.
> > 
> > ASTUnit.cpp, for example, checks if `Size != 0` to determine if there's a 
> > preamble (without considering the offset). This isn't in the diff because 
> > it was already like that.
> Could we simply return `Size = 0` from `ComputePreambleBounds` if we simply 
> skipped BOM and the preamble itself is empty?
> My concern is that currently it's very easy to forget adding `StartOffset` 
> and simply use `Size` when writing code that uses `PreambleBounds`. If we 
> only have `Size`, probability of mistakes is much lower.
Alright, sold. There's already other places that use the size without checking 
the offset, it turns out.


https://reviews.llvm.org/D37491



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


[PATCH] D37042: Teach clang to tolerate the 'p = nullptr + n' idiom used by glibc

2017-09-14 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor updated this revision to Diff 115262.
andrew.w.kaylor added a comment.

-Changed GNU idiom from extension to warning.
-Updated to ToT.


https://reviews.llvm.org/D37042

Files:
  include/clang/AST/Expr.h
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Expr.cpp
  lib/CodeGen/CGExprScalar.cpp
  lib/Sema/SemaExpr.cpp
  test/CodeGen/nullptr-arithmetic.c
  test/Sema/pointer-addition.c
  test/SemaCXX/nullptr-arithmetic.cpp

Index: lib/CodeGen/CGExprScalar.cpp
===
--- lib/CodeGen/CGExprScalar.cpp
+++ lib/CodeGen/CGExprScalar.cpp
@@ -2678,6 +2678,30 @@
   unsigned width = cast(index->getType())->getBitWidth();
   auto  = CGF.CGM.getDataLayout();
   auto PtrTy = cast(pointer->getType());
+
+  // Some versions of glibc and gcc use idioms (particularly in their malloc
+  // routines) that add a pointer-sized integer (known to be a pointer value)
+  // to a null pointer in order to cast the value back to an integer or as
+  // part of a pointer alignment algorithm.  This is undefined behavior, but
+  // we'd like to be able to compile programs that use it.
+  //
+  // Normally, we'd generate a GEP with a null-pointer base here in response
+  // to that code, but it's also UB to dereference a pointer created that
+  // way.  Instead (as an acknowledged hack to tolerate the idiom) we will
+  // generate a direct cast of the integer value to a pointer.
+  //
+  // The idiom (p = nullptr + N) is not met if any of the following are true:
+  //
+  //   The operation is subtraction.
+  //   The index is not pointer-sized.
+  //   The pointer type is not byte-sized.
+  //
+  if (BinaryOperator::isNullPointerArithmeticExtension(CGF.getContext(),
+   op.Opcode,
+   expr->getLHS(), 
+   expr->getRHS()))
+return CGF.Builder.CreateIntToPtr(index, pointer->getType());
+
   if (width != DL.getTypeSizeInBits(PtrTy)) {
 // Zero-extend or sign-extend the pointer value according to
 // whether the index is signed or not.
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -1829,6 +1829,45 @@
   return OverOps[Opc];
 }
 
+bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext ,
+  Opcode Opc,
+  Expr *LHS, Expr *RHS) {
+  if (Opc != BO_Add)
+return false;
+
+  // Check that we have one pointer and one integer operand.
+  Expr *PExp;
+  Expr *IExp;
+  if (LHS->getType()->isPointerType()) {
+if (!RHS->getType()->isIntegerType())
+  return false;
+PExp = LHS;
+IExp = RHS;
+  } else if (RHS->getType()->isPointerType()) {
+if (!LHS->getType()->isIntegerType())
+  return false;
+PExp = RHS;
+IExp = LHS;
+  } else {
+return false;
+  }
+
+  // Check that the pointer is a nullptr.
+  if (!PExp->IgnoreParenCasts()
+  ->isNullPointerConstant(Ctx, Expr::NPC_ValueDependentIsNotNull))
+return false;
+
+  // Check that the pointee type is char-sized.
+  const PointerType *PTy = PExp->getType()->getAs();
+  if (!PTy || !PTy->getPointeeType()->isCharType())
+return false;
+
+  // Check that the integer type is pointer-sized.
+  if (Ctx.getTypeSize(IExp->getType()) != Ctx.getTypeSize(PExp->getType()))
+return false;
+
+  return true;
+}
 InitListExpr::InitListExpr(const ASTContext , SourceLocation lbraceloc,
ArrayRef initExprs, SourceLocation rbraceloc)
   : Expr(InitListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false,
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -8486,6 +8486,21 @@
 << 0 /* one pointer */ << Pointer->getSourceRange();
 }
 
+/// \brief Diagnose invalid arithmetic on a null pointer.
+///
+/// If \p IsGNUIdiom is true, the operation is using the 'p = (i8*)nullptr + n'
+/// idiom, which we recognize as a GNU extension.
+///
+static void diagnoseArithmeticOnNullPointer(Sema , SourceLocation Loc,
+Expr *Pointer, bool IsGNUIdiom) {
+  if (IsGNUIdiom)
+S.Diag(Loc, diag::warn_gnu_null_ptr_arith)
+  << Pointer->getSourceRange();
+  else
+S.Diag(Loc, diag::warn_pointer_arith_null_ptr)
+  << S.getLangOpts().CPlusPlus << Pointer->getSourceRange();
+}
+
 /// \brief Diagnose invalid arithmetic on two function pointers.
 static void diagnoseArithmeticOnTwoFunctionPointers(Sema , SourceLocation Loc,
 Expr *LHS, Expr *RHS) {
@@ -8780,6 +8795,21 @@
   if (!IExp->getType()->isIntegerType())
 return InvalidOperands(Loc, LHS, RHS);
 
+  // 

[PATCH] D37860: [MSan] Enable use-after-dtor instrumentation by default.

2017-09-14 Thread Matt Morehouse via Phabricator via cfe-commits
morehouse created this revision.

Enable the compile-time flag -fsanitize-memory-use-after-dtor by
default. Note that the run-time option MSAN_OPTIONS=poison_in_dtor=1
still needs to be enabled for destructors to be poisoned.


https://reviews.llvm.org/D37860

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/fsanitize.c
  compiler-rt/test/msan/dtor-base-access.cc
  compiler-rt/test/msan/dtor-bit-fields.cc
  compiler-rt/test/msan/dtor-derived-class.cc
  compiler-rt/test/msan/dtor-member.cc
  compiler-rt/test/msan/dtor-multiple-inheritance-nontrivial-class-members.cc
  compiler-rt/test/msan/dtor-multiple-inheritance.cc
  compiler-rt/test/msan/dtor-trivial-class-members.cc
  compiler-rt/test/msan/dtor-trivial.cpp
  compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc
  compiler-rt/test/msan/dtor-vtable.cc
  compiler-rt/test/msan/use-after-dtor.cc

Index: compiler-rt/test/msan/use-after-dtor.cc
===
--- compiler-rt/test/msan/use-after-dtor.cc
+++ compiler-rt/test/msan/use-after-dtor.cc
@@ -1,13 +1,13 @@
-// RUN: %clangxx_msan %s -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
 
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
+// RUN: %clangxx_msan %s -O1 -fsanitize-memory-track-origins -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t >%t.out 2>&1
 // RUN: FileCheck %s --check-prefix=CHECK-ORIGINS < %t.out
 
 #include 
Index: compiler-rt/test/msan/dtor-vtable.cc
===
--- compiler-rt/test/msan/dtor-vtable.cc
+++ compiler-rt/test/msan/dtor-vtable.cc
@@ -1,16 +1,16 @@
-// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 
-// RUN: %clangxx_msan %s -DVPTRA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
+// RUN: %clangxx_msan %s -DVPTRA=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
 
-// RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
+// RUN: %clangxx_msan %s -DVPTRCA=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
 
-// RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
+// RUN: %clangxx_msan %s -DVPTRCB=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
 
-// RUN: %clangxx_msan %s -DVPTRC=1 -O2 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
+// RUN: %clangxx_msan %s -DVPTRC=1 -O2 -o %t && MSAN_OPTIONS=poison_in_dtor=1 not %run %t
 
 // Expected to quit due to invalid access when invoking
 // function using vtable.
Index: compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc
===
--- compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc
+++ compiler-rt/test/msan/dtor-vtable-multiple-inheritance.cc
@@ -1,14 +1,14 @@
-// RUN: %clangxx_msan %s -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O0 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 
-// RUN: %clangxx_msan %s -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
+// RUN: %clangxx_msan %s -O1 -o %t && MSAN_OPTIONS=poison_in_dtor=1 %run %t
 
-// RUN: %clangxx_msan %s -O2 -fsanitize=memory 

[PATCH] D31363: [libc++] Remove cmake glob for source files

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

This depends on https://reviews.llvm.org/D37859 for the `SOURCE_DIR` parameter 
to `llvm_check_source_file_list`.


https://reviews.llvm.org/D31363



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


[PATCH] D31363: [libc++] Remove cmake glob for source files

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai updated this revision to Diff 115259.
smeenai added a comment.
Herald added a subscriber: fedor.sergeev.

Address comments


https://reviews.llvm.org/D31363

Files:
  benchmarks/CMakeLists.txt
  lib/CMakeLists.txt


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -1,13 +1,48 @@
 set(LIBCXX_LIB_CMAKEFILES_DIR 
"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"  PARENT_SCOPE)
 
-# Get sources
-# FIXME: Don't use glob here
-file(GLOB LIBCXX_SOURCES ../src/*.cpp)
+include(LLVMProcessSources)
+set(LIBCXX_SOURCES
+  ../src/algorithm.cpp
+  ../src/any.cpp
+  ../src/bind.cpp
+  ../src/chrono.cpp
+  ../src/condition_variable.cpp
+  ../src/debug.cpp
+  ../src/exception.cpp
+  ../src/functional.cpp
+  ../src/future.cpp
+  ../src/hash.cpp
+  ../src/ios.cpp
+  ../src/iostream.cpp
+  ../src/locale.cpp
+  ../src/memory.cpp
+  ../src/mutex.cpp
+  ../src/new.cpp
+  ../src/optional.cpp
+  ../src/random.cpp
+  ../src/regex.cpp
+  ../src/shared_mutex.cpp
+  ../src/stdexcept.cpp
+  ../src/string.cpp
+  ../src/strstream.cpp
+  ../src/system_error.cpp
+  ../src/thread.cpp
+  ../src/typeinfo.cpp
+  ../src/utility.cpp
+  ../src/valarray.cpp
+  ../src/variant.cpp
+  ../src/vector.cpp)
+llvm_check_source_file_list(${LIBCXX_SOURCES} SOURCE_DIR ../src)
 if(WIN32)
-  file(GLOB LIBCXX_WIN32_SOURCES ../src/support/win32/*.cpp)
+  set(LIBCXX_WIN32_SOURCES
+../src/support/win32/locale_win32.cpp
+../src/support/win32/support.cpp)
+  llvm_check_source_file_list(${LIBCXX_WIN32_SOURCES} SOURCE_DIR 
../src/support/win32)
   list(APPEND LIBCXX_SOURCES ${LIBCXX_WIN32_SOURCES})
 elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
-  file(GLOB LIBCXX_SOLARIS_SOURCES ../src/support/solaris/*.cpp)
+  set(LIBCXX_SOLARIS_SOURCES
+../src/support/solaris/xlocale.cpp)
+  llvm_check_source_file_list(${LIBCXX_SOLARIS_SOURCES} SOURCE_DIR 
../src/support/solaris)
   list(APPEND LIBCXX_SOURCES ${LIBCXX_SOLARIS_SOURCES})
 endif()
 
@@ -283,9 +318,15 @@
 add_custom_target(cxx DEPENDS ${LIBCXX_TARGETS})
 
 if (LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY)
-  file(GLOB LIBCXX_EXPERIMENTAL_SOURCES ../src/experimental/*.cpp)
+  set(LIBCXX_EXPERIMENTAL_SOURCES
+../src/experimental/memory_resource.cpp)
+  llvm_check_source_file_list(${LIBCXX_EXPERIMENTAL_SOURCES} SOURCE_DIR 
../src/experimental)
   if (LIBCXX_ENABLE_FILESYSTEM)
-file(GLOB LIBCXX_FILESYSTEM_SOURCES ../src/experimental/filesystem/*.cpp)
+set(LIBCXX_FILESYSTEM_SOURCES
+  ../src/experimental/filesystem/directory_iterator.cpp
+  ../src/experimental/filesystem/operations.cpp
+  ../src/experimental/filesystem/path.cpp)
+llvm_check_source_file_list(${LIBCXX_FILESYSTEM_SOURCES} SOURCE_DIR 
../src/experimental/filesystem)
   endif()
   add_library(cxx_experimental STATIC ${LIBCXX_EXPERIMENTAL_SOURCES} 
${LIBCXX_FILESYSTEM_SOURCES})
   if (LIBCXX_ENABLE_SHARED)
Index: benchmarks/CMakeLists.txt
===
--- benchmarks/CMakeLists.txt
+++ benchmarks/CMakeLists.txt
@@ -143,7 +143,16 @@
 #==
 # Register Benchmark tests
 #==
-file(GLOB BENCHMARK_TESTS "*.bench.cpp")
+include(LLVMProcessSources)
+set(BENCHMARK_TESTS
+  algorithms.bench.cpp
+  filesystem.bench.cpp
+  string.bench.cpp
+  stringstream.bench.cpp
+  unordered_set_operations.bench.cpp
+  util_smartptr.bench.cpp
+  vector_operations.bench.cpp)
+llvm_check_source_file_list(${BENCHMARK_TESTS})
 foreach(test_path ${BENCHMARK_TESTS})
   get_filename_component(test_file "${test_path}" NAME)
   string(REPLACE ".bench.cpp" "" test_name "${test_file}")


Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -1,13 +1,48 @@
 set(LIBCXX_LIB_CMAKEFILES_DIR "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}"  PARENT_SCOPE)
 
-# Get sources
-# FIXME: Don't use glob here
-file(GLOB LIBCXX_SOURCES ../src/*.cpp)
+include(LLVMProcessSources)
+set(LIBCXX_SOURCES
+  ../src/algorithm.cpp
+  ../src/any.cpp
+  ../src/bind.cpp
+  ../src/chrono.cpp
+  ../src/condition_variable.cpp
+  ../src/debug.cpp
+  ../src/exception.cpp
+  ../src/functional.cpp
+  ../src/future.cpp
+  ../src/hash.cpp
+  ../src/ios.cpp
+  ../src/iostream.cpp
+  ../src/locale.cpp
+  ../src/memory.cpp
+  ../src/mutex.cpp
+  ../src/new.cpp
+  ../src/optional.cpp
+  ../src/random.cpp
+  ../src/regex.cpp
+  ../src/shared_mutex.cpp
+  ../src/stdexcept.cpp
+  ../src/string.cpp
+  ../src/strstream.cpp
+  ../src/system_error.cpp

[PATCH] D37308: Fix the __interface inheritence rules to work better with IUnknown and IDispatch

2017-09-14 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: lib/AST/DeclCXX.cpp:1474
+bool CXXRecordDecl::isInterfaceLike() const {
+  // All __interfaces are inheritently interface like.
+  if (isInterface())

nit: use "interface-like" for consistency with the comments below



Comment at: lib/AST/DeclCXX.cpp:1477
+return true;
+
+  // No interface-like types can have a user declared constructor, destructor,

What should this do for incomplete types, i.e. forward decls and templates 
undergoing instantiation? The only caller of this checks for this case before 
hand, but maybe we should `assert(hasDefinition());` on entry.



Comment at: lib/AST/DeclCXX.cpp:1478
+
+  // No interface-like types can have a user declared constructor, destructor,
+  // friends, VBases, conersion functions, or fields.  Additionally, lambdas

Maybe "Interface-like types cannot have ..."

Can an interface-like type have an explicitly defaulted copy ctor? That will be 
user declared, but it will probably be trivial.



Comment at: lib/AST/DeclCXX.cpp:1486-1489
+  // No interface-like type can have a method with a definition.
+  for (const auto *const Method : methods())
+if (Method->isDefined())
+  return false;

Huh, so they can be declared, but they don't have to be pure.



Comment at: lib/AST/DeclCXX.cpp:1516-1517
+const auto *Base = BS.getType()->getAsCXXRecordDecl();
+if (Base->isInterface())
+  continue;
+if (Base->isInterfaceLike()) {

Are you sure you want this? MSVC rejects the test case that exercises this case.



Comment at: test/SemaCXX/ms-iunknown-outofline-def.cpp:9-10
+void IUnknown::foo() {}
+// expected-error@+1{{interface type cannot inherit from}}
+__interface HasError : public IUnknown {}; 

Again, this is a pretty weird error. If the method isn't pure, there must be a 
definition *somewhere* in the program, unless interface types are always 
declared with novtable.



Comment at: test/SemaCXX/ms-iunknown.cpp:24
+
+struct fine_base : temp_iface, IUnknown {};
+__interface can_inherit: public fine_base{};

MSVC seems to reject this use of multiple inheritance. Are you sure it doesn't 
just require single-inheritance from an interface-like type? If so, maybe you 
can simplify the loop over the bases?


https://reviews.llvm.org/D37308



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


[PATCH] D36713: [libc++] Add a persistent way to disable availability

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

@mclow.lists, any final verdict here? I ended up doing this differently for my 
internal use case, so if you think this isn't generally useful, I'm happy to 
abandon.


https://reviews.llvm.org/D36713



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


[PATCH] D36720: [libc++] Prevent stale site configuration headers

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313284: [libc++] Prevent stale site configuration headers 
(authored by smeenai).

Changed prior to commit:
  https://reviews.llvm.org/D36720?vs=111096=115250#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36720

Files:
  libcxx/trunk/CMakeLists.txt


Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -615,9 +615,10 @@
   config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 endif()
 
+set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site")
 if (LIBCXX_NEEDS_SITE_CONFIG)
   configure_file("include/__config_site.in"
- "${LIBCXX_BINARY_DIR}/__config_site"
+ "${site_config_path}"
  @ONLY)
 
   # Provide the config definitions by included the generated __config_site
@@ -627,6 +628,11 @@
   else()
 add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
   endif()
+else()
+  if (EXISTS "${site_config_path}")
+message(STATUS "Removing stale site configuration ${site_config_path}")
+file(REMOVE "${site_config_path}")
+  endif()
 endif()
 
 
#===


Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -615,9 +615,10 @@
   config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 endif()
 
+set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site")
 if (LIBCXX_NEEDS_SITE_CONFIG)
   configure_file("include/__config_site.in"
- "${LIBCXX_BINARY_DIR}/__config_site"
+ "${site_config_path}"
  @ONLY)
 
   # Provide the config definitions by included the generated __config_site
@@ -627,6 +628,11 @@
   else()
 add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
   endif()
+else()
+  if (EXISTS "${site_config_path}")
+message(STATUS "Removing stale site configuration ${site_config_path}")
+file(REMOVE "${site_config_path}")
+  endif()
 endif()
 
 #===
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r313284 - [libc++] Prevent stale site configuration headers

2017-09-14 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Thu Sep 14 11:23:43 2017
New Revision: 313284

URL: http://llvm.org/viewvc/llvm-project?rev=313284=rev
Log:
[libc++] Prevent stale site configuration headers

If we define cmake macros that require a site config, and then undefine
all such macros, a stale site config header will be left behind.
Explicitly delete any generate site config if we don't need one to avoid
this.

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

Modified:
libcxx/trunk/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=313284=313283=313284=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Thu Sep 14 11:23:43 2017
@@ -615,9 +615,10 @@ if (DEFINED WIN32 AND LIBCXX_ENABLE_STAT
   config_define(ON _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
 endif()
 
+set(site_config_path "${LIBCXX_BINARY_DIR}/__config_site")
 if (LIBCXX_NEEDS_SITE_CONFIG)
   configure_file("include/__config_site.in"
- "${LIBCXX_BINARY_DIR}/__config_site"
+ "${site_config_path}"
  @ONLY)
 
   # Provide the config definitions by included the generated __config_site
@@ -627,6 +628,11 @@ if (LIBCXX_NEEDS_SITE_CONFIG)
   else()
 add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site")
   endif()
+else()
+  if (EXISTS "${site_config_path}")
+message(STATUS "Removing stale site configuration ${site_config_path}")
+file(REMOVE "${site_config_path}")
+  endif()
 endif()
 
 
#===


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


[PATCH] D36720: [libc++] Prevent stale site configuration headers

2017-09-14 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added inline comments.



Comment at: CMakeLists.txt:633
+  if (EXISTS "${site_config_path}")
+file(REMOVE "${site_config_path}")
+  endif()

EricWF wrote:
> Maybe print a warning or a message here? While it seems useful to 
> re-configure and remove the stale header without requiring the user delete 
> the build directory, it does seem like an odd thing to do, at least silently.
> 
> Since this shouldn't be happening very often, I don't think it would be too 
> noisy to explicitly warn the user what is going on.
> 
Sounds good.


https://reviews.llvm.org/D36720



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


[PATCH] D37856: [refactor] add support for refactoring options

2017-09-14 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

This patch adds initial support for refactoring options. One can now use 
optional and required `std::string` options.

The options are implemented in the following manner:

- A base interface `RefactoringOption` declares methods that describe the 
option's name, description and whether or not it's required. It also declares a 
method that takes in a `RefactoringOptionConsumer` that will visit the option 
and its typed value.
- A visitor interface `RefactoringOptionConsumer` declares the `handle` methods 
that provide an overload for each valid option type (std::string, etc).
- Classes `OptionalRequiredOption` and `RequiredRefactoringOption` partially 
implement the `RefactoringOption` interface, store the value and provide a 
getter for the value. The individual options then just have to implement 
`getName` and `getDescription`.
- The `RefactoringOptionsRequirement` is a base requirement class the declares 
a method that can returns all of the options used in a single requirement.
- The `OptionRequirement` class is a helper class that implements a refactoring 
action rule requirement for a particular option.

`clang-refactor` now creates command-line arguments for each unique option used 
by all rules in an action.

This patch also adds a `NewNameOption` for the local-rename refactoring action 
to ensure that options work.


Repository:
  rL LLVM

https://reviews.llvm.org/D37856

Files:
  include/clang/Tooling/Refactoring/RefactoringActionRule.h
  include/clang/Tooling/Refactoring/RefactoringActionRuleRequirements.h
  include/clang/Tooling/Refactoring/RefactoringActionRulesInternal.h
  include/clang/Tooling/Refactoring/RefactoringOption.h
  include/clang/Tooling/Refactoring/RefactoringOptionConsumer.h
  include/clang/Tooling/Refactoring/RefactoringOptions.h
  include/clang/Tooling/Refactoring/Rename/RenamingAction.h
  lib/Tooling/Refactoring/Rename/RenamingAction.cpp
  test/Refactor/LocalRename/Field.cpp
  test/Refactor/tool-test-support.c
  tools/clang-refactor/ClangRefactor.cpp

Index: tools/clang-refactor/ClangRefactor.cpp
===
--- tools/clang-refactor/ClangRefactor.cpp
+++ tools/clang-refactor/ClangRefactor.cpp
@@ -18,6 +18,7 @@
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Refactoring/RefactoringAction.h"
+#include "clang/Tooling/Refactoring/RefactoringOptions.h"
 #include "clang/Tooling/Refactoring/Rename/RenamingAction.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/Support/CommandLine.h"
@@ -32,10 +33,10 @@
 
 namespace opts {
 
-static cl::OptionCategory CommonRefactorOptions("Common refactoring options");
+static cl::OptionCategory CommonRefactorOptions("Refactoring options");
 
 static cl::opt Verbose("v", cl::desc("Use verbose output"),
- cl::cat(CommonRefactorOptions),
+ cl::cat(cl::GeneralCategory),
  cl::sub(*cl::AllSubCommands));
 } // end namespace opts
 
@@ -116,6 +117,98 @@
   return nullptr;
 }
 
+/// A container that stores the command-line options used by a single
+/// refactoring option.
+class RefactoringActionCommandLineOptions {
+public:
+  template 
+  void addOption(const RefactoringOption ,
+ std::unique_ptr CLOption);
+
+  const cl::opt &
+  getStringOption(const RefactoringOption ) const {
+auto It = StringOptions.find();
+return *It->second;
+  }
+
+private:
+  llvm::DenseMap>>
+  StringOptions;
+};
+
+template <>
+void RefactoringActionCommandLineOptions::addOption(
+const RefactoringOption ,
+std::unique_ptr CLOption) {
+  StringOptions[] = std::move(CLOption);
+}
+
+/// Passes the command-line option values to the options used by a single
+/// refactoring action rule.
+class CommandLineRefactoringOptionConsumer final
+: public RefactoringOptionConsumer {
+public:
+  CommandLineRefactoringOptionConsumer(
+  const RefactoringActionCommandLineOptions )
+  : Options(Options) {}
+
+  void handle(const RefactoringOption ,
+  Optional ) override {
+const cl::opt  = Options.getStringOption(Opt);
+if (!CLOpt.getValue().empty()) {
+  Value = CLOpt.getValue();
+  return;
+}
+Value = None;
+if (Opt.isRequired())
+  MissingRequiredOptions.push_back();
+  }
+
+  ArrayRef getMissingRequiredOptions() const {
+return MissingRequiredOptions;
+  }
+
+private:
+  llvm::SmallVector MissingRequiredOptions;
+  const RefactoringActionCommandLineOptions 
+};
+
+/// Creates the refactoring options used by all the rules in a single
+/// refactoring action.
+class CommandLineRefactoringOptionCreator final
+: public RefactoringOptionConsumer {
+public:
+  CommandLineRefactoringOptionCreator(
+  cl::OptionCategory , cl::SubCommand ,
+  RefactoringActionCommandLineOptions )
+  : Category(Category), Subcommand(Subcommand), 

[PATCH] D37855: [bindings] allow null strings in Python 3

2017-09-14 Thread Masud Rahman via Phabricator via cfe-commits
frutiger created this revision.

Some API calls accept 'NULL' instead of a char array (e.g. the second
argument to 'clang_ParseTranslationUnit').  For Python 3 compatibility,
all strings are passed through 'c_interop_string' which expects to
receive only 'bytes' or 'str' objects.  This change extends this
behavior to additionally allow 'None' to be supplied.

A test case was added which breaks in Python 3, and is fixed by this
change.  All the test cases pass in both, Python 2 and Python 3.


https://reviews.llvm.org/D37855

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_index.py


Index: bindings/python/tests/cindex/test_index.py
===
--- bindings/python/tests/cindex/test_index.py
+++ bindings/python/tests/cindex/test_index.py
@@ -13,3 +13,5 @@
 assert isinstance(index, Index)
 tu = index.parse(os.path.join(kInputsDir, 'hello.cpp'))
 assert isinstance(tu, TranslationUnit)
+tu = index.parse(None, ['-c', os.path.join(kInputsDir, 'hello.cpp')])
+assert isinstance(tu, TranslationUnit)
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -94,6 +94,9 @@
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
+if param is None:
+# Support passing null to C functions expecting char arrays
+return None
 raise TypeError("Cannot convert '{}' to 
'{}'".format(type(param).__name__, cls.__name__))
 
 @staticmethod


Index: bindings/python/tests/cindex/test_index.py
===
--- bindings/python/tests/cindex/test_index.py
+++ bindings/python/tests/cindex/test_index.py
@@ -13,3 +13,5 @@
 assert isinstance(index, Index)
 tu = index.parse(os.path.join(kInputsDir, 'hello.cpp'))
 assert isinstance(tu, TranslationUnit)
+tu = index.parse(None, ['-c', os.path.join(kInputsDir, 'hello.cpp')])
+assert isinstance(tu, TranslationUnit)
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -94,6 +94,9 @@
 return cls(param)
 if isinstance(param, bytes):
 return cls(param)
+if param is None:
+# Support passing null to C functions expecting char arrays
+return None
 raise TypeError("Cannot convert '{}' to '{}'".format(type(param).__name__, cls.__name__))
 
 @staticmethod
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37573: [bindings] add Cursor.linkage

2017-09-14 Thread Masud Rahman via Phabricator via cfe-commits
frutiger added a comment.

@compnerd if nothing else remains here, I would also appreciate it if you could 
merge this.  Thanks!


https://reviews.llvm.org/D37573



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


[PATCH] D37573: [bindings] add Cursor.linkage

2017-09-14 Thread Masud Rahman via Phabricator via cfe-commits
frutiger updated this revision to Diff 115246.
frutiger added a comment.

Rebased on top of the latest master.


https://reviews.llvm.org/D37573

Files:
  bindings/python/clang/cindex.py
  bindings/python/tests/cindex/test_linkage.py


Index: bindings/python/tests/cindex/test_linkage.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,30 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, 'no_linkage')
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, 'internal')
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, 'unique_external')
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, 'external')
+assert external.linkage == LinkageKind.EXTERNAL
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def linkage(self):
+"""Return the linkage of this cursor."""
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
 @property
 def tls_kind(self):
 """Return the thread-local storage (TLS) kind of this cursor."""
@@ -2069,6 +2077,25 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class LinkageKind(BaseEnumeration):
+"""Describes the kind of linkage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)
+LinkageKind.EXTERNAL = LinkageKind(4)
+
 class TLSKind(BaseEnumeration):
 """Describes the kind of thread-local storage (TLS) of a cursor."""
 
@@ -4089,6 +4116,7 @@
 'File',
 'FixIt',
 'Index',
+'LinkageKind',
 'SourceLocation',
 'SourceRange',
 'TLSKind',


Index: bindings/python/tests/cindex/test_linkage.py
===
--- /dev/null
+++ bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,30 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+"""Ensure that linkage specifers are available on cursors"""
+
+tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+no_linkage = get_cursor(tu.cursor, 'no_linkage')
+assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+internal = get_cursor(tu.cursor, 'internal')
+assert internal.linkage == LinkageKind.INTERNAL
+
+unique_external = get_cursor(tu.cursor, 'unique_external')
+assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+external = get_cursor(tu.cursor, 'external')
+assert external.linkage == LinkageKind.EXTERNAL
+
Index: bindings/python/clang/cindex.py
===
--- bindings/python/clang/cindex.py
+++ bindings/python/clang/cindex.py
@@ -1548,6 +1548,14 @@
 
 return self._loc
 
+@property
+def linkage(self):
+"""Return the linkage of this cursor."""
+if not hasattr(self, '_linkage'):
+self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+return LinkageKind.from_id(self._linkage)
+
 @property
 def tls_kind(self):
 """Return the thread-local storage (TLS) kind of this cursor."""
@@ -2069,6 +2077,25 @@
 RefQualifierKind.LVALUE = RefQualifierKind(1)
 RefQualifierKind.RVALUE = RefQualifierKind(2)
 
+class LinkageKind(BaseEnumeration):
+"""Describes the kind of linkage of a cursor."""
+
+# The unique kind objects, indexed by id.
+_kinds = []
+_name_map = None
+
+def from_param(self):
+return self.value
+
+def __repr__(self):
+return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = 

Re: [libcxxabi] r313215 - Reland "When built with ASan, __cxa_throw calls __asan_handle_no_return"

2017-09-14 Thread Kostya Serebryany via cfe-commits
The bot is unhappy:
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/7880/steps/build%20libcxx%2Fasan/logs/stdio

1/6] Building CXX object
projects/libcxxabi/src/CMakeFiles/cxxabi_objects.dir/cxa_exception.cpp.o
FAILED: projects/libcxxabi/src/CMakeFiles/cxxabi_objects.dir/cxa_exception.cpp.o
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm_build0/bin/clang++
  -DHAVE___CXA_THREAD_ATEXIT_IMPL -D_DEBUG -D_GNU_SOURCE
-D_LIBCPP_DISABLE_EXTERN_TEMPLATE -D_LIBCXXABI_BUILDING_LIBRARY
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
-Iprojects/libcxxabi/src
-I/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/projects/libcxxabi/src
-I/usr/include/libxml2 -Iinclude
-I/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/include
-I/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/projects/libcxxabi/include
-I/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/projects/libcxx/include
-fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall
-W -Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wmissing-field-initializers -pedantic -Wno-long-long
-Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor
-Wstring-conversion -fno-omit-frame-pointer -gline-tables-only
-fsanitize=address -fsanitize-address-use-after-scope
-fcolor-diagnostics -ffunction-sections -fdata-sections  -O3  -fPIC
-UNDEBUG -nostdinc++ -Werror=return-type -W -Wall -Wchar-subscripts
-Wconversion -Wmismatched-tags -Wmissing-braces -Wnewline-eof
-Wunused-function -Wshadow -Wshorten-64-to-32 -Wsign-compare
-Wsign-conversion -Wstrict-aliasing=2 -Wstrict-overflow=4
-Wunused-parameter -Wunused-variable -Wwrite-strings -Wundef
-Wno-error -pedantic -fstrict-aliasing -funwind-tables -D_DEBUG
-UNDEBUG -std=c++11 -MD -MT
projects/libcxxabi/src/CMakeFiles/cxxabi_objects.dir/cxa_exception.cpp.o
-MF projects/libcxxabi/src/CMakeFiles/cxxabi_objects.dir/cxa_exception.cpp.o.d
-o projects/libcxxabi/src/CMakeFiles/cxxabi_objects.dir/cxa_exception.cpp.o
-c 
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/projects/libcxxabi/src/cxa_exception.cpp
/mnt/b/sanitizer-buildbot3/sanitizer-x86_64-linux-fast/build/llvm/projects/libcxxabi/src/cxa_exception.cpp:227:5:
error: use of undeclared identifier '__asan_handle_no_return'
__asan_handle_no_return();
^


On Wed, Sep 13, 2017 at 4:35 PM, Petr Hosek via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: phosek
> Date: Wed Sep 13 16:35:07 2017
> New Revision: 313215
>
> URL: http://llvm.org/viewvc/llvm-project?rev=313215=rev
> Log:
> Reland "When built with ASan, __cxa_throw calls __asan_handle_no_return"
>
> The ASan runtime on many systems intercepts cxa_throw just so it
> can call asan_handle_no_return first. Some newer systems such as
> Fuchsia don't use interceptors on standard library functions at all,
> but instead use sanitizer-instrumented versions of the standard
> libraries. When libc++abi is built with ASan, cxa_throw can just
> call asan_handle_no_return itself so no interceptor is required.
>
> Patch by Roland McGrath
>
> Differential Revision: https://reviews.llvm.org/D37229
>
> Modified:
> libcxxabi/trunk/src/cxa_exception.cpp
>
> Modified: libcxxabi/trunk/src/cxa_exception.cpp
> URL: http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/
> cxa_exception.cpp?rev=313215=313214=313215=diff
> 
> ==
> --- libcxxabi/trunk/src/cxa_exception.cpp (original)
> +++ libcxxabi/trunk/src/cxa_exception.cpp Wed Sep 13 16:35:07 2017
> @@ -19,6 +19,10 @@
>  #include "cxa_handlers.hpp"
>  #include "fallback_malloc.h"
>
> +#if __has_feature(address_sanitizer)
> +#include 
> +#endif
> +
>  // +---+-+-
> --+
>  // | __cxa_exception   | _Unwind_Exception CLNGC++\0 | thrown
> object |
>  // +---+-+-
> --+
> @@ -217,6 +221,12 @@ __cxa_throw(void *thrown_object, std::ty
>  globals->uncaughtExceptions += 1;   // Not atomically, since globals
> are thread-local
>
>  exception_header->unwindHeader.exception_cleanup =
> exception_cleanup_func;
> +
> +#if __has_feature(address_sanitizer)
> +// Inform the ASan runtime that now might be a good time to clean
> stuff up.
> +__asan_handle_no_return();
> +#endif
> +
>  #ifdef __USING_SJLJ_EXCEPTIONS__
>  _Unwind_SjLj_RaiseException(_header->unwindHeader);
>  #else
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37804: [OpenCL] Handle address space conversion while setting type alignment

2017-09-14 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:957
 
-return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
+return Builder.CreatePointerBitCastOrAddrSpaceCast(
+Addr, ConvertType(E->getType()));

yaxunl wrote:
> Better assert that only CK_AddressSpaceConversion allows different addr 
> spaces in target type.
It seems for consistency then we would have to assert for both different ASes 
in non-`addrspacecast` case and equivalent ASes in the other case.

As condition becomes complicated then, I could as well split into either 
creating `bitcast` or `addrspacecast` explicitly at a cost of one simple check 
in the return statement but that would be in release build too. 


https://reviews.llvm.org/D37804



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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-14 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek marked 3 inline comments as done.
Prazek added a comment.

Thanks for help. I checked and docs build and looks legit. Sorry that it took 
so long.


Repository:
  rL LLVM

https://reviews.llvm.org/D33852



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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-14 Thread Piotr Padlewski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL313278: Enable __declspec(selectany) on any platform 
(authored by Prazek).

Repository:
  rL LLVM

https://reviews.llvm.org/D33852

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/test/Sema/attr-selectany.c
  cfe/trunk/test/SemaCXX/attr-selectany.cpp


Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -3192,3 +3192,18 @@
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation 
`_
+or `msvc documentation `_.
+}];
+}
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -2472,9 +2472,9 @@
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
-  let Documentation = [Undocumented];
+  let Documentation = [SelectAnyDocs];
 }
 
 def Thread : Attr {
Index: cfe/trunk/test/Sema/attr-selectany.c
===
--- cfe/trunk/test/Sema/attr-selectany.c
+++ cfe/trunk/test/Sema/attr-selectany.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
 
Index: cfe/trunk/test/SemaCXX/attr-selectany.cpp
===
--- cfe/trunk/test/SemaCXX/attr-selectany.cpp
+++ cfe/trunk/test/SemaCXX/attr-selectany.cpp
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions 
-fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}


Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -3192,3 +3192,18 @@
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation `_
+or `msvc documentation `_.
+}];
+}
Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -2472,9 +2472,9 @@
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
-  let Documentation = [Undocumented];
+  let Documentation = [SelectAnyDocs];
 }
 
 def Thread : Attr {
Index: cfe/trunk/test/Sema/attr-selectany.c
===
--- cfe/trunk/test/Sema/attr-selectany.c
+++ cfe/trunk/test/Sema/attr-selectany.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++
 
Index: cfe/trunk/test/SemaCXX/attr-selectany.cpp

r313278 - Enable __declspec(selectany) on any platform

2017-09-14 Thread Piotr Padlewski via cfe-commits
Author: prazek
Date: Thu Sep 14 10:33:08 2017
New Revision: 313278

URL: http://llvm.org/viewvc/llvm-project?rev=313278=rev
Log:
Enable __declspec(selectany) on any platform

Summary:
This feature was disabled probably by mistake in rL300562
This fixes bug https://bugs.llvm.org/show_bug.cgi?id=33285

Reviewers: davide, rnk

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/test/Sema/attr-selectany.c
cfe/trunk/test/SemaCXX/attr-selectany.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=313278=313277=313278=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Sep 14 10:33:08 2017
@@ -2472,9 +2472,9 @@ def DLLImport : InheritableAttr, TargetS
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
-  let Documentation = [Undocumented];
+  let Documentation = [SelectAnyDocs];
 }
 
 def Thread : Attr {

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=313278=313277=313278=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Thu Sep 14 10:33:08 2017
@@ -3192,3 +3192,18 @@ This attribute can be added to an Object
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation 
`_
+or `msvc documentation `_.
+}];
+}

Modified: cfe/trunk/test/Sema/attr-selectany.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-selectany.c?rev=313278=313277=313278=diff
==
--- cfe/trunk/test/Sema/attr-selectany.c (original)
+++ cfe/trunk/test/Sema/attr-selectany.c Thu Sep 14 10:33:08 2017
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
 

Modified: cfe/trunk/test/SemaCXX/attr-selectany.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-selectany.cpp?rev=313278=313277=313278=diff
==
--- cfe/trunk/test/SemaCXX/attr-selectany.cpp (original)
+++ cfe/trunk/test/SemaCXX/attr-selectany.cpp Thu Sep 14 10:33:08 2017
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions 
-fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}


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


[PATCH] D33852: Enable __declspec(selectany) on linux

2017-09-14 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 115243.
Prazek marked 8 inline comments as done.
Prazek added a comment.

Fixed links


https://reviews.llvm.org/D33852

Files:
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  test/Sema/attr-selectany.c
  test/SemaCXX/attr-selectany.cpp


Index: test/SemaCXX/attr-selectany.cpp
===
--- test/SemaCXX/attr-selectany.cpp
+++ test/SemaCXX/attr-selectany.cpp
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions 
-fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility 
-fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}
Index: test/Sema/attr-selectany.c
===
--- test/Sema/attr-selectany.c
+++ test/Sema/attr-selectany.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
 
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3149,3 +3149,18 @@
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation 
`_
+or `msvc documentation `_.
+}];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -2472,9 +2472,9 @@
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr {
+def SelectAny : InheritableAttr {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
-  let Documentation = [Undocumented];
+  let Documentation = [SelectAnyDocs];
 }
 
 def Thread : Attr {


Index: test/SemaCXX/attr-selectany.cpp
===
--- test/SemaCXX/attr-selectany.cpp
+++ test/SemaCXX/attr-selectany.cpp
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
Index: test/Sema/attr-selectany.c
===
--- test/Sema/attr-selectany.c
+++ test/Sema/attr-selectany.c
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++
 
Index: include/clang/Basic/AttrDocs.td
===
--- include/clang/Basic/AttrDocs.td
+++ include/clang/Basic/AttrDocs.td
@@ -3149,3 +3149,18 @@
 ensure that this class cannot be subclassed.
   }];
 }
+
+
+def SelectAnyDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute appertains to a global symbol, causing it to have a weak
+definition (
+`linkonce `_
+), allowing the linker to select any definition.
+
+For more information see
+`gcc documentation `_
+or `msvc documentation `_.
+}];
+}
Index: include/clang/Basic/Attr.td
===
--- include/clang/Basic/Attr.td
+++ 

Re: r313011 - [X86] Lower _mm[256|512]_[mask[z]]_avg_epu[8|16] intrinsics to native llvm IR

2017-09-14 Thread Ben Langmuir via cfe-commits
Sorry, I have no particular insight.  My commit was reapplied verbatim shortly 
after that and the tests passed, so I’m not sure if there’s any relation.

> On Sep 13, 2017, at 4:16 AM, Tsafrir, Yael  wrote:
> 
> Hello Galina,
>  
> I tried to re-create the issue but with no success. I ran the test on 
> versions before and after my commit, using your builder’s cmake properties, 
> and the test passed each time.
> There doesn’t seem to be a connection between my commit’s changes and the 
> failed test.
>  
> We checked the test’s history and the message in 
> https://reviews.llvm.org/rL259715  
> suggests that the last time this test was modified, there were buildbots 
> failures – could those failures be related or similar to the failures we are 
> seeing now?
>  
> I’ve CC’d Ben Langmuir and Quentin Colombet as they dealt with rL259715.
>  
> Is there anyone who could help or provide more details about the test failure?
>  
> Thanks,
> Yael
>   <>
> From: Galina Kistanova [mailto:gkistan...@gmail.com 
> ] 
> Sent: Tuesday, September 12, 2017 21:16
> To: Tsafrir, Yael >
> Cc: cfe-commits  >
> Subject: Re: r313011 - [X86] Lower _mm[256|512]_[mask[z]]_avg_epu[8|16] 
> intrinsics to native llvm IR
>  
> Hello Yael,
> 
> It looks like this commit broke one of our builders:
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/17121
>  
> 
> 
> . . . 
> Failing Tests (1):
> Clang :: Modules/builtins.m
> 
> Please have a look?
> 
> Thanks
> 
> Galina
> 
>  
> On Tue, Sep 12, 2017 at 12:46 AM, Yael Tsafrir via cfe-commits 
> > wrote:
> Author: ytsafrir
> Date: Tue Sep 12 00:46:32 2017
> New Revision: 313011
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=313011=rev 
> 
> Log:
> [X86] Lower _mm[256|512]_[mask[z]]_avg_epu[8|16] intrinsics to native llvm IR
> 
> Differential Revision: https://reviews.llvm.org/D37562 
> 
> 
> Modified:
> cfe/trunk/include/clang/Basic/BuiltinsX86.def
> cfe/trunk/lib/Headers/avx2intrin.h
> cfe/trunk/lib/Headers/avx512bwintrin.h
> cfe/trunk/lib/Headers/emmintrin.h
> cfe/trunk/test/CodeGen/avx2-builtins.c
> cfe/trunk/test/CodeGen/avx512bw-builtins.c
> cfe/trunk/test/CodeGen/avx512vlbw-builtins.c
> cfe/trunk/test/CodeGen/builtins-x86.c
> cfe/trunk/test/CodeGen/sse2-builtins.c
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=313011=313010=313011=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Tue Sep 12 00:46:32 2017
> @@ -266,8 +266,6 @@ TARGET_BUILTIN(__builtin_ia32_paddusw128
>  TARGET_BUILTIN(__builtin_ia32_psubusb128, "V16cV16cV16c", "", "sse2")
>  TARGET_BUILTIN(__builtin_ia32_psubusw128, "V8sV8sV8s", "", "sse2")
>  TARGET_BUILTIN(__builtin_ia32_pmulhw128, "V8sV8sV8s", "", "sse2")
> -TARGET_BUILTIN(__builtin_ia32_pavgb128, "V16cV16cV16c", "", "sse2")
> -TARGET_BUILTIN(__builtin_ia32_pavgw128, "V8sV8sV8s", "", "sse2")
>  TARGET_BUILTIN(__builtin_ia32_pmaxub128, "V16cV16cV16c", "", "sse2")
>  TARGET_BUILTIN(__builtin_ia32_pmaxsw128, "V8sV8sV8s", "", "sse2")
>  TARGET_BUILTIN(__builtin_ia32_pminub128, "V16cV16cV16c", "", "sse2")
> @@ -522,8 +520,6 @@ TARGET_BUILTIN(__builtin_ia32_paddusw256
>  TARGET_BUILTIN(__builtin_ia32_psubusb256, "V32cV32cV32c", "", "avx2")
>  TARGET_BUILTIN(__builtin_ia32_psubusw256, "V16sV16sV16s", "", "avx2")
>  TARGET_BUILTIN(__builtin_ia32_palignr256, "V32cV32cV32cIi", "", "avx2")
> -TARGET_BUILTIN(__builtin_ia32_pavgb256, "V32cV32cV32c", "", "avx2")
> -TARGET_BUILTIN(__builtin_ia32_pavgw256, "V16sV16sV16s", "", "avx2")
>  TARGET_BUILTIN(__builtin_ia32_pblendvb256, "V32cV32cV32cV32c", "", "avx2")
>  TARGET_BUILTIN(__builtin_ia32_phaddw256, "V16sV16sV16s", "", "avx2")
>  TARGET_BUILTIN(__builtin_ia32_phaddd256, "V8iV8iV8i", "", "avx2")
> @@ -1075,8 +1071,6 @@ TARGET_BUILTIN(__builtin_ia32_paddsb512_
>  TARGET_BUILTIN(__builtin_ia32_paddsw512_mask, "V32sV32sV32sV32sUi", "", 
> "avx512bw")
>  TARGET_BUILTIN(__builtin_ia32_paddusb512_mask, "V64cV64cV64cV64cULLi", "", 
> "avx512bw")
>  TARGET_BUILTIN(__builtin_ia32_paddusw512_mask, "V32sV32sV32sV32sUi", "", 
> "avx512bw")
> -TARGET_BUILTIN(__builtin_ia32_pavgb512_mask, "V64cV64cV64cV64cULLi", "", 
> "avx512bw")
> 

[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternBlock

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 115240.
PriMee added a comment.

Thank you for noticing! Done.


https://reviews.llvm.org/D37845

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1704,7 +1704,42 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) {
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {}");
+  verifyFormat("extern \"C\" {\n"
+   "int foo();\n"
+   "}");
+  verifyFormat("extern \"C\" int foo() {}");
+  verifyFormat("extern \"C\" int foo();");
+  verifyFormat("extern \"C\" int foo() {\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("extern \"C\" int foo() {}", Style);
+  verifyFormat("extern \"C\" int foo();", Style);
+  verifyFormat("extern \"C\" int foo()\n"
+   "{\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}",
+   Style);
+
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.BraceWrapping.SplitEmptyRecord = false;
+  verifyFormat("extern \"C\"\n"
+   "{}",
+   Style);
+  verifyFormat("extern \"C\"\n"
+   "{\n"
+   "  int foo();\n"
+   "}",
+   Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
@@ -9979,6 +10014,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterObjCDeclaration);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterStruct);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterUnion);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1039,7 +1039,12 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+if (Style.BraceWrapping.AfterExternBlock) {
+  addUnwrappedLine();
+  parseBlock(/*MustBeDeclaration=*/true);
+} else {
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+}
 addUnwrappedLine();
 return;
   }
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -233,9 +233,10 @@
   if (Tok && Tok->is(tok::kw_typedef))
 Tok = Tok->getNextNonComment();
   if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
-  Keywords.kw_interface))
+  tok::kw_extern, Keywords.kw_interface))
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
-? tryMergeSimpleBlock(I, E, Limit) : 0;
+   ? tryMergeSimpleBlock(I, E, Limit)
+   : 0;
 }
 
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -420,6 +420,7 @@
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
 IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
+IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
@@ -500,9 +501,9 @@
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {false, false, false, false, false, false, 
+false, false, false, false, false, false, 
+true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   

r313270 - [lit] Force site configs to be run before source-tree configs

2017-09-14 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Sep 14 09:47:58 2017
New Revision: 313270

URL: http://llvm.org/viewvc/llvm-project?rev=313270=rev
Log:
[lit] Force site configs to be run before source-tree configs

This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=` parameters.  Instead, you need to run
llvm-lit.py.

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

Modified:
cfe/trunk/test/Unit/lit.cfg
cfe/trunk/test/lit.cfg

Modified: cfe/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Unit/lit.cfg?rev=313270=313269=313270=diff
==
--- cfe/trunk/test/Unit/lit.cfg (original)
+++ cfe/trunk/test/Unit/lit.cfg Thu Sep 14 09:47:58 2017
@@ -17,14 +17,11 @@ config.suffixes = []
 
 # test_source_root: The root path where tests are located.
 # test_exec_root: The root path where tests should be run.
-clang_obj_root = getattr(config, 'clang_obj_root', None)
-if clang_obj_root is not None:
-config.test_exec_root = os.path.join(clang_obj_root, 'unittests')
-config.test_source_root = config.test_exec_root
+config.test_exec_root = os.path.join(config.clang_obj_root, 'unittests')
+config.test_source_root = config.test_exec_root
 
 # testFormat: The test format to use to interpret tests.
-llvm_build_mode = getattr(config, 'llvm_build_mode', "Debug")
-config.test_format = lit.formats.GoogleTest(llvm_build_mode, 'Tests')
+config.test_format = lit.formats.GoogleTest(config.llvm_build_mode, 'Tests')
 
 # Propagate the temp directory. Windows requires this because it uses \Windows\
 # if none of these are present.
@@ -38,55 +35,6 @@ for symbolizer in ['ASAN_SYMBOLIZER_PATH
 if symbolizer in os.environ:
 config.environment[symbolizer] = os.environ[symbolizer]
 
-###
-
-# Check that the object root is known.
-if config.test_exec_root is None:
-# Otherwise, we haven't loaded the site specific configuration (the user is
-# probably trying to run on a test file directly, and either the site
-# configuration hasn't been created by the build system, or we are in an
-# out-of-tree build situation).
-
-# Check for 'clang_unit_site_config' user parameter, and use that if 
available.
-site_cfg = lit_config.params.get('clang_unit_site_config', None)
-if site_cfg and os.path.exists(site_cfg):
-lit_config.load_config(config, site_cfg)
-raise SystemExit
-
-# Try to detect the situation where we are using an out-of-tree build by
-# looking for 'llvm-config'.
-#
-# FIXME: I debated (i.e., wrote and threw away) adding logic to
-# automagically generate the lit.site.cfg if we are in some kind of fresh
-# build situation. This means knowing how to invoke the build system
-# though, and I decided it was too much magic.
-
-llvm_config = lit.util.which('llvm-config', config.environment['PATH'])
-if not llvm_config:
-lit_config.fatal('No site specific configuration available!')
-
-# Get the source and object roots.
-llvm_src_root = 

[clang-tools-extra] r313270 - [lit] Force site configs to be run before source-tree configs

2017-09-14 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Sep 14 09:47:58 2017
New Revision: 313270

URL: http://llvm.org/viewvc/llvm-project?rev=313270=rev
Log:
[lit] Force site configs to be run before source-tree configs

This patch simplifies LLVM's lit infrastructure by enforcing an ordering
that a site config is always run before a source-tree config.

A significant amount of the complexity from lit config files arises from
the fact that inside of a source-tree config file, we don't yet know if
the site config has been run.  However it is *always* required to run
a site config first, because it passes various variables down through
CMake that the main config depends on.  As a result, every config
file has to do a bunch of magic to try to reverse-engineer the location
of the site config file if they detect (heuristically) that the site
config file has not yet been run.

This patch solves the problem by emitting a mapping from source tree
config file to binary tree site config file in llvm-lit.py. Then, during
discovery when we find a config file, we check to see if we have a
target mapping for it, and if so we use that instead.

This mechanism is generic enough that it does not affect external users
of lit. They will just not have a config mapping defined, and everything
will work as normal.

On the other hand, for us it allows us to make many simplifications:

* We are guaranteed that a site config will be executed first
* Inside of a main config, we no longer have to assume that attributes
  might not be present and use getattr everywhere.
* We no longer have to pass parameters such as --param llvm_site_config=
  on the command line.
* It is future-proof, meaning you don't have to edit llvm-lit.in to add
  support for new projects.
* All of the duplicated logic of trying various fallback mechanisms of
  finding a site config from the main config are now gone.

One potentially noteworthy thing that was required to implement this
change is that whereas the ninja check targets previously used the first
method to spawn lit, they now use the second. In particular, you can no
longer run lit.py against the source tree while specifying the various
`foo_site_config=` parameters.  Instead, you need to run
llvm-lit.py.

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

Modified:
clang-tools-extra/trunk/test/Unit/lit.cfg
clang-tools-extra/trunk/test/lit.cfg

Modified: clang-tools-extra/trunk/test/Unit/lit.cfg
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/Unit/lit.cfg?rev=313270=313269=313270=diff
==
--- clang-tools-extra/trunk/test/Unit/lit.cfg (original)
+++ clang-tools-extra/trunk/test/Unit/lit.cfg Thu Sep 14 09:47:58 2017
@@ -9,10 +9,9 @@ config.suffixes = [] # Seems not to matt
 
 # Test Source and Exec root dirs both point to the same directory where google
 # test binaries are built.
-extra_tools_obj_dir = getattr(config, 'extra_tools_obj_dir', None)
-if extra_tools_obj_dir is not None:
-  config.test_source_root = extra_tools_obj_dir
-  config.test_exec_root = config.test_source_root
+
+config.test_source_root = config.extra_tools_obj_dir
+config.test_exec_root = config.test_source_root
 
 # All GoogleTests are named to have 'Tests' as their suffix. The '.' option is
 # a special value for GoogleTest indicating that it should look through the
@@ -20,18 +19,6 @@ if extra_tools_obj_dir is not None:
 # ;-separated list of subdirectories).
 config.test_format = lit.formats.GoogleTest('.', 'Tests')
 
-# If the site-specific configuration wasn't loaded (e.g. the build system 
failed
-# to create it or the user is running a test file directly) try to come up with
-# sane config options.
-if config.test_exec_root is None:
-  # Look for a --param=extra_tools_unit_site_config option.
-  site_cfg = lit_config.params.get('extra_tools_unit_site_config', None)
-  if site_cfg and os.path.exists(site_cfg):
-  lit_config.load_config(config, site_cfg)
-  raise SystemExit
-
-  # FIXME: Support out-of-tree builds? See clang/test/Unit/lit.cfg if we care.
-
 shlibpath_var = ''
 if platform.system() == 'Linux':
 shlibpath_var = 'LD_LIBRARY_PATH'
@@ -41,17 +28,11 @@ elif platform.system() == 'Windows':
 shlibpath_var = 'PATH'
 
 # Point the dynamic loader at dynamic libraries in 'lib'.
-shlibdir = getattr(config, 'shlibdir', None)
-if not shlibdir:
-lit_config.fatal('No shlibdir set!')
-llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
-if not llvm_libs_dir:
-lit_config.fatal('No LLVM libs dir set!')
-shlibpath = os.path.pathsep.join((shlibdir, llvm_libs_dir,
+shlibpath = os.path.pathsep.join((config.shlibdir, config.llvm_libs_dir,
  config.environment.get(shlibpath_var,'')))
 
 # Win32 seeks DLLs along %PATH%.
 if sys.platform in ['win32', 'cygwin'] and os.path.isdir(shlibdir):
-shlibpath = os.path.pathsep.join((shlibdir, shlibpath))
+shlibpath = 

[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: include/clang/Lex/Lexer.h:52
+  /// a BOM is present at the start of the file.
+  unsigned StartOffset;
+  /// \brief Size of the preamble in bytes.

cameron314 wrote:
> ilya-biryukov wrote:
> > We could simplify it further by removing `StartOffset`, leaving only `Size`.
> > If you look at the code, it always uses `StartOffset + Size` now, which is 
> > effectively size with BOM.
> > What do you think?
> Yeah, I thought of that, but it's still nice to have the two separated.
> 
> ASTUnit.cpp, for example, checks if `Size != 0` to determine if there's a 
> preamble (without considering the offset). This isn't in the diff because it 
> was already like that.
Could we simply return `Size = 0` from `ComputePreambleBounds` if we simply 
skipped BOM and the preamble itself is empty?
My concern is that currently it's very easy to forget adding `StartOffset` and 
simply use `Size` when writing code that uses `PreambleBounds`. If we only have 
`Size`, probability of mistakes is much lower.


https://reviews.llvm.org/D37491



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


[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-14 Thread Cameron via Phabricator via cfe-commits
cameron314 added inline comments.



Comment at: include/clang/Lex/Lexer.h:52
+  /// a BOM is present at the start of the file.
+  unsigned StartOffset;
+  /// \brief Size of the preamble in bytes.

ilya-biryukov wrote:
> We could simplify it further by removing `StartOffset`, leaving only `Size`.
> If you look at the code, it always uses `StartOffset + Size` now, which is 
> effectively size with BOM.
> What do you think?
Yeah, I thought of that, but it's still nice to have the two separated.

ASTUnit.cpp, for example, checks if `Size != 0` to determine if there's a 
preamble (without considering the offset). This isn't in the diff because it 
was already like that.


https://reviews.llvm.org/D37491



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


r313266 - Fix Refactor/tool-test-support.c test on Windows by avoiding

2017-09-14 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Thu Sep 14 08:10:39 2017
New Revision: 313266

URL: http://llvm.org/viewvc/llvm-project?rev=313266=rev
Log:
Fix Refactor/tool-test-support.c test on Windows by avoiding
the STDERR redirect

Modified:
cfe/trunk/test/Refactor/tool-test-support.c

Modified: cfe/trunk/test/Refactor/tool-test-support.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Refactor/tool-test-support.c?rev=313266=313265=313266=diff
==
--- cfe/trunk/test/Refactor/tool-test-support.c (original)
+++ cfe/trunk/test/Refactor/tool-test-support.c Thu Sep 14 08:10:39 2017
@@ -1,4 +1,4 @@
-// RUN: clang-refactor local-rename -selection=test:%s -v %s -- 2>&1 | 
FileCheck %s
+// RUN: clang-refactor local-rename -selection=test:%s -v %s -- | FileCheck %s
 
 /*range=*/int test;
 
@@ -11,12 +11,12 @@
 /*range named =+0*/int test5;
 
 // CHECK: Test selection group '':
-// CHECK-NEXT:   95-95
-// CHECK-NEXT:   148-148
-// CHECK-NEXT:   187-187
+// CHECK-NEXT:   90-90
+// CHECK-NEXT:   143-143
+// CHECK-NEXT:   182-182
 // CHECK-NEXT: Test selection group 'named':
-// CHECK-NEXT:   122-122
-// CHECK-NEXT:   208-208
+// CHECK-NEXT:   117-117
+// CHECK-NEXT:   203-203
 
 // The following invocations are in the default group:
 


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


[PATCH] D37822: [OpenCL] Clean up and add missing fields for block struct

2017-09-14 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 115222.
yaxunl added a comment.

Fix bug about calling blocks.


https://reviews.llvm.org/D37822

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGOpenCLRuntime.cpp
  lib/CodeGen/CGOpenCLRuntime.h
  test/CodeGen/blocks-opencl.cl
  test/CodeGenOpenCL/blocks.cl
  test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Index: test/CodeGenOpenCL/cl20-device-side-enqueue.cl
===
--- test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -7,7 +7,7 @@
 typedef struct {int a;} ndrange_t;
 
 // N.B. The check here only exists to set BL_GLOBAL
-// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* [[BL_GLOBAL:@__block_literal_global(\.[0-9]+)?]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
+// COMMON: @block_G =  addrspace(1) constant void (i8 addrspace(3)*) addrspace(4)* addrspacecast (void (i8 addrspace(3)*) addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* [[BL_GLOBAL:@__block_literal_global(\.[0-9]+)?]] to void (i8 addrspace(3)*) addrspace(1)*) to void (i8 addrspace(3)*) addrspace(4)*)
 const bl_t block_G = (bl_t) ^ (local void *a) {};
 
 kernel void device_side_enqueue(global int *a, global int *b, int i) {
@@ -27,9 +27,10 @@
   // COMMON: [[NDR:%[a-z0-9]+]] = alloca %struct.ndrange_t, align 4
   // COMMON: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t{{.*}}*, %opencl.queue_t{{.*}}** %default_queue
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
-  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(2)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block to void ()*
+  // B32: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32, i32 addrspace(1)* }>* %block to void ()*
+  // B64: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32 addrspace(1)*, i32 addrspace(1)*, i32 }>* %block to void ()*
   // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)*
-  // COMMON: call i32 @__enqueue_kernel_basic(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* [[BL_I8]])
+  // COMMON: call i32 @__enqueue_kernel_basic(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* byval [[NDR]]{{([0-9]+)?}}, i8 addrspace(4)* [[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange,
  ^(void) {
a[i] = b[i];
@@ -39,7 +40,7 @@
   // COMMON: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // COMMON: [[WAIT_EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %event_wait_list to %opencl.clk_event_t{{.*}}* addrspace(4)*
   // COMMON: [[EVNT:%[0-9]+]] = addrspacecast %opencl.clk_event_t{{.*}}** %clk_event to %opencl.clk_event_t{{.*}}* addrspace(4)*
-  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, %struct.__block_descriptor addrspace(2)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to void ()*
+  // COMMON: [[BL:%[0-9]+]] = bitcast <{ i32, i32, i8 addrspace(4)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to void ()*
   // COMMON: [[BL_I8:%[0-9]+]] = addrspacecast void ()* [[BL]] to i8 addrspace(4)*
   // COMMON: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]],  %struct.ndrange_t* {{.*}}, i32 2, %opencl.clk_event_t{{.*}}* addrspace(4)* [[WAIT_EVNT]], %opencl.clk_event_t{{.*}}* addrspace(4)* [[EVNT]], i8 addrspace(4)* [[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange, 2, _wait_list, _event,
@@ -52,11 +53,11 @@
   // B32: %[[TMP:.*]] = alloca [1 x i32]
   // B32: %[[TMP1:.*]] = getelementptr [1 x i32], [1 x i32]* %[[TMP]], i32 0, i32 0
   // B32: store i32 256, i32* %[[TMP1]], align 4
-  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i8**, i32, i32, i8*, %struct.__block_descriptor addrspace(2)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %[[TMP1]])
+  // B32: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{([0-9]+)?}}, i8 addrspace(4)* addrspacecast (i8 addrspace(1)* bitcast ({ i32, i32, i8 addrspace(4)* } addrspace(1)* @__block_literal_global{{(.[0-9]+)?}} to i8 addrspace(1)*) to i8 addrspace(4)*), i32 1, i32* %[[TMP1]])
   // B64: %[[TMP:.*]] = alloca [1 x i64]
   // B64: %[[TMP1:.*]] = getelementptr [1 x i64], [1 x i64]* %[[TMP]], i32 0, i32 0
   // B64: store i64 256, i64* %[[TMP1]], align 8
-  // B64: call i32 @__enqueue_kernel_vaargs(%opencl.queue_t{{.*}}* [[DEF_Q]], i32 [[FLAGS]], %struct.ndrange_t* [[NDR]]{{(.[0-9]+)?}}, i8 

[PATCH] D37491: [Preamble] Fixed preamble breaking with BOM presence (and particularly, fluctuating BOM presence)

2017-09-14 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

See my comments about removing `StartOffset` field, but other than that looks 
good.




Comment at: include/clang/Lex/Lexer.h:52
+  /// a BOM is present at the start of the file.
+  unsigned StartOffset;
+  /// \brief Size of the preamble in bytes.

We could simplify it further by removing `StartOffset`, leaving only `Size`.
If you look at the code, it always uses `StartOffset + Size` now, which is 
effectively size with BOM.
What do you think?



Comment at: lib/Frontend/PrecompiledPreamble.cpp:227
+  auto PreambleStart = MainFileBuffer->getBufferStart() + Bounds.StartOffset;
+  std::vector PreambleBytes(PreambleStart,
+  PreambleStart + Bounds.Size);

Maybe store BOM bytes in `PreambleBytes` too? Would that allow to get rid of 
`StartOffset` field (see other comment)?


https://reviews.llvm.org/D37491



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


  1   2   >