Re: [PATCH] D24567: [clang-rename] Merge rename-{at|all} & optimise.

2016-09-15 Thread Miklos Vajna via cfe-commits
vmiklos added a comment.

As mentioned earlier, I have no problem with merging rename-at and rename-all.


https://reviews.llvm.org/D24567



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


[PATCH] D24601: XFAIL Driver/darwin-stdlib.cpp if CLANG_DEFAULT_CXX_STDLIB is set

2016-09-15 Thread Jonas Hahnfeld via cfe-commits
Hahnfeld created this revision.
Hahnfeld added a reviewer: t.p.northover.
Hahnfeld added a subscriber: cfe-commits.

Until someone rewrites the stdlib logic for Darwin so that we don't need
to pass down the -stdlib argument to cc1.

https://reviews.llvm.org/D24601

Files:
  test/Driver/darwin-stdlib.cpp
  test/lit.cfg
  test/lit.site.cfg.in

Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -16,6 +16,7 @@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = "@HAVE_LIBZ@"
 config.clang_arcmt = @ENABLE_CLANG_ARCMT@
+config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
 config.clang_staticanalyzer = @ENABLE_CLANG_STATIC_ANALYZER@
 config.clang_examples = @ENABLE_CLANG_EXAMPLES@
 config.enable_shared = @ENABLE_SHARED@
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -343,6 +343,9 @@
 
 # Set available features we allow tests to conditionalize on.
 #
+if config.clang_default_cxx_stdlib != '':
+config.available_features.add('default-cxx-stdlib-set')
+
 # Enabled/disabled features
 if config.clang_staticanalyzer != 0:
 config.available_features.add("staticanalyzer")
Index: test/Driver/darwin-stdlib.cpp
===
--- test/Driver/darwin-stdlib.cpp
+++ test/Driver/darwin-stdlib.cpp
@@ -1,3 +1,7 @@
+// This test will fail if CLANG_DEFAULT_CXX_STDLIB is set to anything different
+// than the platform default.
+// XFAIL: default-cxx-stdlib-set
+
 // RUN: %clang -target x86_64-apple-darwin -arch arm64 
-miphoneos-version-min=7.0 %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-LIBCXX
 // RUN: %clang -target x86_64-apple-darwin -mmacosx-version-min=10.8 %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LIBSTDCXX
 // RUN: %clang -target x86_64-apple-darwin -mmacosx-version-min=10.9 %s -### 
2>&1 | FileCheck %s --check-prefix=CHECK-LIBCXX


Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -16,6 +16,7 @@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
 config.have_zlib = "@HAVE_LIBZ@"
 config.clang_arcmt = @ENABLE_CLANG_ARCMT@
+config.clang_default_cxx_stdlib = "@CLANG_DEFAULT_CXX_STDLIB@"
 config.clang_staticanalyzer = @ENABLE_CLANG_STATIC_ANALYZER@
 config.clang_examples = @ENABLE_CLANG_EXAMPLES@
 config.enable_shared = @ENABLE_SHARED@
Index: test/lit.cfg
===
--- test/lit.cfg
+++ test/lit.cfg
@@ -343,6 +343,9 @@
 
 # Set available features we allow tests to conditionalize on.
 #
+if config.clang_default_cxx_stdlib != '':
+config.available_features.add('default-cxx-stdlib-set')
+
 # Enabled/disabled features
 if config.clang_staticanalyzer != 0:
 config.available_features.add("staticanalyzer")
Index: test/Driver/darwin-stdlib.cpp
===
--- test/Driver/darwin-stdlib.cpp
+++ test/Driver/darwin-stdlib.cpp
@@ -1,3 +1,7 @@
+// This test will fail if CLANG_DEFAULT_CXX_STDLIB is set to anything different
+// than the platform default.
+// XFAIL: default-cxx-stdlib-set
+
 // RUN: %clang -target x86_64-apple-darwin -arch arm64 -miphoneos-version-min=7.0 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LIBCXX
 // RUN: %clang -target x86_64-apple-darwin -mmacosx-version-min=10.8 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LIBSTDCXX
 // RUN: %clang -target x86_64-apple-darwin -mmacosx-version-min=10.9 %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-LIBCXX
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24600: [libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI compatibility

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

I should mention that before this patch a GCC compiled dylib had 62 additional 
symbols and was missing 105 symbols. Now there are only 20 missing symbols and 
62 additional.


https://reviews.llvm.org/D24600



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


Re: [PATCH] D24572: [clang-tidy] Clean up code after applying replacements.

2016-09-15 Thread Eric Liu via cfe-commits
ioeric requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-tidy/ClangTidy.cpp:25
@@ -24,2 +24,3 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Format/Format.h"
 #include "clang/Frontend/ASTConsumers.h"

Also add dependency on clangFormat?


Comment at: clang-tidy/ClangTidy.cpp:159
@@ +158,3 @@
+  R.getReplacementText());
+  Replacements = Replacements.merge(tooling::Replacements(R));
+} else {

Do you need to update `CanBeApplied` and `AppliedFixes` in this branch as well?


Comment at: clang-tidy/ClangTidy.cpp:202
@@ +201,3 @@
+   << Buffer.getError().message() << "\n";
+  // FIXME: Maybe don't apply anything.
+  continue;

This `FIXME` is not very clear, i.e. does it mean don't apply anything for all 
files? Or just a single file?


Comment at: clang-tidy/ClangTidy.cpp:206
@@ +205,3 @@
+StringRef Code = Buffer.get()->getBuffer();
+format::FormatStyle Style = format::getLLVMStyle();
+llvm::Expected CleanReplacements =

Add a `FIXME` here. 

And I think this might be a better workaround for now:
format::FormatStyle InsertStyle = format::getStyle("file", File, "LLVM");


https://reviews.llvm.org/D24572



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


Re: [PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

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

This approach looks great. I don't think we need to split things up into 
separate files. This is exactly how `test_macros.h` should be used.

Feel free to convert as many tests as possible. I've been doing the same to 
anything I work on.



Comment at: test/std/re/re.alg/re.alg.search/grep.pass.cpp:25
@@ -25,2 +24,3 @@
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)

I prefer putting the `#if` on the inside of the function so you don't also have 
to `#ifdef` it out in `main()` below. 



https://reviews.llvm.org/D24562



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


r281596 - [ARM] ARM-specific attributes should be accepted for big-endian

2016-09-15 Thread Oliver Stannard via cfe-commits
Author: olista01
Date: Thu Sep 15 03:55:41 2016
New Revision: 281596

URL: http://llvm.org/viewvc/llvm-project?rev=281596&view=rev
Log:
[ARM] ARM-specific attributes should be accepted for big-endian

The ARM-specific C attributes (currently just interrupt) need to check
for both the big- and little-endian versions of the triples, so that
they are accepted for both big and little endian targets.

TargetWindows and TargetMicrosoftCXXABI also only use the little-endian
triples, but this is correct as windows is not supported on big-endian
ARM targets (and this is asserted in lib/Basic/Targets.cpp).

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


Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/test/Sema/arm-interrupt-attr.c

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=281596&r1=281595&r2=281596&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Thu Sep 15 03:55:41 2016
@@ -254,7 +254,7 @@ class TargetArch arches> {
   list OSes;
   list CXXABIs;
 }
-def TargetARM : TargetArch<["arm", "thumb"]>;
+def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
 def TargetMips : TargetArch<["mips", "mipsel"]>;
 def TargetMSP430 : TargetArch<["msp430"]>;
 def TargetX86 : TargetArch<["x86"]>;

Modified: cfe/trunk/test/Sema/arm-interrupt-attr.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/arm-interrupt-attr.c?rev=281596&r1=281595&r2=281596&view=diff
==
--- cfe/trunk/test/Sema/arm-interrupt-attr.c (original)
+++ cfe/trunk/test/Sema/arm-interrupt-attr.c Thu Sep 15 03:55:41 2016
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumb-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple armeb-none-eabi -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -verify -fsyntax-only
 
 __attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' 
attribute requires a string}}
 __attribute__((interrupt("irq"))) void foo1() {} // expected-warning 
{{'interrupt' attribute argument not supported: irq}}


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


Re: [PATCH] D24245: [ARM] ARM-specific attributes should be accepted for big-endian

2016-09-15 Thread Oliver Stannard via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281596: [ARM] ARM-specific attributes should be accepted for 
big-endian (authored by olista01).

Changed prior to commit:
  https://reviews.llvm.org/D24245?vs=70364&id=71485#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24245

Files:
  cfe/trunk/include/clang/Basic/Attr.td
  cfe/trunk/test/Sema/arm-interrupt-attr.c

Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -254,7 +254,7 @@
   list OSes;
   list CXXABIs;
 }
-def TargetARM : TargetArch<["arm", "thumb"]>;
+def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
 def TargetMips : TargetArch<["mips", "mipsel"]>;
 def TargetMSP430 : TargetArch<["msp430"]>;
 def TargetX86 : TargetArch<["x86"]>;
Index: cfe/trunk/test/Sema/arm-interrupt-attr.c
===
--- cfe/trunk/test/Sema/arm-interrupt-attr.c
+++ cfe/trunk/test/Sema/arm-interrupt-attr.c
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumb-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple armeb-none-eabi -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -verify -fsyntax-only
 
 __attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' 
attribute requires a string}}
 __attribute__((interrupt("irq"))) void foo1() {} // expected-warning 
{{'interrupt' attribute argument not supported: irq}}


Index: cfe/trunk/include/clang/Basic/Attr.td
===
--- cfe/trunk/include/clang/Basic/Attr.td
+++ cfe/trunk/include/clang/Basic/Attr.td
@@ -254,7 +254,7 @@
   list OSes;
   list CXXABIs;
 }
-def TargetARM : TargetArch<["arm", "thumb"]>;
+def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
 def TargetMips : TargetArch<["mips", "mipsel"]>;
 def TargetMSP430 : TargetArch<["msp430"]>;
 def TargetX86 : TargetArch<["x86"]>;
Index: cfe/trunk/test/Sema/arm-interrupt-attr.c
===
--- cfe/trunk/test/Sema/arm-interrupt-attr.c
+++ cfe/trunk/test/Sema/arm-interrupt-attr.c
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 %s -triple arm-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumb-apple-darwin -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple armeb-none-eabi -verify -fsyntax-only
+// RUN: %clang_cc1 %s -triple thumbeb-none-eabi -verify -fsyntax-only
 
 __attribute__((interrupt(IRQ))) void foo() {} // expected-error {{'interrupt' attribute requires a string}}
 __attribute__((interrupt("irq"))) void foo1() {} // expected-warning {{'interrupt' attribute argument not supported: irq}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24602: [libc++] Fix and document visibility attributes for Clang, GCC and Windows.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added a reviewer: mclow.lists.
EricWF added a subscriber: cfe-commits.
Herald added subscribers: mgorny, beanz.

This patch fixes a number of problems with the visibility macros across GCC (on 
Unix) and Windows (DLL import/export semantics). All of the visibility macros 
are now documented under `DesignDocs/VisibilityMacros.rst`. Now I'll no longer 
forget the subtleties of each!

This patch adds two new visibility macros:

* `_LIBCPP_ENUM_VIS` for controlling the typeinfo of enum types. Only Clang 
supports this.
* `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS` for redefining visibility on explicit 
instantiation declarations. Clang and Windows require this.

After applying this patch GCC only emits one -Wattribute warning opposed to 30+.


https://reviews.llvm.org/D24602

Files:
  CMakeLists.txt
  docs/DesignDocs/VisibilityMacros.rst
  docs/index.rst
  include/__config
  include/__locale
  include/__string
  include/experimental/filesystem
  include/istream
  include/locale
  include/ostream
  include/streambuf
  include/string
  include/vector

Index: include/vector
===
--- include/vector
+++ include/vector
@@ -312,7 +312,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
Index: include/string
===
--- include/string
+++ include/string
@@ -574,7 +574,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
@@ -1024,7 +1024,7 @@
 _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
-_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
@@ -3910,8 +3910,8 @@
 }
 #endif
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
 _LIBCPP_EXTERN_TEMPLATE(string operator+, allocator >(char const*, string const&))
 
 _LIBCPP_END_NAMESPACE_STD
Index: include/streambuf
===
--- include/streambuf
+++ include/streambuf
@@ -574,11 +574,11 @@
 return traits_type::eof();
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -1113,8 +1113,8 @@
  use_facet >(__os.getloc()).widen('1'));
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/locale
===
--- include/locale
+++ include/locale
@@ -523,8 +523,8 @@
 return 0;
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
 
 template  >
 class _LIBCPP_TYPE_VIS_ONLY num_get
@@ -1042,8 +1042,8 @@
 return __b;
 }
 
-_LIBCP

Re: [PATCH] D18462: Fix for clang_Cursor_getSpellingNameRange()

2016-09-15 Thread Kevin Funk via cfe-commits
kfunk added a comment.

@other LLVM devs: Please review so we can finally ship this?



Comment at: tools/libclang/CIndex.cpp:4311
@@ -4311,1 +4310,3 @@
+  C.kind == CXCursor_ConversionFunction ||
+  C.kind == CXCursor_FunctionDecl) {
 if (pieceIndex > 0)

skalinichev wrote:
> What about function templates?
> 
> E.g.: template  double operator "" _x();
Still broken for function template. The fix isn't as easy as adding another 
check for `C.kind == CXCursor=FunctionTemplate`, though.

We should fix this in another patch.


https://reviews.llvm.org/D18462



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


Re: [PATCH] D24602: [libc++] Fix and document visibility attributes for Clang, GCC and Windows.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 71486.
EricWF added a comment.

Fix obvious errors in docs.


https://reviews.llvm.org/D24602

Files:
  CMakeLists.txt
  docs/DesignDocs/VisibilityMacros.rst
  docs/index.rst
  include/__config
  include/__locale
  include/__string
  include/experimental/filesystem
  include/istream
  include/locale
  include/ostream
  include/streambuf
  include/string
  include/vector

Index: include/vector
===
--- include/vector
+++ include/vector
@@ -312,7 +312,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
Index: include/string
===
--- include/string
+++ include/string
@@ -574,7 +574,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
@@ -1024,7 +1024,7 @@
 _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
-_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
@@ -3910,8 +3910,8 @@
 }
 #endif
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
 _LIBCPP_EXTERN_TEMPLATE(string operator+, allocator >(char const*, string const&))
 
 _LIBCPP_END_NAMESPACE_STD
Index: include/streambuf
===
--- include/streambuf
+++ include/streambuf
@@ -574,11 +574,11 @@
 return traits_type::eof();
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -1113,8 +1113,8 @@
  use_facet >(__os.getloc()).widen('1'));
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/locale
===
--- include/locale
+++ include/locale
@@ -523,8 +523,8 @@
 return 0;
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
 
 template  >
 class _LIBCPP_TYPE_VIS_ONLY num_get
@@ -1042,8 +1042,8 @@
 return __b;
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get)
-_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get)
 
 struct _LIBCPP_TYPE_VIS __num_put_base
 {
@@ -1192,8 +1192,8 @@
 __op = __ob + (__np - __nb);
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put)
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put)
 
 template  >
 class _LIBCPP_TYPE_V

Re: [PATCH] D24602: [libc++] Fix and document visibility attributes for Clang, GCC and Windows.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF added inline comments.


Comment at: include/__config:605
@@ +604,3 @@
+#  if __has_attribute(__type_visibility__)
+#define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ 
((__visibility__("default")))
+#  else

Checking `__type_visibility__` and using `__visibility__`  looks weird but is 
intended as it's meant to override `__type_visibility__`.


Comment at: include/__string:704
@@ -703,2 +703,3 @@
 template
-size_t _LIBCPP_INLINE_VISIBILITY __do_string_hash(_Ptr __p, _Ptr __e)
+inline _LIBCPP_INLINE_VISIBILITY
+size_t __do_string_hash(_Ptr __p, _Ptr __e)

This suppresses the GCC diagnostic `warning: always_inline function might not 
be inlinable [-Wattributes]` .


https://reviews.llvm.org/D24602



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


Re: [PATCH] D24562: [libcxx] Recover no-exceptions XFAILs

2016-09-15 Thread Asiri Rathnayake via cfe-commits
rmaprath added inline comments.


Comment at: test/std/re/re.alg/re.alg.search/grep.pass.cpp:25
@@ -25,2 +24,3 @@
 
+#ifndef TEST_HAS_NO_EXCEPTIONS
 extern "C" void LLVMFuzzerTestOneInput(const char *data)

EricWF wrote:
> I prefer putting the `#if` on the inside of the function so you don't also 
> have to `#ifdef` it out in `main()` below. 
> 
Thanks. That's much better.

I'll convert as much tests as possible and submit and overall patch for a final 
review.


https://reviews.llvm.org/D24562



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


Re: [PATCH] D21070: Pass the ABI in the triple when appropriate (currently for MIPS) for 'clang -cc1' and 'clang -cc1as'

2016-09-15 Thread Simon Dardis via cfe-commits
sdardis added a comment.

Ping.


https://reviews.llvm.org/D21070



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


[libcxx] r281603 - [libcxx] Allow sanitizing libcxx with ASan+UBSan simultaneously

2016-09-15 Thread Kuba Brecka via cfe-commits
Author: kuba.brecka
Date: Thu Sep 15 06:04:53 2016
New Revision: 281603

URL: http://llvm.org/viewvc/llvm-project?rev=281603&view=rev
Log:
[libcxx] Allow sanitizing libcxx with ASan+UBSan simultaneously

Allow building with LLVM_USE_SANITIZER=“Address;Undefined” (and 
“Undefined;Address”).

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


Modified:
libcxx/trunk/lib/CMakeLists.txt
libcxx/trunk/test/libcxx/test/config.py

Modified: libcxx/trunk/lib/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/lib/CMakeLists.txt?rev=281603&r1=281602&r2=281603&view=diff
==
--- libcxx/trunk/lib/CMakeLists.txt (original)
+++ libcxx/trunk/lib/CMakeLists.txt Thu Sep 15 06:04:53 2016
@@ -38,7 +38,9 @@ add_library_flags("${LIBCXX_CXX_ABI_LIBR
 add_library_flags_if(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "-Wl,-Bdynamic" 
"-Wl,--no-whole-archive")
 
 if (APPLE AND LLVM_USE_SANITIZER)
-  if ("${LLVM_USE_SANITIZER}" STREQUAL "Address")
+  if (("${LLVM_USE_SANITIZER}" STREQUAL "Address") OR
+  ("${LLVM_USE_SANITIZER}" STREQUAL "Address;Undefined") OR
+  ("${LLVM_USE_SANITIZER}" STREQUAL "Undefined;Address"))
 set(LIBFILE "libclang_rt.asan_osx_dynamic.dylib")
   elseif("${LLVM_USE_SANITIZER}" STREQUAL "Undefined")
 set(LIBFILE "libclang_rt.ubsan_osx_dynamic.dylib")

Modified: libcxx/trunk/test/libcxx/test/config.py
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/test/config.py?rev=281603&r1=281602&r2=281603&view=diff
==
--- libcxx/trunk/test/libcxx/test/config.py (original)
+++ libcxx/trunk/test/libcxx/test/config.py Thu Sep 15 06:04:53 2016
@@ -610,9 +610,17 @@ class Configuration(object):
 os.pathsep + symbolizer_search_paths)
 llvm_symbolizer = lit.util.which('llvm-symbolizer',
  symbolizer_search_paths)
+
+def add_ubsan():
+self.cxx.flags += ['-fsanitize=undefined',
+   
'-fno-sanitize=vptr,function,float-divide-by-zero',
+   '-fno-sanitize-recover=all']
+self.env['UBSAN_OPTIONS'] = 'print_stacktrace=1'
+self.config.available_features.add('ubsan')
+
 # Setup the sanitizer compile flags
 self.cxx.flags += ['-g', '-fno-omit-frame-pointer']
-if san == 'Address':
+if san == 'Address' or san == 'Address;Undefined' or san == 
'Undefined;Address':
 self.cxx.flags += ['-fsanitize=address']
 if llvm_symbolizer is not None:
 self.env['ASAN_SYMBOLIZER_PATH'] = llvm_symbolizer
@@ -622,6 +630,8 @@ class Configuration(object):
 self.config.available_features.add('asan')
 self.config.available_features.add('sanitizer-new-delete')
 self.cxx.compile_flags += ['-O1']
+if san == 'Address;Undefined' or san == 'Undefined;Address':
+add_ubsan()
 elif san == 'Memory' or san == 'MemoryWithOrigins':
 self.cxx.flags += ['-fsanitize=memory']
 if san == 'MemoryWithOrigins':
@@ -633,12 +643,8 @@ class Configuration(object):
 self.config.available_features.add('sanitizer-new-delete')
 self.cxx.compile_flags += ['-O1']
 elif san == 'Undefined':
-self.cxx.flags += ['-fsanitize=undefined',
-   
'-fno-sanitize=vptr,function,float-divide-by-zero',
-   '-fno-sanitize-recover=all']
+add_ubsan()
 self.cxx.compile_flags += ['-O2']
-self.env['UBSAN_OPTIONS'] = 'print_stacktrace=1'
-self.config.available_features.add('ubsan')
 elif san == 'Thread':
 self.cxx.flags += ['-fsanitize=thread']
 self.config.available_features.add('tsan')


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


Re: [PATCH] D24380: [migrate-tool] Framework for a codebase-dependent migration tool.

2016-09-15 Thread Eric Liu via cfe-commits
ioeric added a comment.

Ping


https://reviews.llvm.org/D24380



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


Re: [PATCH] D24606: Recommit r281457 "Supports adding insertion around non-insertion replacements" and fix a bug in getAffectedRanges.

2016-09-15 Thread Eric Liu via cfe-commits
ioeric updated this revision to Diff 71495.
ioeric added a comment.

- Update comment in `getAffectedRanges`.


https://reviews.llvm.org/D24606

Files:
  include/clang/Tooling/Core/Replacement.h
  lib/Tooling/Core/Replacement.cpp
  unittests/Tooling/RefactoringTest.cpp

Index: unittests/Tooling/RefactoringTest.cpp
===
--- unittests/Tooling/RefactoringTest.cpp
+++ unittests/Tooling/RefactoringTest.cpp
@@ -115,24 +115,26 @@
   llvm::consumeError(std::move(Err));
 }
 
-TEST_F(ReplacementTest, FailAddOverlappingInsertions) {
+TEST_F(ReplacementTest, AddAdjacentInsertionAndReplacement) {
   Replacements Replaces;
   // Test adding an insertion at the offset of an existing replacement.
   auto Err = Replaces.add(Replacement("x.cc", 10, 3, "replace"));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 0, "insert"));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 
   Replaces.clear();
   // Test overlap with an existing insertion.
   Err = Replaces.add(Replacement("x.cc", 10, 0, "insert"));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 3, "replace"));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 }
 
 TEST_F(ReplacementTest, FailAddRegression) {
@@ -157,14 +159,24 @@
   llvm::consumeError(std::move(Err));
 }
 
-TEST_F(ReplacementTest, FailAddInsertAtOffsetOfReplacement) {
+TEST_F(ReplacementTest, InsertAtOffsetOfReplacement) {
   Replacements Replaces;
   auto Err = Replaces.add(Replacement("x.cc", 10, 2, ""));
   EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
   Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
-  EXPECT_TRUE((bool)Err);
+  EXPECT_TRUE(!Err);
   llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 2, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  EXPECT_EQ(Replaces.size(), 2u);
 }
 
 TEST_F(ReplacementTest, FailAddInsertAtOtherInsert) {
@@ -175,6 +187,38 @@
   Err = Replaces.add(Replacement("x.cc", 10, 0, "b"));
   EXPECT_TRUE((bool)Err);
   llvm::consumeError(std::move(Err));
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE((bool)Err);
+  llvm::consumeError(std::move(Err));
+
+  Replaces.clear();
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 3, ""));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, ""));
+  EXPECT_TRUE((bool)Err);
+  llvm::consumeError(std::move(Err));
+}
+
+TEST_F(ReplacementTest, InsertBetweenAdjacentReplacements) {
+  Replacements Replaces;
+  auto Err = Replaces.add(Replacement("x.cc", 10, 5, "a"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 8, 2, "a"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
+  Err = Replaces.add(Replacement("x.cc", 10, 0, "b"));
+  EXPECT_TRUE(!Err);
+  llvm::consumeError(std::move(Err));
 }
 
 TEST_F(ReplacementTest, CanApplyReplacements) {
@@ -189,6 +233,29 @@
   EXPECT_EQ("line1\nreplaced\nother\nline4", Context.getRewrittenText(ID));
 }
 
+// Verifies that replacement/deletion is applied before insertion at the same
+// offset.
+TEST_F(ReplacementTest, InsertAndDelete) {
+  FileID ID = Context.createInMemoryFile("input.cpp",
+ "line1\nline2\nline3\nline4");
+  Replacements Replaces = toReplacements(
+  {Replacement(Context.Sources, Context.getLocation(ID, 2, 1), 6, ""),
+   Replacement(Context.Sources, Context.getLocation(ID, 2, 1), 0,
+   "other\n")});
+  EXPECT_TRUE(applyAllReplacements(Replaces, Context.Rewrite));
+  EXPECT_EQ("line1\nother\nline3\nline4", Context.getRewrittenText(ID));
+}
+
+TEST_F(ReplacementTest, AdjacentReplacements) {
+  FileID ID = Context.createInMemoryFile("input.cpp",
+ "ab");
+  Replacements Replaces = toReplacements(
+  {Replacement(Context.Sources, Context.getLocation(ID, 1, 1), 1, "x"),
+   Replacement(Context.Sources, Context.getLocation(ID, 1, 2), 1, "y")});
+  EXPECT_TRUE(applyAllReplacements(Replaces, Context.Rewrite));
+  EXPECT_EQ("xy", Context.getRewrittenText(ID));
+}
+
 TEST_F(ReplacementTest, SkipsDuplicateReplacements) {
   FileID ID = Context.createInMemoryFile("input.cpp",
  "line1\

Re: [PATCH] D24572: [clang-tidy] Clean up code after applying replacements.

2016-09-15 Thread Haojian Wu via cfe-commits
hokein added inline comments.


Comment at: clang-tidy/ClangTidy.cpp:206
@@ +205,3 @@
+StringRef Code = Buffer.get()->getBuffer();
+format::FormatStyle Style = format::getLLVMStyle();
+llvm::Expected CleanReplacements =

ioeric wrote:
> Add a `FIXME` here. 
> 
> And I think this might be a better workaround for now:
> format::FormatStyle InsertStyle = format::getStyle("file", File, "LLVM");
A further thought: we might not want to hard-code the code-style here. Add a 
FIXME to make the style customizable?


Comment at: clang-tidy/ClangTidy.cpp:218
@@ -169,1 +217,3 @@
+  }
+  Rewrite.overwriteChangedFiles();
   llvm::errs() << "clang-tidy applied " << AppliedFixes << " of "

Shouldn't we check whether the overwrite operation is successful or not?


https://reviews.llvm.org/D24572



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


Re: [PATCH] D18462: Fix for clang_Cursor_getSpellingNameRange()

2016-09-15 Thread Milian Wolff via cfe-commits
milianw accepted this revision.
milianw added a comment.
This revision is now accepted and ready to land.

agreed, lgtm but someone else must accept this upstream


https://reviews.llvm.org/D18462



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


Re: [PATCH] D24183: A clang tool for changing surrouding namespaces of class/function definitions.

2016-09-15 Thread Eric Liu via cfe-commits
ioeric added a comment.

PIng


https://reviews.llvm.org/D24183



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


[PATCH] D24609: [ARM] Add missing Interlocked intrinsics

2016-09-15 Thread Martin Storsjö via cfe-commits
mstorsjo created this revision.
mstorsjo added a reviewer: compnerd.
mstorsjo added a subscriber: cfe-commits.
Herald added subscribers: samparker, rengolin, aemerson.

On ARM, there are multiple versions of each of the intrinsics, with 
acquire/relaxed/release barrier semantics.

The 64 bit versions that so far were within "ifdef __x86_64__" also are fit for 
arm - I think the reason why they were in ifdefs is that winnt.h have got 
inline versions of them for, within ifdef _M_IX86.

The versions without a width suffix (32 bit) are currently provided as builtins 
instead of as inline functions here. The _acq/_nf/_rel suffixed ones of those 
are provided as inline functions here, since they should only be available on 
certain archs (arm/aarch64).

This is necessary in order to compile C++ code for ARM in MSVC mode.

https://reviews.llvm.org/D24609

Files:
  lib/Headers/intrin.h

Index: lib/Headers/intrin.h
===
--- lib/Headers/intrin.h
+++ lib/Headers/intrin.h
@@ -498,6 +498,23 @@
   long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_SEQ_CST);
   return (_PrevVal >> _BitPos) & 1;
 }
+#if defined(__arm__) || defined(__aarch64__)
+static __inline__ unsigned char __DEFAULT_FN_ATTRS
+_interlockedbittestandset_acq(long volatile *_BitBase, long _BitPos) {
+  long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_ACQUIRE);
+  return (_PrevVal >> _BitPos) & 1;
+}
+static __inline__ unsigned char __DEFAULT_FN_ATTRS
+_interlockedbittestandset_nf(long volatile *_BitBase, long _BitPos) {
+  long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_RELAXED);
+  return (_PrevVal >> _BitPos) & 1;
+}
+static __inline__ unsigned char __DEFAULT_FN_ATTRS
+_interlockedbittestandset_rel(long volatile *_BitBase, long _BitPos) {
+  long _PrevVal = __atomic_fetch_or(_BitBase, 1l << _BitPos, __ATOMIC_RELEASE);
+  return (_PrevVal >> _BitPos) & 1;
+}
+#endif
 #ifdef __x86_64__
 static __inline__ unsigned char __DEFAULT_FN_ATTRS
 _BitScanForward64(unsigned long *_Index, unsigned __int64 _Mask) {
@@ -554,16 +571,70 @@
 _InterlockedExchangeAdd8(char volatile *_Addend, char _Value) {
   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
 }
+#if defined(__arm__) || defined(__aarch64__)
+static __inline__ char __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd8_acq(char volatile *_Addend, char _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
+}
+static __inline__ char __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd8_nf(char volatile *_Addend, char _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
+}
+static __inline__ char __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd8_rel(char volatile *_Addend, char _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
+}
+#endif
 static __inline__ short __DEFAULT_FN_ATTRS
 _InterlockedExchangeAdd16(short volatile *_Addend, short _Value) {
   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
 }
-#ifdef __x86_64__
+#if defined(__arm__) || defined(__aarch64__)
+static __inline__ short __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd16_acq(short volatile *_Addend, short _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
+}
+static __inline__ short __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd16_nf(short volatile *_Addend, short _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
+}
+static __inline__ short __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd16_rel(short volatile *_Addend, short _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE);
+}
+static __inline__ long __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd_acq(long volatile *_Addend, long _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
+}
+static __inline__ long __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd_nf(long volatile *_Addend, long _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
+}
+static __inline__ long __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd_rel(long volatile *_Addend, long _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELEASE);
+}
+#endif
+#if defined(__x86_64__) || defined(__arm__) || defined(__aarch64__)
 static __inline__ __int64 __DEFAULT_FN_ATTRS
 _InterlockedExchangeAdd64(__int64 volatile *_Addend, __int64 _Value) {
   return __atomic_fetch_add(_Addend, _Value, __ATOMIC_SEQ_CST);
 }
 #endif
+#if defined(__arm__) || defined(__aarch64__)
+static __inline__ __int64 __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd64_acq(__int64 volatile *_Addend, __int64 _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_ACQUIRE);
+}
+static __inline__ __int64 __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd64_nf(__int64 volatile *_Addend, __int64 _Value) {
+  return __atomic_fetch_add(_Addend, _Value, __ATOMIC_RELAXED);
+}
+static __inline__ __int64 __DEFAULT_FN_ATTRS
+_InterlockedExchangeAdd64_rel(__int64 volatile *_Addend, __int64 _Va

Re: [PATCH] D24467: Fix an error after D21678

2016-09-15 Thread Vladimir Yakovlev via cfe-commits
vbyakovlcl updated this revision to Diff 71498.

https://reviews.llvm.org/D24467

Files:
  llvm/tools/clang/lib/Sema/SemaExpr.cpp
  llvm/tools/clang/test/CodeGen/vecshift.c
  llvm/tools/clang/test/Sema/vecshift.c

Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp
===
--- llvm/tools/clang/lib/Sema/SemaExpr.cpp
+++ llvm/tools/clang/lib/Sema/SemaExpr.cpp
@@ -8721,7 +8721,8 @@
 static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS,
  SourceLocation Loc, bool IsCompAssign) {
   // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector.
-  if (!LHS.get()->getType()->isVectorType()) {
+  if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) &&
+  !LHS.get()->getType()->isVectorType()) {
 S.Diag(Loc, diag::err_shift_rhs_only_vector)
   << RHS.get()->getType() << LHS.get()->getType()
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
@@ -8737,15 +8738,17 @@
   if (RHS.isInvalid()) return QualType();
 
   QualType LHSType = LHS.get()->getType();
-  const VectorType *LHSVecTy = LHSType->castAs();
-  QualType LHSEleType = LHSVecTy->getElementType();
+  // Note that LHS might be a scalar because the routine calls not only in
+  // OpenCL case.
+  const VectorType *LHSVecTy = LHSType->getAs();
+  QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType;
 
   // Note that RHS might not be a vector.
   QualType RHSType = RHS.get()->getType();
   const VectorType *RHSVecTy = RHSType->getAs();
   QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType;
 
-  // OpenCL v1.1 s6.3.j says that the operands need to be integers.
+  // The operands need to be integers.
   if (!LHSEleType->isIntegerType()) {
 S.Diag(Loc, diag::err_typecheck_expect_int)
   << LHS.get()->getType() << LHS.get()->getSourceRange();
@@ -8758,7 +8761,19 @@
 return QualType();
   }
 
-  if (RHSVecTy) {
+  if (!LHSVecTy) {
+assert(RHSVecTy);
+if (IsCompAssign)
+  return RHSType;
+if (LHSEleType != RHSEleType) {
+  LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast);
+  LHSEleType = RHSEleType;
+}
+QualType VecTy =
+S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements());
+LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat);
+LHSType = VecTy;
+  } else if (RHSVecTy) {
 // OpenCL v1.1 s6.3.j says that for vector types, the operators
 // are applied component-wise. So if RHS is a vector, then ensure
 // that the number of elements is the same as LHS...
Index: llvm/tools/clang/test/CodeGen/vecshift.c
===
--- llvm/tools/clang/test/CodeGen/vecshift.c
+++ llvm/tools/clang/test/CodeGen/vecshift.c
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
+typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
+typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
+typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
+typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
+typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+
+char c;
+short s;
+int i;
+unsigned char uc;
+unsigned short us;
+unsigned int ui;
+vector_char8 vc8;
+vector_short8 vs8;
+vector_int8 vi8;
+vector_uchar8 vuc8;
+vector_ushort8 vus8;
+vector_uint8 vui8;
+vector_char4 vc4;
+vector_short4 vs4;
+vector_int4 vi4;
+vector_uchar4 vuc4;
+vector_ushort4 vus4;
+vector_uint4 vui4;
+
+void foo() {
+  vc8 = 1 << vc8;
+// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}}, align 8
+// CHECK: shl <8 x i8> , [[t0]]
+  vuc8 = 1 << vuc8;
+// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* @vuc8, align 8
+// CHECK: shl <8 x i8> , [[t1]]
+  vi8 = 1 << vi8;
+// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* @vi8, align 32
+// CHECK: shl <8 x i32> , [[t2]]
+  vui8 = 1 << vui8;
+// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* @vui8, align 32
+// CHECK: shl <8 x i32> , [[t3]]
+  vs8 = 1 << vs8;
+// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* @vs8, align 16
+// CHECK: shl <8 x i16> , [[t4]]
+  vus8 = 1 << vus8;
+// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* @vus8, align 16
+// CHECK: shl <8 x i16> , [[t5]]
+
+  vc8 = c << vc8;
+// CHECK: [[t6:%.+]] = load i8, i8* @c, align 1
+// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0
+// CHEC

r281609 - Silence false positive diagnostics regarding passing an object of enumeration type to va_start(). The underlying type for an enumeration in C is either char, signed int, or unsigned int. In

2016-09-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Sep 15 09:01:10 2016
New Revision: 281609

URL: http://llvm.org/viewvc/llvm-project?rev=281609&view=rev
Log:
Silence false positive diagnostics regarding passing an object of enumeration 
type to va_start(). The underlying type for an enumeration in C is either char, 
signed int, or unsigned int. In the case the underlying type is chosen to be 
char (such as when passing -fshort-enums or using __attribute__((packed)) on 
the enum declaration), the enumeration can result in undefined behavior. 
However, when the underlying type is signed int or unsigned int (or long long 
as an extension), there is no undefined behavior because the types are 
compatible. This patch silences diagnostics for the latter while retaining the 
diagnostics for the former.

This patch addresses PR29140.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/varargs.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=281609&r1=281608&r2=281609&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 15 09:01:10 2016
@@ -3240,8 +3240,17 @@ bool Sema::SemaBuiltinVAStartImpl(CallEx
 Diag(TheCall->getArg(1)->getLocStart(),
  diag::warn_second_arg_of_va_start_not_last_named_param);
   else if (IsCRegister || Type->isReferenceType() ||
-   Type->isPromotableIntegerType() ||
-   Type->isSpecificBuiltinType(BuiltinType::Float)) {
+   Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
+ // Promotable integers are UB, but enumerations need a bit of
+ // extra checking to see what their promotable type actually is.
+ if (!Type->isPromotableIntegerType())
+   return false;
+ if (!Type->isEnumeralType())
+   return true;
+ const EnumDecl *ED = Type->getAs()->getDecl();
+ return !(ED &&
+  Context.typesAreCompatible(ED->getPromotionType(), 
Type));
+   }()) {
 unsigned Reason = 0;
 if (Type->isReferenceType())  Reason = 1;
 else if (IsCRegister) Reason = 2;

Modified: cfe/trunk/test/Sema/varargs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=281609&r1=281608&r2=281609&view=diff
==
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Thu Sep 15 09:01:10 2016
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s
 
 void f1(int a)
 {
@@ -94,3 +95,20 @@ void f12(register int i, ...) {  // expe
   __builtin_va_start(ap, i); // expected-warning {{passing a parameter 
declared with the 'register' keyword to 'va_start' has undefined behavior}}
   __builtin_va_end(ap);
 }
+
+enum __attribute__((packed)) E1 {
+  one1
+};
+
+void f13(enum E1 e, ...) {
+  __builtin_va_list va;
+  __builtin_va_start(va, e);
+#ifndef MS
+  // In Microsoft compatibility mode, all enum types are int, but in
+  // non-ms-compatibility mode, this enumeration type will undergo default
+  // argument promotions.
+  // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
+  // expected-warning@-6 {{passing an object that undergoes default argument 
promotion to 'va_start' has undefined behavior}}
+#endif
+  __builtin_va_end(va);
+}


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


Re: [PATCH] D23921: Remove va_start diagnostic false positive with enumerations

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

Commit in r281609


https://reviews.llvm.org/D23921



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


Re: [PATCH] D24183: A clang tool for changing surrouding namespaces of class/function definitions.

2016-09-15 Thread Haojian Wu via cfe-commits
hokein added inline comments.


Comment at: change-namespace/ChangeNamespace.cpp:200
@@ +199,3 @@
+  while (!NsSplitted.empty()) {
+// FIXME: consider code style for comments.
+Code = ("namespace " + NsSplitted.back() + " {\n" + Code +

Doesn't `formatAndApplyAllReplacements` format the comments for us?


Comment at: change-namespace/ChangeNamespace.cpp:213
@@ +212,3 @@
+llvm::StringRef OldNs, llvm::StringRef NewNs,
+const std::string &FilePattern,
+std::map *FileToReplacements,

StringRef.


Comment at: change-namespace/ChangeNamespace.cpp:242
@@ +241,3 @@
+  // Match old namespace blocks.
+  Finder->addMatcher(namespaceDecl(hasName(OldNamespace),
+   isExpansionInFileMatching(FilePattern))

Actually, `hasName` matches the name which ends with `OldNamespace`, which 
doesn't align with the your comments in `OldNamespace` member variable.


Comment at: change-namespace/ChangeNamespace.cpp:373
@@ +372,3 @@
+  // code from old namespace to new namespace.
+  // Insertion information is stores in `InsertFwdDecls` and actual
+  // insertion will be performed in `onEndOfTranslationUnit`.

s/stores/stored


Comment at: change-namespace/ChangeNamespace.cpp:400
@@ +399,3 @@
+  assert(Consumed && "Expect OldNS to start with OldNamespace.");
+  (void)Consumed;
+  const std::string NewNs = (NewNamespace + Postfix).str();

how about `assert(Postfix.consume_front(OldNamespace) && "Expect OldNS to start 
with OldNamespace.");`?


Comment at: change-namespace/ChangeNamespace.cpp:421
@@ +420,3 @@
+
+void ChangeNamespaceTool::fixTypeLoc(
+const ast_matchers::MatchFinder::MatchResult &Result, SourceLocation Start,

Could you add some comments describe what stuff does this function do? The name 
`fixTypeLoc` doesn't explain too much. Looks like this function is replacing 
the qualifiers in TypeLoc.


Comment at: change-namespace/ChangeNamespace.h:43
@@ +42,3 @@
+// FIXME: support moving typedef, enums across namespaces.
+class ChangeNamespaceTool : ast_matchers::MatchFinder::MatchCallback {
+public:

I think you are missing `public` keyword here, otherwise, it will be private 
inheritance.


Comment at: change-namespace/tool/ClangChangeNamespace.cpp:46
@@ +45,3 @@
+
+cl::OptionCategory ChangeNamespaceCategory("Tool options");
+

change to "Change namespace"?


Comment at: change-namespace/tool/ClangChangeNamespace.cpp:106
@@ +105,3 @@
+outs() << "== " << File << " ==\n";
+Rewrite.getEditBuffer(ID).write(llvm::outs());
+outs() << "\n\n";

Might be add a FIXME?


https://reviews.llvm.org/D24183



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


r281610 - [mips][ias] Enable IAS by default for N64 on Debian mips64el.

2016-09-15 Thread Simon Dardis via cfe-commits
Author: sdardis
Date: Thu Sep 15 09:01:55 2016
New Revision: 281610

URL: http://llvm.org/viewvc/llvm-project?rev=281610&view=rev
Log:
[mips][ias] Enable IAS by default for N64 on Debian mips64el.

Unfortunately we can't enable it for all N64 because it is not yet possible to
distinguish N32 from N64 from the triple on other environments.

N64 has been confirmed to produce identical (within reason) objects to GAS
during stage 2 of compiler recursion on N64-abi Fedora. Unfortunately,
Fedora's triples do not distinguish N32 from N64 so I can't enable it by
default there. I'm currently repeating this testing for Debian mips64el but
it's very unlikely to produce a different result.

Patch by: Daniel Sanders

Reviewers: sdardis

Differential Review: https://reviews.llvm.org/D22679

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

Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=281610&r1=281609&r2=281610&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Sep 15 09:01:55 2016
@@ -2778,6 +2778,13 @@ bool Generic_GCC::IsIntegratedAssemblerD
   case llvm::Triple::mips:
   case llvm::Triple::mipsel:
 return true;
+  case llvm::Triple::mips64:
+  case llvm::Triple::mips64el:
+// Enabled for Debian mips64/mips64el only. Other targets are unable to
+// distinguish N32 from N64.
+if (getTriple().getEnvironment() == llvm::Triple::GNUABI64)
+  return true;
+return false;
   default:
 return false;
   }


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


Re: [PATCH] D22679: [mips][ias] Enable IAS by default for N64 on Debian mips64el.

2016-09-15 Thread Simon Dardis via cfe-commits
sdardis closed this revision.
sdardis added a comment.

Committed as https://reviews.llvm.org/rL281610.


https://reviews.llvm.org/D22679



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


r281612 - Reverting r281609; it caused some build bots to break.

2016-09-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Sep 15 09:12:33 2016
New Revision: 281612

URL: http://llvm.org/viewvc/llvm-project?rev=281612&view=rev
Log:
Reverting r281609; it caused some build bots to break.

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/20061/steps/test/logs/stdio

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/varargs.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=281612&r1=281611&r2=281612&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 15 09:12:33 2016
@@ -3240,17 +3240,8 @@ bool Sema::SemaBuiltinVAStartImpl(CallEx
 Diag(TheCall->getArg(1)->getLocStart(),
  diag::warn_second_arg_of_va_start_not_last_named_param);
   else if (IsCRegister || Type->isReferenceType() ||
-   Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
- // Promotable integers are UB, but enumerations need a bit of
- // extra checking to see what their promotable type actually is.
- if (!Type->isPromotableIntegerType())
-   return false;
- if (!Type->isEnumeralType())
-   return true;
- const EnumDecl *ED = Type->getAs()->getDecl();
- return !(ED &&
-  Context.typesAreCompatible(ED->getPromotionType(), 
Type));
-   }()) {
+   Type->isPromotableIntegerType() ||
+   Type->isSpecificBuiltinType(BuiltinType::Float)) {
 unsigned Reason = 0;
 if (Type->isReferenceType())  Reason = 1;
 else if (IsCRegister) Reason = 2;

Modified: cfe/trunk/test/Sema/varargs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=281612&r1=281611&r2=281612&view=diff
==
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Thu Sep 15 09:12:33 2016
@@ -1,6 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
-// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s
 
 void f1(int a)
 {
@@ -95,20 +94,3 @@ void f12(register int i, ...) {  // expe
   __builtin_va_start(ap, i); // expected-warning {{passing a parameter 
declared with the 'register' keyword to 'va_start' has undefined behavior}}
   __builtin_va_end(ap);
 }
-
-enum __attribute__((packed)) E1 {
-  one1
-};
-
-void f13(enum E1 e, ...) {
-  __builtin_va_list va;
-  __builtin_va_start(va, e);
-#ifndef MS
-  // In Microsoft compatibility mode, all enum types are int, but in
-  // non-ms-compatibility mode, this enumeration type will undergo default
-  // argument promotions.
-  // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
-  // expected-warning@-6 {{passing an object that undergoes default argument 
promotion to 'va_start' has undefined behavior}}
-#endif
-  __builtin_va_end(va);
-}


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


Re: [PATCH] D24243: [clang-move] A prototype tool for moving class definition to new file.

2016-09-15 Thread Haojian Wu via cfe-commits
hokein updated this revision to Diff 71506.
hokein marked 2 inline comments as done.
hokein added a comment.
Herald added a subscriber: mgorny.

Address review comments.


https://reviews.llvm.org/D24243

Files:
  CMakeLists.txt
  clang-move/CMakeLists.txt
  clang-move/ClangMove.cpp
  clang-move/ClangMove.h
  clang-move/tool/CMakeLists.txt
  clang-move/tool/ClangMoveMain.cpp
  unittests/CMakeLists.txt
  unittests/clang-move/CMakeLists.txt
  unittests/clang-move/ClangMoveTests.cpp

Index: unittests/clang-move/ClangMoveTests.cpp
===
--- /dev/null
+++ unittests/clang-move/ClangMoveTests.cpp
@@ -0,0 +1,226 @@
+//===-- ClangMoveTest.cpp - clang-move unit tests -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangMove.h"
+#include "unittests/Tooling/RewriterTestContext.h"
+#include "clang/Format/Format.h"
+#include "clang/Frontend/FrontendActions.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Rewrite/Core/Rewriter.h"
+#include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/StringRef.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace clang {
+namespace move {
+namespace {
+
+const char TestHeaderName[] = "foo.h";
+
+const char TestCCName[] = "foo.cc";
+
+const char TestHeader[] = "namespace a {\n"
+  "class C1;\n"
+  "namespace b {\n"
+  "class Foo {\n"
+  "public:\n"
+  "  void f();\n"
+  "\n"
+  "private:\n"
+  "  C1 *c1;\n"
+  "  static int b;\n"
+  "};\n"
+  "\n"
+  "class Foo2 {\n"
+  "public:\n"
+  "  int f();\n"
+  "};\n"
+  "} // namespace b\n"
+  "} // namespace a\n";
+
+const char TestCC[] = "#include \"foo.h\"\n"
+  "namespace a {\n"
+  "namespace b {\n"
+  "namespace {\n"
+  "void f1() {}\n"
+  "int kConstInt1 = 0;\n"
+  "} // namespace\n"
+  "\n"
+  "static int kConstInt2 = 1;\n"
+  "\n"
+  "static int help() {\n"
+  "  int a = 0;\n"
+  "  return a;\n"
+  "}\n"
+  "\n"
+  "void Foo::f() { f1(); }\n"
+  "\n"
+  "int Foo::b = 2;\n"
+  "int Foo2::f() {\n"
+  "  f1();\n"
+  "  return 1;\n"
+  "}\n"
+  "} // namespace b\n"
+  "} // namespace a\n";
+
+const char ExpectedTestHeader[] = "namespace a {\n"
+  "class C1;\n"
+  "namespace b {\n"
+  "\n"
+  "class Foo2 {\n"
+  "public:\n"
+  "  int f();\n"
+  "};\n"
+  "} // namespace b\n"
+  "} // namespace a\n";
+
+const char ExpectedTestCC[] = "#include \"foo.h\"\n"
+  "namespace a {\n"
+  "namespace b {\n"
+  "namespace {\n"
+  "void f1() {}\n"
+  "int kConstInt1 = 0;\n"
+  "} // namespace\n"
+  "\n"
+  "static int kConstInt2 = 1;\n"
+  "\n"
+  "static int help() {\n"
+  "  int a = 0;\n"
+  "  return a;\n"
+  "}\n"
+  "\n"
+  "int Foo2::f() {\n"
+  "  f1();\n"
+  "  return 1;\n"
+  "}\n"
+  "} // namespace b\n"
+  "} // namespace a\n";
+
+const char ExpectedNewHeader[] = "namespace a {\n"
+ "class C1;\n"
+ "namespace b {\n"
+ "class Foo {\n"
+ "public:\n"

Re: [PATCH] D24243: [clang-move] A prototype tool for moving class definition to new file.

2016-09-15 Thread Haojian Wu via cfe-commits
hokein added inline comments.


Comment at: clang-move/ClangMove.cpp:104
@@ +103,3 @@
+  std::reverse(Namespaces.begin(), Namespaces.end());
+  return Namespaces;
+}

Aha, I see. I misused the `findLocationAfterToken` previously.


Comment at: clang-move/ClangMove.cpp:130
@@ +129,3 @@
+  // Add #Includes.
+  std::string AllIncludesString;
+  // FIXME: Filter out the old_header.h and add header guard.

For anonymous namespace, `getNamespaces` just makes it an empty string.
Apart from that, we have to deal with other exceptions, for instance:


```
namespace a {
void A::f() {}
}
```
What we want is namespace `a`, but `getQualifiedNameAsString` returns 
`a::A::f`. Thus, using `getQualifiedNameAsString` wouldn't simplify the code at 
the moment. 



https://reviews.llvm.org/D24243



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


Re: [PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

2016-09-15 Thread Tavian Barnes via cfe-commits
tavianator updated this revision to Diff 71508.
tavianator added a comment.
Herald added subscribers: mgorny, beanz.

Integrated @EricWF's expanded test case, and avoid an unneeded 
pthread_setspecific() call if the last thread_local's destructor initializes a 
new thread_local.


https://reviews.llvm.org/D21803

Files:
  src/cxa_thread_atexit.cpp
  test/CMakeLists.txt
  test/cxa_thread_atexit_test.pass.cpp
  test/libcxxabi/test/config.py
  test/lit.site.cfg.in
  test/thread_local_destruction_order.pass.cpp

Index: test/thread_local_destruction_order.pass.cpp
===
--- test/thread_local_destruction_order.pass.cpp
+++ test/thread_local_destruction_order.pass.cpp
@@ -0,0 +1,56 @@
+//===-- thread_local_destruction_order.pass.cpp ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+#include 
+#include 
+
+int seq = 0;
+
+class OrderChecker {
+public:
+  explicit OrderChecker(int n) : n_{n} { }
+
+  ~OrderChecker() {
+assert(seq++ == n_);
+  }
+
+private:
+  int n_;
+};
+
+template 
+class CreatesThreadLocalInDestructor {
+public:
+  ~CreatesThreadLocalInDestructor() {
+thread_local OrderChecker checker{ID};
+  }
+};
+
+OrderChecker global{7};
+
+void thread_fn() {
+  static OrderChecker fn_static{5};
+  thread_local CreatesThreadLocalInDestructor<2> creates_tl2;
+  thread_local OrderChecker fn_thread_local{1};
+  thread_local CreatesThreadLocalInDestructor<0> creates_tl0;
+}
+
+int main() {
+  static OrderChecker fn_static{6};
+
+  std::thread{thread_fn}.join();
+  assert(seq == 3);
+
+  thread_local OrderChecker fn_thread_local{4};
+  thread_local CreatesThreadLocalInDestructor<3> creates_tl;
+
+  return 0;
+}
Index: test/lit.site.cfg.in
===
--- test/lit.site.cfg.in
+++ test/lit.site.cfg.in
@@ -13,7 +13,6 @@
 config.enable_32bit = "@LIBCXXABI_BUILD_32_BITS@"
 config.target_info  = "@LIBCXXABI_TARGET_INFO@"
 config.executor = "@LIBCXXABI_EXECUTOR@"
-config.thread_atexit= "@LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL@"
 config.libcxxabi_shared = "@LIBCXXABI_ENABLE_SHARED@"
 config.enable_shared= "@LIBCXX_ENABLE_SHARED@"
 config.enable_exceptions= "@LIBCXXABI_ENABLE_EXCEPTIONS@"
Index: test/libcxxabi/test/config.py
===
--- test/libcxxabi/test/config.py
+++ test/libcxxabi/test/config.py
@@ -37,8 +37,6 @@
 super(Configuration, self).configure_features()
 if not self.get_lit_bool('enable_exceptions', True):
 self.config.available_features.add('libcxxabi-no-exceptions')
-if self.get_lit_bool('thread_atexit', True):
-self.config.available_features.add('thread_atexit')
 
 def configure_compile_flags(self):
 self.cxx.compile_flags += ['-DLIBCXXABI_NO_TIMER']
Index: test/cxa_thread_atexit_test.pass.cpp
===
--- test/cxa_thread_atexit_test.pass.cpp
+++ test/cxa_thread_atexit_test.pass.cpp
@@ -8,7 +8,6 @@
 //===--===//
 
 // REQUIRES: linux
-// REQUIRES: thread_atexit
 
 #include 
 #include 
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -16,7 +16,6 @@
 pythonize_bool(LIBCXXABI_ENABLE_THREADS)
 pythonize_bool(LIBCXXABI_ENABLE_EXCEPTIONS)
 pythonize_bool(LIBCXXABI_USE_LLVM_UNWINDER)
-pythonize_bool(LIBCXXABI_HAS_CXA_THREAD_ATEXIT_IMPL)
 set(LIBCXXABI_TARGET_INFO "libcxx.test.target_info.LocalTI" CACHE STRING
 "TargetInfo to use when setting up test environment.")
 set(LIBCXXABI_EXECUTOR "None" CACHE STRING
Index: src/cxa_thread_atexit.cpp
===
--- src/cxa_thread_atexit.cpp
+++ src/cxa_thread_atexit.cpp
@@ -7,20 +7,133 @@
 //
 //===--===//
 
+#include "abort_message.h"
 #include "cxxabi.h"
+#include 
+#include 
 
 namespace __cxxabiv1 {
-extern "C" {
 
-#ifdef HAVE___CXA_THREAD_ATEXIT_IMPL
+  using Dtor = void(*)(void*);
 
-_LIBCXXABI_FUNC_VIS int __cxa_thread_atexit(void (*dtor)(void *), void *obj,
-void *dso_symbol) throw() {
-  extern int __cxa_thread_atexit_impl(void (*)(void *), void *, void *);
-  return __cxa_thread_atexit_impl(dtor, obj, dso_symbol);
-}
+  extern "C"
+#ifndef HAVE___CXA_THREAD_ATEXIT_IMPL
+  // A weak symbol is used to detect this function's presence in the C library
+  // at runtim

Re: [PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

2016-09-15 Thread Tavian Barnes via cfe-commits
tavianator marked 5 inline comments as done.


Comment at: src/cxa_thread_atexit.cpp:70
@@ +69,3 @@
+while (auto head = dtors) {
+  dtors = head->next;
+  head->dtor(head->obj);

EricWF wrote:
> tavianator wrote:
> > EricWF wrote:
> > > tavianator wrote:
> > > > EricWF wrote:
> > > > > There is a bug here. If `head->next == nullptr` and if 
> > > > > `head->dtor(head->obj))` creates a TL variable in the destructor then 
> > > > > that destructor will not be invoked.
> > > > > 
> > > > > Here's an updated test case which catches the bug: 
> > > > > https://gist.github.com/EricWF/3bb50d4f28b91aa28d2adefea0e94a0e
> > > > I can't reproduce that failure here, your exact test case passes (even 
> > > > with `#undef HAVE___CXA_THREAD_ATEXIT_IMPL` and the weak symbol test 
> > > > commented out).
> > > > 
> > > > Tracing the implementation logic, it seems correct.  If `head->next == 
> > > > nullptr` then this line does `dtors = nullptr`.  Then if 
> > > > `head->dtor(head->obj)` registers a new `thread_local`, 
> > > > `__cxa_thread_atexit()` does `head = malloc(...); ... dtors = head;`.  
> > > > Then the next iteration of the loop `while (auto head = dtors) {` picks 
> > > > up that new node.
> > > > 
> > > > Have I missed something?
> > > I can't reproduce this morning either, I must have been doing something 
> > > funny. I'll look at this with a fresh head tomorrow. If I can't find 
> > > anything this will be good to go. Thanks for working on this. 
> > No problem!  I can integrate your updated test case anyway if you want.
> Yeah I would like to see the upgraded test case applied. At least that way 
> we're testing the case in question.
> 
> So I agree with your above analysis of what happens, and that all destructors 
> are correctly called during the first iteration of pthread key destruction. 
> My one issues is that we still register a new non-null key which forces 
> pthread to run the destructor for the key again. I would like to see this 
> fixed.
Yep, done!  I guess that was the point of `thread_alive` from your original 
patch-to-my-patch, sorry for stripping it out.


https://reviews.llvm.org/D21803



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


Re: [PATCH] D20811: [analyzer] Model some library functions

2016-09-15 Thread Artem Dergachev via cfe-commits
NoQ updated this revision to Diff 71510.
NoQ marked an inline comment as done.
NoQ added a comment.
Herald added subscribers: mgorny, beanz.

Added a huge amount of macros in order to improve readability of function specs.
Other inline comments should have been addressed before.


https://reviews.llvm.org/D20811

Files:
  include/clang/StaticAnalyzer/Checkers/Checkers.td
  lib/StaticAnalyzer/Checkers/CMakeLists.txt
  lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  test/Analysis/std-library-functions.c
  test/Analysis/std-library-functions.cpp

Index: test/Analysis/std-library-functions.cpp
===
--- /dev/null
+++ test/Analysis/std-library-functions.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdLibraryFunctions,debug.ExprInspection -verify %s
+
+// Test that we don't model functions with broken prototypes.
+// Because they probably work differently as well.
+//
+// This test lives in a separate file because we wanted to test all functions
+// in the .c file, however in C there are no overloads.
+
+void clang_analyzer_eval(bool);
+bool isalpha(char);
+
+void test() {
+  clang_analyzer_eval(isalpha('A')); // no-crash // expected-warning{{UNKNOWN}}
+}
Index: test/Analysis/std-library-functions.c
===
--- /dev/null
+++ test/Analysis/std-library-functions.c
@@ -0,0 +1,184 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=unix.StdLibraryFunctions,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(int);
+
+int glob;
+
+typedef struct FILE FILE;
+#define EOF -1
+
+int getc(FILE *);
+void test_getc(FILE *fp) {
+  int x;
+  while ((x = getc(fp)) != EOF) {
+clang_analyzer_eval(x > 255); // expected-warning{{FALSE}}
+clang_analyzer_eval(x >= 0); // expected-warning{{TRUE}}
+  }
+}
+
+int fgetc(FILE *);
+void test_fgets(FILE *fp) {
+  clang_analyzer_eval(fgetc(fp) < 256); // expected-warning{{TRUE}}
+  clang_analyzer_eval(fgetc(fp) >= 0); // expected-warning{{UNKNOWN}}
+}
+
+
+typedef unsigned long size_t;
+typedef signed long ssize_t;
+ssize_t read(int, void *, size_t);
+ssize_t write(int, const void *, size_t);
+void test_read_write(int fd, char *buf) {
+  glob = 1;
+  ssize_t x = write(fd, buf, 10);
+  clang_analyzer_eval(glob); // expected-warning{{UNKNOWN}}
+  if (x >= 0) {
+clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+ssize_t y = read(fd, &glob, sizeof(glob));
+if (y >= 0) {
+  clang_analyzer_eval(y <= sizeof(glob)); // expected-warning{{TRUE}}
+} else {
+  // -1 overflows on promotion!
+  clang_analyzer_eval(y <= sizeof(glob)); // expected-warning{{FALSE}}
+}
+  } else {
+clang_analyzer_eval(x == -1); // expected-warning{{TRUE}}
+  }
+}
+
+size_t fread(void *, size_t, size_t, FILE *);
+size_t fwrite(const void *restrict, size_t, size_t, FILE *restrict);
+void test_fread_fwrite(FILE *fp, int *buf) {
+  size_t x = fwrite(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(x <= 10); // expected-warning{{TRUE}}
+  size_t y = fread(buf, sizeof(int), 10, fp);
+  clang_analyzer_eval(y <= 10); // expected-warning{{TRUE}}
+  size_t z = fwrite(buf, sizeof(int), y, fp);
+  // FIXME: should be TRUE once symbol-symbol constraint support is improved.
+  clang_analyzer_eval(z <= y); // expected-warning{{UNKNOWN}}
+}
+
+ssize_t getline(char **, size_t *, FILE *);
+void test_getline(FILE *fp) {
+  char *line = 0;
+  size_t n = 0;
+  ssize_t len;
+  while ((len = getline(&line, &n, fp)) != -1) {
+clang_analyzer_eval(len == 0); // expected-warning{{FALSE}}
+  }
+}
+
+int isascii(int);
+void test_isascii(int x) {
+  clang_analyzer_eval(isascii(123)); // expected-warning{{TRUE}}
+  clang_analyzer_eval(isascii(-1)); // expected-warning{{FALSE}}
+  if (isascii(x)) {
+clang_analyzer_eval(x < 128); // expected-warning{{TRUE}}
+clang_analyzer_eval(x >= 0); // expected-warning{{TRUE}}
+  } else {
+if (x > 42)
+  clang_analyzer_eval(x >= 128); // expected-warning{{TRUE}}
+else
+  clang_analyzer_eval(x < 0); // expected-warning{{TRUE}}
+  }
+  glob = 1;
+  isascii('a');
+  clang_analyzer_eval(glob); // expected-warning{{TRUE}}
+}
+
+int islower(int);
+void test_islower(int x) {
+  clang_analyzer_eval(islower('x')); // expected-warning{{TRUE}}
+  clang_analyzer_eval(islower('X')); // expected-warning{{FALSE}}
+  if (islower(x))
+clang_analyzer_eval(x < 'a'); // expected-warning{{FALSE}}
+}
+
+int getchar(void);
+void test_getchar() {
+  int x = getchar();
+  if (x == EOF)
+return;
+  clang_analyzer_eval(x < 0); // expected-warning{{FALSE}}
+  clang_analyzer_eval(x < 256); // expected-warning{{TRUE}}
+}
+
+int isalpha(int);
+void test_isalpha() {
+  clang_analyzer_eval(isalpha(']')); // expected-warning{{FALSE}}
+  clang_analyzer_eval(isalpha('Q')); // expected-warning{{TRUE}}
+  clang_analyzer_eval(isalpha(128)); // expected-warning{{UNKNOWN}}
+}
+
+int isalnum(int);
+void test_

r281625 - [analyzer] Fix HTMLRewriter style sheets to support non-webkit browsers.

2016-09-15 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Sep 15 11:25:42 2016
New Revision: 281625

URL: http://llvm.org/viewvc/llvm-project?rev=281625&view=rev
Log:
[analyzer] Fix HTMLRewriter style sheets to support non-webkit browsers.

This fixes rounded corners and shadows of analyzer diagnostic pieces
in browsers such as Firefox.

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

Modified:
cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Modified: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/HTMLRewrite.cpp?rev=281625&r1=281624&r2=281625&view=diff
==
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp (original)
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp Thu Sep 15 11:25:42 2016
@@ -301,6 +301,7 @@ void html::AddHeaderFooterInternalBuilti
   " .macro:hover .expansion { display: block; border: 2px solid #FF; "
   "padding: 2px; background-color:#FFF0F0; font-weight: normal; "
   "  -webkit-border-radius:5px;  -webkit-box-shadow:1px 1px 7px #000; "
+  "  border-radius:5px;  box-shadow:1px 1px 7px #000; "
   "position: absolute; top: -1em; left:10em; z-index: 1 } \n"
   " .macro { color: darkmagenta; background-color:LemonChiffon;"
  // Macros are position: relative to provide base for expansions.
@@ -311,7 +312,9 @@ void html::AddHeaderFooterInternalBuilti
   " .line { padding-left: 1ex; border-left: 3px solid #ccc }\n"
   " .line { white-space: pre }\n"
   " .msg { -webkit-box-shadow:1px 1px 7px #000 }\n"
+  " .msg { box-shadow:1px 1px 7px #000 }\n"
   " .msg { -webkit-border-radius:5px }\n"
+  " .msg { border-radius:5px }\n"
   " .msg { font-family:Helvetica, sans-serif; font-size:8pt }\n"
   " .msg { float:left }\n"
   " .msg { padding:0.25em 1ex 0.25em 1ex }\n"
@@ -326,6 +329,7 @@ void html::AddHeaderFooterInternalBuilti
   " .PathIndex { font-weight: bold; padding:0px 5px; "
 "margin-right:5px; }\n"
   " .PathIndex { -webkit-border-radius:8px }\n"
+  " .PathIndex { border-radius:8px }\n"
   " .PathIndexEvent { background-color:#bfba87 }\n"
   " .PathIndexControl { background-color:#8c8c8c }\n"
   " .PathNav a { text-decoration:none; font-size: larger }\n"


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


Re: [PATCH] D23272: [analyzer][Rewrite] Fix boxes and shadows in HTML rewrites in Firefox.

2016-09-15 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281625: [analyzer] Fix HTMLRewriter style sheets to support 
non-webkit browsers. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D23272?vs=67182&id=71517#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23272

Files:
  cfe/trunk/lib/Rewrite/HTMLRewrite.cpp

Index: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
===
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
@@ -301,6 +301,7 @@
   " .macro:hover .expansion { display: block; border: 2px solid #FF; "
   "padding: 2px; background-color:#FFF0F0; font-weight: normal; "
   "  -webkit-border-radius:5px;  -webkit-box-shadow:1px 1px 7px #000; "
+  "  border-radius:5px;  box-shadow:1px 1px 7px #000; "
   "position: absolute; top: -1em; left:10em; z-index: 1 } \n"
   " .macro { color: darkmagenta; background-color:LemonChiffon;"
  // Macros are position: relative to provide base for expansions.
@@ -311,7 +312,9 @@
   " .line { padding-left: 1ex; border-left: 3px solid #ccc }\n"
   " .line { white-space: pre }\n"
   " .msg { -webkit-box-shadow:1px 1px 7px #000 }\n"
+  " .msg { box-shadow:1px 1px 7px #000 }\n"
   " .msg { -webkit-border-radius:5px }\n"
+  " .msg { border-radius:5px }\n"
   " .msg { font-family:Helvetica, sans-serif; font-size:8pt }\n"
   " .msg { float:left }\n"
   " .msg { padding:0.25em 1ex 0.25em 1ex }\n"
@@ -326,6 +329,7 @@
   " .PathIndex { font-weight: bold; padding:0px 5px; "
 "margin-right:5px; }\n"
   " .PathIndex { -webkit-border-radius:8px }\n"
+  " .PathIndex { border-radius:8px }\n"
   " .PathIndexEvent { background-color:#bfba87 }\n"
   " .PathIndexControl { background-color:#8c8c8c }\n"
   " .PathNav a { text-decoration:none; font-size: larger }\n"


Index: cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
===
--- cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
+++ cfe/trunk/lib/Rewrite/HTMLRewrite.cpp
@@ -301,6 +301,7 @@
   " .macro:hover .expansion { display: block; border: 2px solid #FF; "
   "padding: 2px; background-color:#FFF0F0; font-weight: normal; "
   "  -webkit-border-radius:5px;  -webkit-box-shadow:1px 1px 7px #000; "
+  "  border-radius:5px;  box-shadow:1px 1px 7px #000; "
   "position: absolute; top: -1em; left:10em; z-index: 1 } \n"
   " .macro { color: darkmagenta; background-color:LemonChiffon;"
  // Macros are position: relative to provide base for expansions.
@@ -311,7 +312,9 @@
   " .line { padding-left: 1ex; border-left: 3px solid #ccc }\n"
   " .line { white-space: pre }\n"
   " .msg { -webkit-box-shadow:1px 1px 7px #000 }\n"
+  " .msg { box-shadow:1px 1px 7px #000 }\n"
   " .msg { -webkit-border-radius:5px }\n"
+  " .msg { border-radius:5px }\n"
   " .msg { font-family:Helvetica, sans-serif; font-size:8pt }\n"
   " .msg { float:left }\n"
   " .msg { padding:0.25em 1ex 0.25em 1ex }\n"
@@ -326,6 +329,7 @@
   " .PathIndex { font-weight: bold; padding:0px 5px; "
 "margin-right:5px; }\n"
   " .PathIndex { -webkit-border-radius:8px }\n"
+  " .PathIndex { border-radius:8px }\n"
   " .PathIndexEvent { background-color:#bfba87 }\n"
   " .PathIndexControl { background-color:#8c8c8c }\n"
   " .PathNav a { text-decoration:none; font-size: larger }\n"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24599: Add 'inline' but not _LIBCPP_INLINE_VISIBILITY to basic_string's destructor

2016-09-15 Thread Marshall Clow via cfe-commits
mclow.lists added a comment.

Any reason we shouldn't just revert r280944, wait for the LLVM bug to be fixed, 
and then re-apply it?


https://reviews.llvm.org/D24599



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


[PATCH] D24615: [OpenMP] clang doesnt diagnose if there is a lexical block around a for stmt for OpenMP loops. It is technically not allowed in the OpenMP standard

2016-09-15 Thread David Sheinkman via cfe-commits
davidsh created this revision.
davidsh added reviewers: carlo.bertolli, arpith-jacob, kkwli0, sfantao, ABataev.
davidsh added a subscriber: cfe-commits.


#pragma omp for
{
for(...)
}

This is technically not allowed by the standard, gcc doesnt allow such code.


https://reviews.llvm.org/D24615

Files:
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/for_loop_messages.cpp

Index: test/OpenMP/for_loop_messages.cpp
===
--- test/OpenMP/for_loop_messages.cpp
+++ test/OpenMP/for_loop_messages.cpp
@@ -353,6 +353,14 @@
   }
 
 #pragma omp parallel
+// expected-error@+2 {{statement after '#pragma omp for' must be a for loop}}
+#pragma omp for
+  {
+  for (int i = 0; i < 16; ++i)
+;
+  }
+
+#pragma omp parallel
 // expected-note@+3 {{loop step is expected to be positive due to this 
condition}}
 // expected-error@+2 {{increment expression must cause 'i' to increase on each 
iteration of OpenMP for loop}}
 #pragma omp for
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -5133,7 +5133,9 @@
   llvm::MapVector Captures;
   SmallVector IterSpaces;
   IterSpaces.resize(NestedLoopCount);
-  Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true);
+  Stmt *CurStmt = AStmt;
+  if (auto CapS = dyn_cast_or_null(CurStmt))
+CurStmt = CapS->getCapturedStmt();
   for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) {
 if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt,
   NestedLoopCount, CollapseLoopCountExpr,


Index: test/OpenMP/for_loop_messages.cpp
===
--- test/OpenMP/for_loop_messages.cpp
+++ test/OpenMP/for_loop_messages.cpp
@@ -353,6 +353,14 @@
   }
 
 #pragma omp parallel
+// expected-error@+2 {{statement after '#pragma omp for' must be a for loop}}
+#pragma omp for
+  {
+  for (int i = 0; i < 16; ++i)
+;
+  }
+
+#pragma omp parallel
 // expected-note@+3 {{loop step is expected to be positive due to this condition}}
 // expected-error@+2 {{increment expression must cause 'i' to increase on each iteration of OpenMP for loop}}
 #pragma omp for
Index: lib/Sema/SemaOpenMP.cpp
===
--- lib/Sema/SemaOpenMP.cpp
+++ lib/Sema/SemaOpenMP.cpp
@@ -5133,7 +5133,9 @@
   llvm::MapVector Captures;
   SmallVector IterSpaces;
   IterSpaces.resize(NestedLoopCount);
-  Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true);
+  Stmt *CurStmt = AStmt;
+  if (auto CapS = dyn_cast_or_null(CurStmt))
+CurStmt = CapS->getCapturedStmt();
   for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) {
 if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt,
   NestedLoopCount, CollapseLoopCountExpr,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r281632 - Reapply: Silence false positive diagnostics regarding passing an object of enumeration type to va_start().

2016-09-15 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Sep 15 13:07:51 2016
New Revision: 281632

URL: http://llvm.org/viewvc/llvm-project?rev=281632&view=rev
Log:
Reapply: Silence false positive diagnostics regarding passing an object of 
enumeration type to va_start().

The underlying type for an enumeration in C is either char, signed int, or 
unsigned int. In the case the underlying type is chosen to be char (such as 
when passing -fshort-enums or using __attribute__((packed)) on the enum 
declaration), the enumeration can result in undefined behavior. However, when 
the underlying type is signed int or unsigned int (or long long as an 
extension), there is no undefined behavior because the types are compatible. 
This patch silences diagnostics for the latter while retaining the diagnostics 
for the former.

This patch addresses PR29140.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/varargs.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=281632&r1=281631&r2=281632&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 15 13:07:51 2016
@@ -3240,8 +3240,17 @@ bool Sema::SemaBuiltinVAStartImpl(CallEx
 Diag(TheCall->getArg(1)->getLocStart(),
  diag::warn_second_arg_of_va_start_not_last_named_param);
   else if (IsCRegister || Type->isReferenceType() ||
-   Type->isPromotableIntegerType() ||
-   Type->isSpecificBuiltinType(BuiltinType::Float)) {
+   Type->isSpecificBuiltinType(BuiltinType::Float) || [=] {
+ // Promotable integers are UB, but enumerations need a bit of
+ // extra checking to see what their promotable type actually is.
+ if (!Type->isPromotableIntegerType())
+   return false;
+ if (!Type->isEnumeralType())
+   return true;
+ const EnumDecl *ED = Type->getAs()->getDecl();
+ return !(ED &&
+  Context.typesAreCompatible(ED->getPromotionType(), 
Type));
+   }()) {
 unsigned Reason = 0;
 if (Type->isReferenceType())  Reason = 1;
 else if (IsCRegister) Reason = 2;

Modified: cfe/trunk/test/Sema/varargs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/varargs.c?rev=281632&r1=281631&r2=281632&view=diff
==
--- cfe/trunk/test/Sema/varargs.c (original)
+++ cfe/trunk/test/Sema/varargs.c Thu Sep 15 13:07:51 2016
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -triple i386-pc-unknown
 // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-apple-darwin9
+// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -DMS -verify %s -triple 
x86_64-pc-win32
 
 void f1(int a)
 {
@@ -94,3 +95,20 @@ void f12(register int i, ...) {  // expe
   __builtin_va_start(ap, i); // expected-warning {{passing a parameter 
declared with the 'register' keyword to 'va_start' has undefined behavior}}
   __builtin_va_end(ap);
 }
+
+enum __attribute__((packed)) E1 {
+  one1
+};
+
+void f13(enum E1 e, ...) {
+  __builtin_va_list va;
+  __builtin_va_start(va, e);
+#ifndef MS
+  // In Microsoft compatibility mode, all enum types are int, but in
+  // non-ms-compatibility mode, this enumeration type will undergo default
+  // argument promotions.
+  // expected-note@-7 {{parameter of type 'enum E1' is declared here}}
+  // expected-warning@-6 {{passing an object that undergoes default argument 
promotion to 'va_start' has undefined behavior}}
+#endif
+  __builtin_va_end(va);
+}


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


Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-09-15 Thread Nico Weber via cfe-commits
thakis added a comment.

Works for me if rnk likes it :-)

(We could bikeshed on if this should be one of the -Wmicrosoft warnings, but 
the warning can't be both in -Wall and -Wmicrosoft, so let's don't).

I do have a question about the test (the first commit below):



Comment at: test/SemaCXX/warn-msvc-enum-bitfield.cpp:12
@@ +11,3 @@
+
+  s.e2 = E2;
+  s.f2 = F2;

Shouldn't this be the version that warns? The assignment with E1 assigns 0 
which is portable, but this assigns 1 which overflows, right?


Comment at: test/SemaCXX/warn-msvc-enum-bitfield.cpp:39
@@ +38,3 @@
+  s.e2 = E2;
+  s.f2 = F2;
+}

We have -Wconversion warnings for similar cases; maybe we should have this here 
too (but not in this change):

Nicos-MBP:llvm-build thakis$ cat test2.cc
enum E {e1, e2};

struct S {
  E e1 : 1;
};
void f() {
  short s1 = 65536;
  short s2 = 32769;

  S s;
  s.e1 = e2;
}
Nicos-MBP:llvm-build thakis$ clang -Wconversion -c test2.cc
test2.cc:8:14: warning: implicit conversion changes signedness: 'int' to 
'short' [-Wsign-conversion]
  short s2 = 32769;
~~   ^
test2.cc:7:14: warning: implicit conversion from 'int' to 'short' changes value 
from 65536 to 0 [-Wconstant-conversion]
  short s1 = 65536;
~~   ^
2 warnings generated.


https://reviews.llvm.org/D24289



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


Re: [PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

2016-09-15 Thread Keno Fischer via cfe-commits
loladiro updated this revision to Diff 71528.
loladiro added a comment.

Add private copy of forward (__forward) that is constexpr even in C++11 mode, 
use test suggested by @rsmith


Repository:
  rL LLVM

https://reviews.llvm.org/D24372

Files:
  include/memory
  
test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp

Index: test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp
===
--- /dev/null
+++ test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp
@@ -0,0 +1,36 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+// UNSUPPORTED: c++98, c++03
+
+#include 
+#include 
+
+#ifndef _LIBCPP_SAFE_STATIC
+#define _LIBCPP_SAFE_STATIC
+#endif
+
+extern std::unique_ptr a;
+extern std::unique_ptr b;
+void *tramplea = std::memset(&a, 0xab, sizeof(a));
+void *trampleb = std::memset(&b, 0xab, sizeof(b));
+_LIBCPP_SAFE_STATIC std::unique_ptr a;
+_LIBCPP_SAFE_STATIC std::unique_ptr b(nullptr);
+
+int main() {
+// Check that the initialization of 'a' was performed before the initialization of 'tramplea'.
+for (size_t n = 0; n != sizeof(a); ++n)
+  assert(reinterpret_cast(tramplea)[n] == 0xab);
+// Check that the initialization of 'b' was performed before the initialization of 'trampleb'.
+for (size_t n = 0; n != sizeof(b); ++n)
+  assert(reinterpret_cast(trampleb)[n] == 0xab);
+// Put a unique_ptr object back so that the global dtor is valid.
+new (&a) std::unique_ptr;
+new (&b) std::unique_ptr;
+}
Index: include/memory
===
--- include/memory
+++ include/memory
@@ -2053,6 +2053,26 @@
 typedef void element_type;
 };
 
+// Private copy of forward, for use only in this file, which is constexpr even
+// in C++11
+template 
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+_Tp&&
+__forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
+{
+return static_cast<_Tp&&>(__t);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+_Tp&&
+__forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
+{
+static_assert(!is_lvalue_reference<_Tp>::value,
+  "Can not forward an rvalue as an lvalue.");
+return static_cast<_Tp&&>(__t);
+}
+
 template ::type,
  typename remove_cv<_T2>::type>::value,
 bool = is_empty<_T1>::value
@@ -2096,24 +2116,28 @@
 typedef const typename remove_reference<_T1>::type& _T1_const_reference;
 typedef const typename remove_reference<_T2>::type& _T2_const_reference;
 
-_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
-_LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
-: __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
-_LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
-: __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
-_LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
-: __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+__libcpp_compressed_pair_imp() : __first_(), __second_() {}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+explicit __libcpp_compressed_pair_imp(_T1_param __t1)
+: __first_(__forward<_T1_param>(__t1)), __second_() {}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+explicit __libcpp_compressed_pair_imp(_T2_param __t2)
+: __first_(), __second_(__forward<_T2_param>(__t2)) {}
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+__libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
+: __first_(__forward<_T1_param>(__t1)), __second_(__forward<_T2_param>(__t2)) {}
 
 #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
 _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
is_nothrow_copy_constructible<_T2>::value)
 : __first_(__p.first()),
   __second_(__p.second()) {}
 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
 _NOEXCEPT_(is_nothrow_copy_assignable<_T1

Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-09-15 Thread Reid Kleckner via cfe-commits
rnk added a comment.

In https://reviews.llvm.org/D24289#543874, @thakis wrote:

> Works for me if rnk likes it :-)


Yep, looks good.

> (We could bikeshed on if this should be one of the -Wmicrosoft warnings, but 
> the warning can't be both in -Wall and -Wmicrosoft, so let's don't).


I also don't think it's a good fit for -Wmicrosoft, which is usually trying to 
warn you that "hey, this is an MS extension!", and not "hey, your Unix code 
isn't portable to Windows!".


https://reviews.llvm.org/D24289



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


Re: [PATCH] D24289: Add warning when assigning enums to bitfields without an explicit unsigned underlying type

2016-09-15 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

LGTM as well, thank you!


https://reviews.llvm.org/D24289



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


[libcxx] r281641 - [libc++] Avoid include in locale_win32.h

2016-09-15 Thread Shoaib Meenai via cfe-commits
Author: smeenai
Date: Thu Sep 15 13:36:13 2016
New Revision: 281641

URL: http://llvm.org/viewvc/llvm-project?rev=281641&view=rev
Log:
[libc++] Avoid  include in locale_win32.h

When `_LIBCPP_NO_EXCEPTIONS` is defined, we end up with compile errors
when targeting MSVCRT:

* Code includes ``
* `` includes `` in order to get `abort`
* `` includes ``, _before_ the `using ::abort`
* `` includes `locale_win32.h`
* `locale_win32.h` includes ``
* `` includes ``
* `` includes `` references `_VSTD::abort`, which isn't declared

The easiest solution is to make `locale_win32.h` not include ``,
by removing the use of `unique_ptr` and manually restoring the locale
instead.

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

Modified:
libcxx/trunk/include/support/win32/locale_win32.h
libcxx/trunk/src/support/win32/locale_win32.cpp

Modified: libcxx/trunk/include/support/win32/locale_win32.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/support/win32/locale_win32.h?rev=281641&r1=281640&r2=281641&view=diff
==
--- libcxx/trunk/include/support/win32/locale_win32.h (original)
+++ libcxx/trunk/include/support/win32/locale_win32.h Thu Sep 15 13:36:13 2016
@@ -17,7 +17,6 @@ extern "C" unsigned short  __declspec(dl
 #include "support/win32/support.h"
 #include "support/win32/locale_mgmt_win32.h"
 #include 
-#include 
 
 lconv *localeconv_l( locale_t loc );
 size_t mbrlen_l( const char *__restrict s, size_t n,
@@ -34,13 +33,10 @@ size_t wcsnrtombs_l( char *__restrict ds
  size_t nwc, size_t len, mbstate_t *__restrict ps, 
locale_t loc);
 wint_t btowc_l( int c, locale_t loc );
 int wctob_l( wint_t c, locale_t loc );
-typedef _VSTD::remove_pointer::type __locale_struct;
-typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 inline _LIBCPP_ALWAYS_INLINE
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
-  __locale_raii __current( uselocale(__l), uselocale );
-  return MB_CUR_MAX;
+  return ___mb_cur_max_l_func(__l);
 }
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, 
VS2005+

Modified: libcxx/trunk/src/support/win32/locale_win32.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/support/win32/locale_win32.cpp?rev=281641&r1=281640&r2=281641&view=diff
==
--- libcxx/trunk/src/support/win32/locale_win32.cpp (original)
+++ libcxx/trunk/src/support/win32/locale_win32.cpp Thu Sep 15 13:36:13 2016
@@ -10,6 +10,11 @@
 
 #include 
 #include  // va_start, va_end
+#include 
+#include 
+
+typedef _VSTD::remove_pointer::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )


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


Re: [PATCH] D24374: [libc++] Avoid include in locale_win32.h

2016-09-15 Thread Shoaib Meenai via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281641: [libc++] Avoid  include in locale_win32.h 
(authored by smeenai).

Changed prior to commit:
  https://reviews.llvm.org/D24374?vs=70899&id=71530#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24374

Files:
  libcxx/trunk/include/support/win32/locale_win32.h
  libcxx/trunk/src/support/win32/locale_win32.cpp

Index: libcxx/trunk/src/support/win32/locale_win32.cpp
===
--- libcxx/trunk/src/support/win32/locale_win32.cpp
+++ libcxx/trunk/src/support/win32/locale_win32.cpp
@@ -10,6 +10,11 @@
 
 #include 
 #include  // va_start, va_end
+#include 
+#include 
+
+typedef _VSTD::remove_pointer::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
Index: libcxx/trunk/include/support/win32/locale_win32.h
===
--- libcxx/trunk/include/support/win32/locale_win32.h
+++ libcxx/trunk/include/support/win32/locale_win32.h
@@ -17,7 +17,6 @@
 #include "support/win32/support.h"
 #include "support/win32/locale_mgmt_win32.h"
 #include 
-#include 
 
 lconv *localeconv_l( locale_t loc );
 size_t mbrlen_l( const char *__restrict s, size_t n,
@@ -34,13 +33,10 @@
  size_t nwc, size_t len, mbstate_t *__restrict ps, 
locale_t loc);
 wint_t btowc_l( int c, locale_t loc );
 int wctob_l( wint_t c, locale_t loc );
-typedef _VSTD::remove_pointer::type __locale_struct;
-typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 inline _LIBCPP_ALWAYS_INLINE
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
-  __locale_raii __current( uselocale(__l), uselocale );
-  return MB_CUR_MAX;
+  return ___mb_cur_max_l_func(__l);
 }
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, 
VS2005+


Index: libcxx/trunk/src/support/win32/locale_win32.cpp
===
--- libcxx/trunk/src/support/win32/locale_win32.cpp
+++ libcxx/trunk/src/support/win32/locale_win32.cpp
@@ -10,6 +10,11 @@
 
 #include 
 #include  // va_start, va_end
+#include 
+#include 
+
+typedef _VSTD::remove_pointer::type __locale_struct;
+typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 
 // FIXME: base currently unused. Needs manual work to construct the new locale
 locale_t newlocale( int mask, const char * locale, locale_t /*base*/ )
Index: libcxx/trunk/include/support/win32/locale_win32.h
===
--- libcxx/trunk/include/support/win32/locale_win32.h
+++ libcxx/trunk/include/support/win32/locale_win32.h
@@ -17,7 +17,6 @@
 #include "support/win32/support.h"
 #include "support/win32/locale_mgmt_win32.h"
 #include 
-#include 
 
 lconv *localeconv_l( locale_t loc );
 size_t mbrlen_l( const char *__restrict s, size_t n,
@@ -34,13 +33,10 @@
  size_t nwc, size_t len, mbstate_t *__restrict ps, locale_t loc);
 wint_t btowc_l( int c, locale_t loc );
 int wctob_l( wint_t c, locale_t loc );
-typedef _VSTD::remove_pointer::type __locale_struct;
-typedef _VSTD::unique_ptr<__locale_struct, decltype(&uselocale)> __locale_raii;
 inline _LIBCPP_ALWAYS_INLINE
 decltype(MB_CUR_MAX) MB_CUR_MAX_L( locale_t __l )
 {
-  __locale_raii __current( uselocale(__l), uselocale );
-  return MB_CUR_MAX;
+  return ___mb_cur_max_l_func(__l);
 }
 
 // the *_l functions are prefixed on Windows, only available for msvcr80+, VS2005+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24599: Add 'inline' but not _LIBCPP_INLINE_VISIBILITY to basic_string's destructor

2016-09-15 Thread Aditya Kumar via cfe-commits
hiraditya added a comment.

@EricWF, since inline is only a hint, the compiler would not inline in many 
cases, it might give the inliner a little bit of push to inline. When we were 
working on this patch, adding inline wasn't enough and hence we added the 
_LIBCPP_INLINE_VISIBILITY flag. The compiler crash seems to be in the Verifier 
which does not allow aliases to available_externally functions.


https://reviews.llvm.org/D24599



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


Re: [PATCH] D21803: [libcxxabi] Provide a fallback __cxa_thread_atexit() implementation

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

LGTM. Thanks for the patch.



Comment at: src/cxa_thread_atexit.cpp:70
@@ +69,3 @@
+
+  void run_dtors(void*) {
+while (auto head = dtors) {

Na I thought I was solving a bug that didn't exist. You give me too much credit.


https://reviews.llvm.org/D21803



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


Re: [PATCH] D24599: Add 'inline' but not _LIBCPP_INLINE_VISIBILITY to basic_string's destructor

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

In https://reviews.llvm.org/D24599#543849, @mclow.lists wrote:

> Any reason we shouldn't just revert r280944, wait for the LLVM bug to be 
> fixed, and then re-apply it?


I would like to put some time between fixing the Clang bug and re-introducing 
the reproducer into libc++.
Like it would be nice if 3.9 + libc++ still self hosted. I already reverted 
r280944 and I think we should put it
back eventually, but maybe not right after it's fixed.

In https://reviews.llvm.org/D24599#543917, @hiraditya wrote:

> @EricWF, since inline is only a hint, the compiler would not inline in many 
> cases, it might give the inliner a little bit of push to inline. When we were 
> working on this patch, adding inline wasn't enough and hence we added the 
> _LIBCPP_INLINE_VISIBILITY flag. The compiler crash seems to be in the 
> Verifier which does not allow aliases to available_externally functions.


I'm aware. As I mentioned in the summary Clang only listens to `inline` at -O2 
or greater. However without `inline` it won't even get inlined then. This is 
more of a bandage than your complete solution.


https://reviews.llvm.org/D24599



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


Re: [PATCH] D24467: Fix an error after D21678

2016-09-15 Thread Akira Hatanaka via cfe-commits
ahatanak added a comment.

LGTM with a nit in test case.



Comment at: llvm/tools/clang/test/CodeGen/vecshift.c:43
@@ +42,3 @@
+  vi8 = 1 << vi8;
+// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* @vi8, align 32
+// CHECK: shl <8 x i32> , [[t2]]

This test fails on my machine because MaxVectorAlign is 128 (16B) for darwin. 
Maybe you can remove the alignment checks or add a triple to the RUN line?


https://reviews.llvm.org/D24467



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


r281648 - clang-format VS plugin: upgrade the project files to VS2015

2016-09-15 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Sep 15 14:44:49 2016
New Revision: 281648

URL: http://llvm.org/viewvc/llvm-project?rev=281648&view=rev
Log:
clang-format VS plugin: upgrade the project files to VS2015

The plugin itself runs on previous VS versions, but this enables
it to be built with VS2015.

Modified:
cfe/trunk/tools/clang-format-vs/ClangFormat.sln
cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj
cfe/trunk/tools/clang-format-vs/ClangFormat/Resources.Designer.cs

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat.sln
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat.sln?rev=281648&r1=281647&r2=281648&view=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat.sln (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat.sln Thu Sep 15 14:44:49 2016
@@ -1,6 +1,8 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClangFormat", 
"ClangFormat\ClangFormat.csproj", "{7FD1783E-2D31-4D05-BF23-6EBE1B42B608}"
 EndProject
 Global

Modified: cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj?rev=281648&r1=281647&r2=281648&view=diff
==
--- cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj (original)
+++ cfe/trunk/tools/clang-format-vs/ClangFormat/ClangFormat.csproj Thu Sep 15 
14:44:49 2016
@@ -14,7 +14,7 @@
 true
 Key.snk
 v4.0
-12.0
+14.0
 
 
 
@@ -219,7 +219,7 @@
   
   
   
-if not exist $(ProjectDir)Key.snk 
("$(FrameworkSDKDir)Bin\NETFX 4.5.1 Tools\sn.exe" -k 
$(ProjectDir)Key.snk)
+if not exist $(ProjectDir)Key.snk 
("$(FrameworkSDKDir)Bin\NETFX 4.6 Tools\sn.exe" -k 
$(ProjectDir)Key.snk)
   
   

Re: [PATCH] D24467: Fix an error after D21678

2016-09-15 Thread Vladimir Yakovlev via cfe-commits
vbyakovlcl added inline comments.


Comment at: llvm/tools/clang/test/CodeGen/vecshift.c:43
@@ +42,3 @@
+  vi8 = 1 << vi8;
+// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* @vi8, align 32
+// CHECK: shl <8 x i32> , [[t2]]

ahatanak wrote:
> This test fails on my machine because MaxVectorAlign is 128 (16B) for darwin. 
> Maybe you can remove the alignment checks or add a triple to the RUN line?
Done


https://reviews.llvm.org/D24467



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


Re: [PATCH] D24467: Fix an error after D21678

2016-09-15 Thread Vladimir Yakovlev via cfe-commits
vbyakovlcl updated this revision to Diff 71545.

https://reviews.llvm.org/D24467

Files:
  llvm/tools/clang/lib/Sema/SemaExpr.cpp
  llvm/tools/clang/test/CodeGen/vecshift.c
  llvm/tools/clang/test/Sema/vecshift.c

Index: llvm/tools/clang/lib/Sema/SemaExpr.cpp
===
--- llvm/tools/clang/lib/Sema/SemaExpr.cpp
+++ llvm/tools/clang/lib/Sema/SemaExpr.cpp
@@ -8721,7 +8721,8 @@
 static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS,
  SourceLocation Loc, bool IsCompAssign) {
   // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector.
-  if (!LHS.get()->getType()->isVectorType()) {
+  if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) &&
+  !LHS.get()->getType()->isVectorType()) {
 S.Diag(Loc, diag::err_shift_rhs_only_vector)
   << RHS.get()->getType() << LHS.get()->getType()
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
@@ -8737,15 +8738,17 @@
   if (RHS.isInvalid()) return QualType();
 
   QualType LHSType = LHS.get()->getType();
-  const VectorType *LHSVecTy = LHSType->castAs();
-  QualType LHSEleType = LHSVecTy->getElementType();
+  // Note that LHS might be a scalar because the routine calls not only in
+  // OpenCL case.
+  const VectorType *LHSVecTy = LHSType->getAs();
+  QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType;
 
   // Note that RHS might not be a vector.
   QualType RHSType = RHS.get()->getType();
   const VectorType *RHSVecTy = RHSType->getAs();
   QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType;
 
-  // OpenCL v1.1 s6.3.j says that the operands need to be integers.
+  // The operands need to be integers.
   if (!LHSEleType->isIntegerType()) {
 S.Diag(Loc, diag::err_typecheck_expect_int)
   << LHS.get()->getType() << LHS.get()->getSourceRange();
@@ -8758,7 +8761,19 @@
 return QualType();
   }
 
-  if (RHSVecTy) {
+  if (!LHSVecTy) {
+assert(RHSVecTy);
+if (IsCompAssign)
+  return RHSType;
+if (LHSEleType != RHSEleType) {
+  LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast);
+  LHSEleType = RHSEleType;
+}
+QualType VecTy =
+S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements());
+LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat);
+LHSType = VecTy;
+  } else if (RHSVecTy) {
 // OpenCL v1.1 s6.3.j says that for vector types, the operators
 // are applied component-wise. So if RHS is a vector, then ensure
 // that the number of elements is the same as LHS...
Index: llvm/tools/clang/test/CodeGen/vecshift.c
===
--- llvm/tools/clang/test/CodeGen/vecshift.c
+++ llvm/tools/clang/test/CodeGen/vecshift.c
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
+typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
+typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
+typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
+typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
+typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+
+char c;
+short s;
+int i;
+unsigned char uc;
+unsigned short us;
+unsigned int ui;
+vector_char8 vc8;
+vector_short8 vs8;
+vector_int8 vi8;
+vector_uchar8 vuc8;
+vector_ushort8 vus8;
+vector_uint8 vui8;
+vector_char4 vc4;
+vector_short4 vs4;
+vector_int4 vi4;
+vector_uchar4 vuc4;
+vector_ushort4 vus4;
+vector_uint4 vui4;
+
+void foo() {
+  vc8 = 1 << vc8;
+// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> , [[t0]]
+  vuc8 = 1 << vuc8;
+// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> , [[t1]]
+  vi8 = 1 << vi8;
+// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> , [[t2]]
+  vui8 = 1 << vui8;
+// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> , [[t3]]
+  vs8 = 1 << vs8;
+// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: shl <8 x i16> , [[t4]]
+  vus8 = 1 << vus8;
+// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: shl <8 x i16> , [[t5]]
+
+  vc8 = c << vc8;
+// CHECK: [[t6:%.+]] = load i8, i8* @c,
+// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0
+// CHECK: [[splat_splat:%.+]] = shufflevector <8 x i8> 

Re: [cfe-dev] [Static Analyzer] Retain count checker does not warn about parameters that might leak

2016-09-15 Thread Devin Coughlin via cfe-commits
- cfe-dev, + cfe-commits

Hi Tobias,

This is a great start. Thanks for the patch!

> Not sure I know how to use the analyzer config flags yet. My patch
> currently also still causes a segfault on Analysis/retain-release.m

The segfault is because the diagnostics machinery expects a declaration with 
body for the uniquing declaration (See below).

> and
> changes a test case, where I am not sure it should.
> 
> I probably need some time to get this tested and get more confidence in
> what it is doing. I will then put it up for review and we can see how to
> add an analyzer-config flag.


You can take a look at the MallocChecker and the malloc-annotations.c test to 
see how analyzer-config flags work.

Also, in the future, it is probably best to submit patches on Phabricator: 
> This makes it easier for 
multiple people to comment on the same patch.

> On Sep 8, 2016, at 2:15 AM, Tobias Grosser  wrote:
> 
> And here a slightly more cleaned up version of my patch, just for
> reference.
> 
> Best,
> Tobias
> <0001-RetainCountChecker-Also-check-function-parameters-fo.patch>

> From 19654ebf904c11e3fa5d7f8c938d4a0bb863fbf0 Mon Sep 17 00:00:00 2001
> From: Tobias Grosser 
> Date: Thu, 8 Sep 2016 09:38:36 +0200
> Subject: [PATCH] RetainCountChecker: Also check function parameters for leaks
> 
> ---
>  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 87 
> +++---
>  test/Analysis/retain-release-function-parameters.m | 26 +++
>  test/Analysis/retain-release-gc-only.m |  2 +-
>  3 files changed, 105 insertions(+), 10 deletions(-)
>  create mode 100644 test/Analysis/retain-release-function-parameters.m
> 
> diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp 
> b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
> index d445e91..71035a0 100644
> --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
> +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
> @@ -1823,6 +1823,13 @@ namespace {
>  
>class CFRefLeakReport : public CFRefReport {
>  const MemRegion* AllocBinding;
> +const Stmt *AllocStmt;

It looks like neither of these instance variables are referred to after object 
construction. Do they really need to be ivars?

> +
> +void deriveParamLocation(CheckerContext &Ctx, SymbolRef sym);
> +void deriveAllocLocation(CheckerContext &Ctx, SymbolRef sym);
> +void createDescription(CheckerContext &Ctx,
> +   bool GCEnabled, bool IncludeAllocationLine);
> +
>public:
>  CFRefLeakReport(CFRefBug &D, const LangOptions &LOpts, bool GCEnabled,
>  const SummaryLogTy &Log, ExplodedNode *n, SymbolRef sym,
> @@ -2388,13 +2395,25 @@ CFRefLeakReportVisitor::getEndPath(BugReporterContext 
> &BRC,
>return llvm::make_unique(L, os.str());
>  }
>  
> -CFRefLeakReport::CFRefLeakReport(CFRefBug &D, const LangOptions &LOpts,
> - bool GCEnabled, const SummaryLogTy &Log,
> - ExplodedNode *n, SymbolRef sym,
> - CheckerContext &Ctx,
> - bool IncludeAllocationLine)
> -  : CFRefReport(D, LOpts, GCEnabled, Log, n, sym, false) {
> +void CFRefLeakReport::deriveParamLocation(CheckerContext &Ctx, SymbolRef 
> sym) {
> +  const SourceManager& SMgr = Ctx.getSourceManager();
> +
> +  if (!sym->getOriginRegion())
> +return;
>  

Some style notes: In LLVM style we typically use ‘auto *’ for pointers to make 
it clear there is not an
expensive copy. For example: 'auto *PDecl = …’

We also try to avoided nested indentation where possible. So, for example:
  if (!Region)
return;

> +  auto Region = dyn_cast(sym->getOriginRegion());
> +  if (Region) {
> +auto PDecl = Region->getDecl();
> +if (PDecl && isa(PDecl)) {

I think it is worth adding a comment here explaining that the location
of the leak is the location of the parameter annotated as consumed.

> +  auto ParamLocation = PathDiagnosticLocation::create(PDecl, SMgr);
> +  Location = ParamLocation;
> +  UniqueingLocation = ParamLocation;
> +  UniqueingDecl = PDecl;

Rather than using PDecl here, you can use the declaration for the containing 
function:
UniqueingDecl = Ctx.getLocationContext()->getDecl();

This will avoid the crash when flushing diagnostics.

> +}
> +  }
> +}
> +
> +void CFRefLeakReport::deriveAllocLocation(CheckerContext &Ctx,SymbolRef sym) 
> {
>// Most bug reports are cached at the location where they occurred.
>// With leaks, we want to unique them by the location where they were
>// allocated, and only report a single path.  To do this, we need to find
> @@ -2418,8 +2437,12 @@ CFRefLeakReport::CFRefLeakReport(CFRefBug &D, const 
> LangOptions &LOpts,
>// FIXME: This will crash the analyzer if an allocation comes from an
>// implicit call (ex: a destructor call).
>// (Currently there are no such allocations

[PATCH] D24626: [OpenCL] Diagnose assignment to dereference of half type pointer

2016-09-15 Thread Yaxun Liu via cfe-commits
yaxunl created this revision.
yaxunl added reviewers: Anastasia, bader.
yaxunl added subscribers: cfe-commits, nhaustov, rampitec.
Herald added a subscriber: yaxunl.

https://reviews.llvm.org/D24626

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/half.cl

Index: test/SemaOpenCL/half.cl
===
--- test/SemaOpenCL/half.cl
+++ test/SemaOpenCL/half.cl
@@ -8,8 +8,10 @@
 {
   half a[2]; // expected-error{{declaring variable of type 'half [2]' is not 
allowed}}
   half b;// expected-error{{declaring variable of type 'half' is not 
allowed}}
-  *p; // expected-error{{loading directly from pointer to type 'half' is not 
allowed}}
-  p[1]; // expected-error{{loading directly from pointer to type 'half' is not 
allowed}}
+  *p; // expected-error{{loading directly from pointer to type 'half' requires 
cl_khr_fp16. Use vector data load builtin functions instead}}
+  *p = 0; // expected-error{{assigning directly to pointer to type 'half' 
requires cl_khr_fp16. Use vector data store builtin functions instead}}
+  p[1]; // expected-error{{loading directly from pointer to type 'half' 
requires cl_khr_fp16. Use vector data load builtin functions instead}}
+  p[1] = 0; // expected-error{{assigning directly to pointer to type 'half' 
requires cl_khr_fp16. Use vector data store builtin functions instead}}
 
   float c = 1.0f;
   b = (half) c;  // expected-error{{casting to type 'half' is not allowed}}
@@ -31,7 +33,9 @@
   half a[2];
   half b;
   *p;
+  *p = 0;
   p[1];
+  p[1] = 0;
 
   float c = 1.0f;
   b = (half) c;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10085,6 +10085,16 @@
   QualType LHSType = LHSExpr->getType();
   QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() :
  CompoundType;
+  // OpenCL v1.2 s6.1.1.1 p2:
+  // The half data type can only be used to declare a pointer to a buffer that
+  // contains half values
+  if (getLangOpts().OpenCL && !getOpenCLOptions().cl_khr_fp16 &&
+LHSType->isHalfType()) {
+Diag(Loc, diag::err_opencl_half_load_store) << 1
+<< LHSType.getUnqualifiedType();
+return QualType();
+  }
+
   AssignConvertType ConvTy;
   if (CompoundType.isNull()) {
 Expr *RHSCheck = RHS.get();
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -659,7 +659,8 @@
 def err_parameters_retval_cannot_have_fp16_type : Error<
   "%select{parameters|function return value}0 cannot have __fp16 type; did you 
forget * ?">;
 def err_opencl_half_load_store : Error<
-  "%select{loading directly from|assigning directly to}0 pointer to type %1 is 
not allowed">;
+  "%select{loading directly from|assigning directly to}0 pointer to type %1 
requires "
+  "cl_khr_fp16. Use vector data %select{load|store}0 builtin functions 
instead">;
 def err_opencl_cast_to_half : Error<"casting to type %0 is not allowed">;
 def err_opencl_half_declaration : Error<
   "declaring variable of type %0 is not allowed">;


Index: test/SemaOpenCL/half.cl
===
--- test/SemaOpenCL/half.cl
+++ test/SemaOpenCL/half.cl
@@ -8,8 +8,10 @@
 {
   half a[2]; // expected-error{{declaring variable of type 'half [2]' is not allowed}}
   half b;// expected-error{{declaring variable of type 'half' is not allowed}}
-  *p; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
-  p[1]; // expected-error{{loading directly from pointer to type 'half' is not allowed}}
+  *p; // expected-error{{loading directly from pointer to type 'half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
+  *p = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
+  p[1]; // expected-error{{loading directly from pointer to type 'half' requires cl_khr_fp16. Use vector data load builtin functions instead}}
+  p[1] = 0; // expected-error{{assigning directly to pointer to type 'half' requires cl_khr_fp16. Use vector data store builtin functions instead}}
 
   float c = 1.0f;
   b = (half) c;  // expected-error{{casting to type 'half' is not allowed}}
@@ -31,7 +33,9 @@
   half a[2];
   half b;
   *p;
+  *p = 0;
   p[1];
+  p[1] = 0;
 
   float c = 1.0f;
   b = (half) c;
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -10085,6 +10085,16 @@
   QualType LHSType = LHSExpr->getType();
   QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() :
  CompoundType;
+  // OpenCL v1.2 s6.

[PATCH] D24628: [ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber

2016-09-15 Thread Andrii Grynenko via cfe-commits
andriigrynenko created this revision.
andriigrynenko added reviewers: kcc, blastrock, dvyukov, filcab.
andriigrynenko added a subscriber: cfe-commits.
andriigrynenko set the repository for this revision to rL LLVM.
Herald added a subscriber: kubabrecka.

This patch extends __sanitizer_finish_switch_fiber method to optionally return 
previous stack base and size. 

This solves the problem of coroutines/fibers library not knowing the original 
stack context from which the library is used. It's incorrect to assume that 
such context is always the default stack of current thread (e.g. one such 
library may be used from a fiber/coroutine created by another library). Bulding 
a separate stack tracking mechanism would not only duplicate AsanThread, but 
also require each coroutines/fibers library to integrate with it.

Repository:
  rL LLVM

https://reviews.llvm.org/D24628

Files:
  compiler-rt/include/sanitizer/common_interface_defs.h
  compiler-rt/lib/asan/asan_thread.cc
  compiler-rt/lib/asan/asan_thread.h

Index: compiler-rt/lib/asan/asan_thread.h
===
--- compiler-rt/lib/asan/asan_thread.h
+++ compiler-rt/lib/asan/asan_thread.h
@@ -94,7 +94,8 @@
   }
 
   void StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom, uptr size);
-  void FinishSwitchFiber(FakeStack *fake_stack_save);
+  void FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
+ uptr *size_old);
 
   bool has_fake_stack() {
 return !atomic_load(&stack_switching_, memory_order_relaxed) &&
Index: compiler-rt/lib/asan/asan_thread.cc
===
--- compiler-rt/lib/asan/asan_thread.cc
+++ compiler-rt/lib/asan/asan_thread.cc
@@ -141,7 +141,9 @@
 current_fake_stack->Destroy(this->tid());
 }
 
-void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save) {
+void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save,
+   uptr *bottom_old,
+   uptr *size_old) {
   if (!atomic_load(&stack_switching_, memory_order_relaxed)) {
 Report("ERROR: finishing a fiber switch that has not started\n");
 Die();
@@ -152,6 +154,12 @@
 fake_stack_ = fake_stack_save;
   }
 
+  if (bottom_old) {
+*bottom_old = stack_bottom_;
+  }
+  if (size_old) {
+*size_old = stack_top_ - stack_bottom_;
+  }
   stack_bottom_ = next_stack_bottom_;
   stack_top_ = next_stack_top_;
   atomic_store(&stack_switching_, 0, memory_order_release);
@@ -447,12 +455,16 @@
 }
 
 SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_finish_switch_fiber(void* fakestack) {
+void __sanitizer_finish_switch_fiber(void* fakestack,
+ const void **bottom_old,
+ uptr *size_old) {
   AsanThread *t = GetCurrentThread();
   if (!t) {
 VReport(1, "__asan_finish_switch_fiber called from unknown thread\n");
 return;
   }
-  t->FinishSwitchFiber((FakeStack*)fakestack);
+  t->FinishSwitchFiber((FakeStack*)fakestack,
+   (uptr*)bottom_old,
+   (uptr*)size_old);
 }
 }
Index: compiler-rt/include/sanitizer/common_interface_defs.h
===
--- compiler-rt/include/sanitizer/common_interface_defs.h
+++ compiler-rt/include/sanitizer/common_interface_defs.h
@@ -169,7 +169,9 @@
   // use-after-return detection.
   void __sanitizer_start_switch_fiber(void **fake_stack_save,
   const void *bottom, size_t size);
-  void __sanitizer_finish_switch_fiber(void *fake_stack_save);
+  void __sanitizer_finish_switch_fiber(void *fake_stack_save,
+   const void **bottom_old,
+   size_t *size_old);
 #ifdef __cplusplus
 }  // extern "C"
 #endif


Index: compiler-rt/lib/asan/asan_thread.h
===
--- compiler-rt/lib/asan/asan_thread.h
+++ compiler-rt/lib/asan/asan_thread.h
@@ -94,7 +94,8 @@
   }
 
   void StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom, uptr size);
-  void FinishSwitchFiber(FakeStack *fake_stack_save);
+  void FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
+ uptr *size_old);
 
   bool has_fake_stack() {
 return !atomic_load(&stack_switching_, memory_order_relaxed) &&
Index: compiler-rt/lib/asan/asan_thread.cc
===
--- compiler-rt/lib/asan/asan_thread.cc
+++ compiler-rt/lib/asan/asan_thread.cc
@@ -141,7 +141,9 @@
 current_fake_stack->Destroy(this->tid());
 }
 
-void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save) {
+void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save,
+   uptr *bottom_old,
+   uptr *size_old) {
   if (!atomic_load(&stack_swi

Re: [PATCH] D24507: Add attribute for return values that shouldn't be cast to bool

2016-09-15 Thread Aaron Ballman via cfe-commits
aaron.ballman added a comment.

Thank you for working on this check! A few comments:

The patch is missing Sema tests for the attribute (that it only applies to 
declarations you expect, accepts no args, etc).

Have you considered making this a type attribute on the return type of the 
function rather than a declaration attribute on the function declaration? Right 
now, the diagnostic you receive on a conversion may be spatially separated from 
where the user called the function (including crossing translation unit 
boundaries, which the static analyzer doesn't currently handle). By putting the 
attribute on the type, it carries more obvious semantic meaning and means the 
check can happen entirely in the frontend (no static analyzer required). For 
instance: `typedef __attribute__((warn_impcast_to_bool)) IntNotABool;` I'm not 
certain if this is a better design or not, but I am wondering if it was 
something you had considered.



Comment at: include/clang/Basic/Attr.td:1138
@@ +1137,3 @@
+def WarnImpcastToBool : InheritableAttr {
+  let Spellings = [GCC<"warn_impcast_to_bool">];
+  let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,

This should not use a GCC spelling because it's not an attribute that GCC 
supports. You should probably use GNU instead, since I suspect this attribute 
will be useful in C as well as C++.


Comment at: include/clang/Basic/Attr.td:1140
@@ +1139,3 @@
+  let Subjects = SubjectList<[ObjCMethod, Function], WarnDiag,
+ "ExpectedFunctionOrMethod">;
+  let Documentation = [WarnImpcastToBoolDocs];

No need to specify the WarnDiag or ExpectedFunctionOrMethod arguments; they 
will be handled automatically.


Comment at: include/clang/Basic/AttrDocs.td:2058
@@ +2057,3 @@
+  let Content = [{
+The ``warn_impcast_to_bool`` attribute is used to indicate that the return 
value of a function with integral return type cannot be used as a boolean 
value. For example, if a function returns -1 if it couldn't efficiently read 
the data, 0 if the data is invalid and 1 for success, it might be dangerous to 
implicitly cast the return value to bool, e.g. to indicate success. Therefore, 
it is a good idea to trigger a warning about such cases. However, in case a 
programmer uses an explicit cast to bool, that probably means that he knows 
what he is doing, therefore a warning should be triggered only for implicit 
casts.
+

You should manually wrap this to roughly the 80 col limit.

Instead of "he", can you use "they" please?


Comment at: include/clang/Basic/DiagnosticGroups.td:57
@@ -56,2 +56,3 @@
 def DoublePromotion : DiagGroup<"double-promotion">;
+def UnsafeBoolConversion : DiagGroup<"unsafe-bool-conversion">;
 def EnumTooLarge : DiagGroup<"enum-too-large">;

I'm not certain this requires its own diagnostic group. This can probably be 
handled under `BoolConversion`


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2259
@@ +2258,3 @@
+def warn_attribute_return_int_only : Warning<
+  "%0 attribute only applies to return values that are integers">,
+  InGroup;

How about: ...only applies to integer return types?


Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2883
@@ +2882,3 @@
+  "implicit conversion turns non-bool into bool: %0 to %1">,
+  InGroup, DefaultIgnore;
+

I don't think this should be a DefaultIgnore diagnostic -- if the user wrote 
the attribute, they should get the diagnostic when appropriate.


Comment at: lib/Sema/SemaChecking.cpp:8262
@@ +8261,3 @@
+/// e.g. (x ? f : g)(y)
+if (isa(E)) {
+  FunctionDecl* fn = cast(E)->getDirectCallee();

Should use `if (const auto *CE = dyn_cast(E)) {`


Comment at: lib/Sema/SemaChecking.cpp:8263-8264
@@ +8262,4 @@
+if (isa(E)) {
+  FunctionDecl* fn = cast(E)->getDirectCallee();
+  if (!fn)
+return;

Then you can do `if (const auto *Fn = CE->getDirectCallee()) {`


Comment at: lib/Sema/SemaChecking.cpp:8269
@@ +8268,3 @@
+S.Diag(fn->getLocation(), diag::note_entity_declared_at)
+<< fn->getDeclName();
+return;

You can pass in `fn` directly, the diagnostics engine will properly get the 
name out of it because it's derived from `NamedDecl`.


Comment at: lib/Sema/SemaDeclAttr.cpp:1316
@@ +1315,3 @@
+S.Diag(Attr.getLoc(), diag::warn_attribute_return_int_only)
+  

Re: [PATCH] D24628: [ASAN] Pass previous stack information through __sanitizer_finish_switch_fiber

2016-09-15 Thread Philippe Daouadi via cfe-commits
blastrock added a comment.

Seems fine to me, but I think you forgot to update the tests :)


Repository:
  rL LLVM

https://reviews.llvm.org/D24628



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


Re: [PATCH] D24513: [AMDGPU] Expose flat work group size, register and wave control attributes

2016-09-15 Thread Aaron Ballman via cfe-commits
aaron.ballman added inline comments.


Comment at: lib/Sema/SemaDeclAttr.cpp:4967
@@ +4966,3 @@
+
+  D->addAttr(::new (S.Context)
+ AMDGPUFlatWorkGroupSizeAttr(Attr.getLoc(), S.Context, Min, Max,

Is it okay to supply `0, 0` as the min, max arguments?


Comment at: lib/Sema/SemaDeclAttr.cpp:4997
@@ +4996,3 @@
+
+  D->addAttr(::new (S.Context)
+ AMDGPUWavesPerEUAttr(Attr.getLoc(), S.Context, Min, Max,

Is it okay to supply `0, 0` as the min, max arguments?


Comment at: lib/Sema/SemaDeclAttr.cpp:6039-6043
@@ -5976,3 +6038,7 @@
   D->setInvalidDecl();
-} else if (Attr *A = D->getAttr()) {
+} else if (Attr *A = D->getAttr()) {
+  Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
+<< A << ExpectedKernelFunction;
+  D->setInvalidDecl();
+} else if (Attr *A = D->getAttr()) {
   Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)

Yes, totally fine to be a follow-up patch. I was hoping it would look something 
like (we can bikeshed the name):
```
def SomeAttr {
  /* Blah */
}

def SomeOtherAttr {
  let RequiredCompanionAttributes = [SomeAttr];
}
```


https://reviews.llvm.org/D24513



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


Re: [PATCH] D24372: [libcxx] Sprinkle constexpr over compressed_pair

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF added a comment.

Thanks for working on this. That static initialization bug is ugly.

My only concern with this patch is that adding `constexpr` to unconstrained 
constructors is going to result compile errors caused by Clang's eager 
instantiation.

Also, unlike @mclow.lists, I think we should make `std::forward` and 
`std::move` constexpr in C++11 as an extension. libstdc++ does it so it should 
be safe. I'm working on a patch that adds this extension now.

More comments to come shortly.



Comment at: include/memory:2056
@@ -2055,1 +2055,3 @@
 
+// Private copy of forward, for use only in this file, which is constexpr even
+// in C++11

I would put this right next to `std::forward`.


Comment at: include/memory:2531
@@ -2491,3 +2530,3 @@
 
-_LIBCPP_INLINE_VISIBILITY
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __compressed_pair& operator=(__compressed_pair&& __p)

The body of this function is only constexpr in C++14 because it contains two 
statements.

`return base::operator=(static_cast<__compressed_pair&&>(__p)), *this` is a 
constant expression in C++11 though.


Comment at: include/memory:2546
@@ -2507,2 +2545,3 @@
+_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
 __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> 
__first_args,
   tuple<_Args2...> 
__second_args)

This isn't a constant expression until C++14, since both `tuple` and `move` are 
only constexpr in C++14.

(Although I guess two default constructed tuple's would be constexpr in C++11).


Comment at: 
test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp:1
@@ +1,2 @@
+//===--===//
+//

This test should live under 
`test/std/utilities/memory/unique.ptr/unique.ptr.single/unique.ptr.single.ctor` 
since `unique.ptr.runtime` is for unique_ptr's of arrays (e.g. 
`unique_ptr`). Adding a separate version of this test for unique_ptr 
would also be appreciated.


Comment at: 
test/std/utilities/memory/unique.ptr/unique.ptr.runtime/unique.ptr.runtime.ctor/constinit.pass.cpp:20
@@ +19,3 @@
+extern std::unique_ptr a;
+extern std::unique_ptr b;
+void *tramplea = std::memset(&a, 0xab, sizeof(a));

Could this add a test case for a unique_ptr with a non-empty deleter? That will 
test an entirely different specialization of `__compressed_pair`.



Repository:
  rL LLVM

https://reviews.llvm.org/D24372



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


Re: [PATCH] D23765: Fix for clang PR 29087

2016-09-15 Thread Taewook Oh via cfe-commits
twoh updated this revision to Diff 71560.
twoh added a comment.

Tests added


https://reviews.llvm.org/D23765

Files:
  lib/Sema/SemaExprCXX.cpp
  test/SemaCXX/crash-has-nothrow-constructor.cpp
  test/SemaCXX/crash-has-nothrow-copy.cpp

Index: test/SemaCXX/crash-has-nothrow-copy.cpp
===
--- test/SemaCXX/crash-has-nothrow-copy.cpp
+++ test/SemaCXX/crash-has-nothrow-copy.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
+
+#define assert(x) if (x) {}
+
+struct X {
+  X(const X &x) {}
+};
+
+struct Y : public X {
+public:
+  using X::X;
+};
+
+int main() {
+  assert(__has_nothrow_copy(Y));
+}
Index: test/SemaCXX/crash-has-nothrow-constructor.cpp
===
--- test/SemaCXX/crash-has-nothrow-constructor.cpp
+++ test/SemaCXX/crash-has-nothrow-constructor.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
+
+#define assert(x) if (x) {}
+
+struct X {
+  X() {}
+};
+
+struct Y : public X {
+public:
+  using X::X;
+};
+
+int main() {
+  assert(__has_nothrow_constructor(Y));
+}
Index: lib/Sema/SemaExprCXX.cpp
===
--- lib/Sema/SemaExprCXX.cpp
+++ lib/Sema/SemaExprCXX.cpp
@@ -292,7 +292,7 @@
   if (isDependent) {
 // We didn't find our type, but that's okay: it's dependent
 // anyway.
-
+
 // FIXME: What if we have no nested-name-specifier?
 QualType T = CheckTypenameType(ETK_None, SourceLocation(),
SS.getWithLocInContext(Context),
@@ -326,14 +326,14 @@
 ParsedType Sema::getDestructorType(const DeclSpec& DS, ParsedType ObjectType) {
 if (DS.getTypeSpecType() == DeclSpec::TST_error || !ObjectType)
   return nullptr;
-assert(DS.getTypeSpecType() == DeclSpec::TST_decltype 
+assert(DS.getTypeSpecType() == DeclSpec::TST_decltype
&& "only get destructor types from declspecs");
 QualType T = BuildDecltypeType(DS.getRepAsExpr(), DS.getTypeSpecTypeLoc());
 QualType SearchType = GetTypeFromParser(ObjectType);
 if (SearchType->isDependentType() || Context.hasSameUnqualifiedType(SearchType, T)) {
   return ParsedType::make(T);
 }
-  
+
 Diag(DS.getTypeSpecTypeLoc(), diag::err_destructor_expr_type_mismatch)
   << T << SearchType;
 return nullptr;
@@ -662,7 +662,7 @@
   IsThrownVarInScope = true;
   break;
 }
-
+
 if (S->getFlags() &
 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
  Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
@@ -672,11 +672,11 @@
 }
   }
   }
-  
+
   return BuildCXXThrow(OpLoc, Ex, IsThrownVarInScope);
 }
 
-ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, 
+ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr *Ex,
bool IsThrownVarInScope) {
   // Don't report an error if 'throw' is used in system headers.
   if (!getLangOpts().CXXExceptions &&
@@ -903,10 +903,10 @@
I-- && isa(FunctionScopes[I]);
CurDC = getLambdaAwareParentOfDeclContext(CurDC)) {
 CurLSI = cast(FunctionScopes[I]);
-
-if (!CurLSI->isCXXThisCaptured()) 
+
+if (!CurLSI->isCXXThisCaptured())
 continue;
-  
+
 auto C = CurLSI->getCXXThisCapture();
 
 if (C.isCopyCapture()) {
@@ -922,7 +922,7 @@
 assert(CurLSI);
 assert(isGenericLambdaCallOperatorSpecialization(CurLSI->CallOperator));
 assert(CurDC == getLambdaAwareParentOfDeclContext(CurLSI->CallOperator));
-
+
 auto IsThisCaptured =
 [](CXXRecordDecl *Closure, bool &IsByCopy, bool &IsConst) {
   IsConst = false;
@@ -992,10 +992,10 @@
   return ThisTy;
 }
 
-Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S, 
+Sema::CXXThisScopeRAII::CXXThisScopeRAII(Sema &S,
  Decl *ContextDecl,
  unsigned CXXThisTypeQuals,
- bool Enabled) 
+ bool Enabled)
   : S(S), OldCXXThisTypeOverride(S.CXXThisTypeOverride), Enabled(false)
 {
   if (!Enabled || !ContextDecl)
@@ -1006,13 +1006,13 @@
 Record = Template->getTemplatedDecl();
   else
 Record = cast(ContextDecl);
-
+
   // We care only for CVR qualifiers here, so cut everything else.
   CXXThisTypeQuals &= Qualifiers::FastMask;
   S.CXXThisTypeOverride
 = S.Context.getPointerType(
 S.Context.getRecordType(Record).withCVRQualifiers(CXXThisTypeQuals));
-  
+
   this->Enabled = true;
 }
 
@@ -1026,7 +1026,7 @@
 static Expr *captureThis(Sema &S, ASTContext &Context, RecordDecl *RD,
  QualType ThisTy, SourceLocation Loc,
  const bool ByCopy) {
- 
+
   QualType AdjustedThisTy = ThisTy;
   // The type of the corresponding data member (not a 'this' point

Re: [PATCH] D18462: Fix for clang_Cursor_getSpellingNameRange()

2016-09-15 Thread Benjamin Kramer via cfe-commits
bkramer accepted this revision.
bkramer added a comment.

looks good from my side.


https://reviews.llvm.org/D18462



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


Re: [PATCH] D23765: Fix for clang PR 29087

2016-09-15 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaExprCXX.cpp:4227
@@ -4226,1 +4226,3 @@
   continue;
+// Using(Shadow)Decl itself is not a constructor
+if (isa(ND) || isa(ND))

This isn't really right: a `UsingShadowDecl` whose underlying declaration is a 
constructor should itself act like a constructor. This could matter in some 
obscure cases:

  struct B;
  struct A { A(B&); };
  struct B : A { using A::A; };

What does `__has_nothrow_copy(B)` return? It should probably be `false`, since 
copying a non-const `B` object will invoke the `A(B&)` constructor, which may 
throw, even though the `B(const B&)` constructor does not.

However, these `__has_*` traits should be considered deprecated and are 
essentially useless, so perhaps it doesn't matter too much whether we get these 
corner cases right. We also get the constructor template case "wrong" here, 
which I would imagine comes up a lot more frequently.


Comment at: test/SemaCXX/crash-has-nothrow-constructor.cpp:1
@@ +1,2 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s
+

Please add these tests into some existing test file for the type traits rather 
than adding two new files.


https://reviews.llvm.org/D23765



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


Re: [PATCH] D23926: [libcxx] Don't use C99 math ops in -std=c++03 mode

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF resigned from this revision.
EricWF removed a reviewer: EricWF.
EricWF added a comment.

After talking with @rmaprath we have agreed to go in a different direction. 
Resigning as reviewer to keep my queue clean.


https://reviews.llvm.org/D23926



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


r281665 - [sanitizer-coverage] make trace-pc-guard and indirect-call work together

2016-09-15 Thread Kostya Serebryany via cfe-commits
Author: kcc
Date: Thu Sep 15 17:11:08 2016
New Revision: 281665

URL: http://llvm.org/viewvc/llvm-project?rev=281665&view=rev
Log:
[sanitizer-coverage] make trace-pc-guard and indirect-call work together

Modified:
cfe/trunk/docs/SanitizerCoverage.rst

Modified: cfe/trunk/docs/SanitizerCoverage.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerCoverage.rst?rev=281665&r1=281664&r2=281665&view=diff
==
--- cfe/trunk/docs/SanitizerCoverage.rst (original)
+++ cfe/trunk/docs/SanitizerCoverage.rst Thu Sep 15 17:11:08 2016
@@ -323,8 +323,8 @@ and can be used with `AFL 

r281666 - Simplify Clang's version number configuration in CMake.

2016-09-15 Thread David L. Jones via cfe-commits
Author: dlj
Date: Thu Sep 15 17:12:26 2016
New Revision: 281666

URL: http://llvm.org/viewvc/llvm-project?rev=281666&view=rev
Log:
Simplify Clang's version number configuration in CMake.

Currently, the Clang version is computed as follows:

 1. LLVM defines major, minor, and patch versions, all statically set. Today,
these are 4, 0, and 0, respectively.
 2. The static version numbers are combined into PACKAGE_VERSION along with a
suffix, so the result today looks like "4.0.0svn".
 3. Clang extracts CLANG_VERSION from PACKAGE_VERSION using a regexp. The regexp
allows the patch level to omitted, and drops any non-digit trailing values.
Today, this result looks like "4.0.0".
 4. CLANG_VERSION is then split further into CLANG_VERSION_MAJOR and
CLANG_VERSION_MINOR. Today, these resolve to 4 and 0, respectively.
 5. If CLANG_VERSION matches a regexp with three version components, then
CLANG_VERSION_PATCHLEVEL is extracted and the CLANG_HAS_VERSION_PATCHLEVEL
variable is set to 1. Today, these values are 0 and 1, respectively.
 6. The CLANG_VERSION_* variables (and CLANG_HAS_VERSION_PATCHLEVEL) are
configured into [llvm/tools/clang/]include/clang/Basic/Version.inc
verbatim by CMake.
 7. In [llvm/tools/clang/]include/clang/Basic/Version.h, macros are defined
conditionally, based on CLANG_HAS_VERSION_PATCHLEVEL, to compute
CLANG_VERSION_STRING as either a two- or three-level version number. Today,
this value is "4.0.0", because despite the patchlevel being 0, it was
matched by regexp and is thus "HAS"ed by the preprocessor. This string is
then used wherever Clang's "version" is needed [*].

[*] Including, notably, by compiler-rt, for computing its installation path.

This change collapses steps 2-5 by defaulting Clang to use LLVM's (non-string)
version components for the Clang version (see [*] for why not PACKAGE_VERSION),
and collapses steps 6 and 7 by simply writing CLANG_VERSION_STRING into
Version.inc. The Clang version today always uses the patchlevel form, so the
collapsed Version.inc does not have logic for a version without a patch level.

Historically speaking, this technique began with the VER file in r82085 (which
survives in the form of the regexp in #3). The major, minor, and patchlevel
versions were introduced by r106863 (which remains in #4-6). The VER file itself
was deleted in favor of the LLVM version number in r106914. On the LLVM side,
the individual LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR, and PACKAGE_VERSION
weren't introduced for nearly two more years, until r150405.

Modified:
cfe/trunk/CMakeLists.txt
cfe/trunk/include/clang/Basic/Version.h
cfe/trunk/include/clang/Basic/Version.inc.in
cfe/trunk/lib/Frontend/InitPreprocessor.cpp

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=281666&r1=281665&r2=281666&view=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Thu Sep 15 17:12:26 2016
@@ -262,22 +262,13 @@ if( NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_
 endif()
 
 # Compute the Clang version from the LLVM version.
-string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION
-  ${PACKAGE_VERSION})
+set(CLANG_VERSION_MAJOR ${LLVM_VERSION_MAJOR})
+set(CLANG_VERSION_MINOR ${LLVM_VERSION_MINOR})
+set(CLANG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH})
+# Unlike PACKAGE_VERSION, CLANG_VERSION does not include LLVM_VERSION_SUFFIX.
+set(CLANG_VERSION 
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}.${CLANG_VERSION_PATCHLEVEL}")
 message(STATUS "Clang version: ${CLANG_VERSION}")
 
-string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" CLANG_VERSION_MAJOR
-  ${CLANG_VERSION})
-string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" CLANG_VERSION_MINOR
-  ${CLANG_VERSION})
-if (${CLANG_VERSION} MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
-  set(CLANG_HAS_VERSION_PATCHLEVEL 1)
-  string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" 
CLANG_VERSION_PATCHLEVEL
-${CLANG_VERSION})
-else()
-  set(CLANG_HAS_VERSION_PATCHLEVEL 0)
-endif()
-
 # Configure the Version.inc file.
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/include/clang/Basic/Version.inc.in

Modified: cfe/trunk/include/clang/Basic/Version.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Version.h?rev=281666&r1=281665&r2=281666&view=diff
==
--- cfe/trunk/include/clang/Basic/Version.h (original)
+++ cfe/trunk/include/clang/Basic/Version.h Thu Sep 15 17:12:26 2016
@@ -19,26 +19,6 @@
 #include "clang/Basic/Version.inc"
 #include "llvm/ADT/StringRef.h"
 
-/// \brief Helper macro for CLANG_VERSION_STRING.
-#define CLANG_MAKE_VERSION_STRING2(X) #X
-
-#ifdef CLANG_VERSION_PATCHLEVEL
-/// \brief Helper macro for CLANG_VERSION_STRING.
-#define CLANG_MAKE_VERSION_STRING(X,Y,Z) CLANG_MAKE_VERSION_STRING2(X.Y.Z)
-
-/// \brief A string 

Re: [PATCH] D24467: Fix an error after D21678

2016-09-15 Thread Akira Hatanaka via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281669: [Sema] Allow shifting a scalar operand by a vector 
operand. (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D24467?vs=71545&id=71569#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24467

Files:
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/test/CodeGen/vecshift.c
  cfe/trunk/test/Sema/vecshift.c

Index: cfe/trunk/test/CodeGen/vecshift.c
===
--- cfe/trunk/test/CodeGen/vecshift.c
+++ cfe/trunk/test/CodeGen/vecshift.c
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
+typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
+typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
+typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
+typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
+typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+
+char c;
+short s;
+int i;
+unsigned char uc;
+unsigned short us;
+unsigned int ui;
+vector_char8 vc8;
+vector_short8 vs8;
+vector_int8 vi8;
+vector_uchar8 vuc8;
+vector_ushort8 vus8;
+vector_uint8 vui8;
+vector_char4 vc4;
+vector_short4 vs4;
+vector_int4 vi4;
+vector_uchar4 vuc4;
+vector_ushort4 vus4;
+vector_uint4 vui4;
+
+void foo() {
+  vc8 = 1 << vc8;
+// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> , [[t0]]
+  vuc8 = 1 << vuc8;
+// CHECK: [[t1:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> , [[t1]]
+  vi8 = 1 << vi8;
+// CHECK: [[t2:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> , [[t2]]
+  vui8 = 1 << vui8;
+// CHECK: [[t3:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> , [[t3]]
+  vs8 = 1 << vs8;
+// CHECK: [[t4:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: shl <8 x i16> , [[t4]]
+  vus8 = 1 << vus8;
+// CHECK: [[t5:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: shl <8 x i16> , [[t5]]
+
+  vc8 = c << vc8;
+// CHECK: [[t6:%.+]] = load i8, i8* @c,
+// CHECK: [[splat_splatinsert:%.+]] = insertelement <8 x i8> undef, i8 [[t6]], i32 0
+// CHECK: [[splat_splat:%.+]] = shufflevector <8 x i8> [[splat_splatinsert]], <8 x i8> undef, <8 x i32> zeroinitializer
+// CHECK: [[t7:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> [[splat_splat]], [[t7]]
+  vuc8 = i << vuc8;
+// CHECK: [[t8:%.+]] = load i32, i32* @i,
+// CHECK: [[tconv:%.+]] = trunc i32 [[t8]] to i8
+// CHECK: [[splat_splatinsert7:%.+]] = insertelement <8 x i8> undef, i8 [[tconv]], i32 0
+// CHECK: [[splat_splat8:%.+]] = shufflevector <8 x i8> [[splat_splatinsert7]], <8 x i8> undef, <8 x i32> zeroinitializer
+// CHECK: [[t9:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> [[splat_splat8]], [[t9]]
+  vi8 = uc << vi8;
+// CHECK: [[t10:%.+]] = load i8, i8* @uc,
+// CHECK: [[conv10:%.+]] = zext i8 [[t10]] to i32
+// CHECK: [[splat_splatinsert11:%.+]] = insertelement <8 x i32> undef, i32 [[conv10]], i32 0
+// CHECK: [[splat_splat12:%.+]] = shufflevector <8 x i32> [[splat_splatinsert11]], <8 x i32> undef, <8 x i32> zeroinitializer
+// CHECK: [[t11:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> [[splat_splat12]], [[t11]]
+  vui8 = us << vui8;
+// CHECK: [[t12:%.+]] = load i16, i16* @us,
+// CHECK: [[conv14:%.+]] = zext i16 [[t12]] to i32
+// CHECK: [[splat_splatinsert15:%.+]] = insertelement <8 x i32> undef, i32 [[conv14]], i32 0
+// CHECK: [[splat_splat16:%.+]] = shufflevector <8 x i32> [[splat_splatinsert15]], <8 x i32> undef, <8 x i32> zeroinitializer
+// CHECK: [[t13:%.+]] = load <8 x i32>, <8 x i32>* {{@.+}},
+// CHECK: shl <8 x i32> [[splat_splat16]], [[t13]]
+  vs8 = ui << vs8;
+// CHECK: [[t14:%.+]] = load i32, i32* @ui,
+// CHECK: [[conv18:%.+]] = trunc i32 [[t14]] to i16
+// CHECK: [[splat_splatinsert19:%.+]] = insertelement <8 x i16> undef, i16 [[conv18]], i32 0
+// CHECK: [[splat_splat20:%.+]] = shufflevector <8 x i16> [[splat_splatinsert19]], <8 x i16> undef, <8 x i32> zeroinitializer
+// CHECK: [[t15:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: shl <8 x i16> [[splat_splat20]], [[t15]]
+  vus8 = 1 << vus8;
+// CHECK: [[t16:%.+]] = load <8 x i16>, <8 x i16>* {{@.+}},
+// CHECK: [[shl22:%.+]] = shl <8 x i16> , [[t16]]
+
+ vc8 = vc8 << vc8;
+// CHECK: [[t17:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: [[t18:%.+]] = load <8

r281669 - [Sema] Allow shifting a scalar operand by a vector operand.

2016-09-15 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Sep 15 17:19:25 2016
New Revision: 281669

URL: http://llvm.org/viewvc/llvm-project?rev=281669&view=rev
Log:
[Sema] Allow shifting a scalar operand by a vector operand.

r278501 inadvertently introduced a bug in which it disallowed shifting
scalar operands by vector operands when not compiling for OpenCL. This
commit fixes it.

Patch by Vladimir Yakovlev.

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

Added:
cfe/trunk/test/CodeGen/vecshift.c
cfe/trunk/test/Sema/vecshift.c
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=281669&r1=281668&r2=281669&view=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 15 17:19:25 2016
@@ -8722,7 +8722,8 @@ static void DiagnoseBadShiftValues(Sema&
 static QualType checkVectorShift(Sema &S, ExprResult &LHS, ExprResult &RHS,
  SourceLocation Loc, bool IsCompAssign) {
   // OpenCL v1.1 s6.3.j says RHS can be a vector only if LHS is a vector.
-  if (!LHS.get()->getType()->isVectorType()) {
+  if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) &&
+  !LHS.get()->getType()->isVectorType()) {
 S.Diag(Loc, diag::err_shift_rhs_only_vector)
   << RHS.get()->getType() << LHS.get()->getType()
   << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
@@ -8738,15 +8739,17 @@ static QualType checkVectorShift(Sema &S
   if (RHS.isInvalid()) return QualType();
 
   QualType LHSType = LHS.get()->getType();
-  const VectorType *LHSVecTy = LHSType->castAs();
-  QualType LHSEleType = LHSVecTy->getElementType();
+  // Note that LHS might be a scalar because the routine calls not only in
+  // OpenCL case.
+  const VectorType *LHSVecTy = LHSType->getAs();
+  QualType LHSEleType = LHSVecTy ? LHSVecTy->getElementType() : LHSType;
 
   // Note that RHS might not be a vector.
   QualType RHSType = RHS.get()->getType();
   const VectorType *RHSVecTy = RHSType->getAs();
   QualType RHSEleType = RHSVecTy ? RHSVecTy->getElementType() : RHSType;
 
-  // OpenCL v1.1 s6.3.j says that the operands need to be integers.
+  // The operands need to be integers.
   if (!LHSEleType->isIntegerType()) {
 S.Diag(Loc, diag::err_typecheck_expect_int)
   << LHS.get()->getType() << LHS.get()->getSourceRange();
@@ -8759,7 +8762,19 @@ static QualType checkVectorShift(Sema &S
 return QualType();
   }
 
-  if (RHSVecTy) {
+  if (!LHSVecTy) {
+assert(RHSVecTy);
+if (IsCompAssign)
+  return RHSType;
+if (LHSEleType != RHSEleType) {
+  LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast);
+  LHSEleType = RHSEleType;
+}
+QualType VecTy =
+S.Context.getExtVectorType(LHSEleType, RHSVecTy->getNumElements());
+LHS = S.ImpCastExprToType(LHS.get(), VecTy, CK_VectorSplat);
+LHSType = VecTy;
+  } else if (RHSVecTy) {
 // OpenCL v1.1 s6.3.j says that for vector types, the operators
 // are applied component-wise. So if RHS is a vector, then ensure
 // that the number of elements is the same as LHS...

Added: cfe/trunk/test/CodeGen/vecshift.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vecshift.c?rev=281669&view=auto
==
--- cfe/trunk/test/CodeGen/vecshift.c (added)
+++ cfe/trunk/test/CodeGen/vecshift.c Thu Sep 15 17:19:25 2016
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+
+typedef __attribute__((__ext_vector_type__(8))) char vector_char8;
+typedef __attribute__((__ext_vector_type__(8))) short vector_short8;
+typedef __attribute__((__ext_vector_type__(8))) int vector_int8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned char vector_uchar8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned short vector_ushort8;
+typedef __attribute__((__ext_vector_type__(8))) unsigned int vector_uint8;
+typedef __attribute__((__ext_vector_type__(4))) char vector_char4;
+typedef __attribute__((__ext_vector_type__(4))) short vector_short4;
+typedef __attribute__((__ext_vector_type__(4))) int vector_int4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned char vector_uchar4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned short vector_ushort4;
+typedef __attribute__((__ext_vector_type__(4))) unsigned int vector_uint4;
+
+char c;
+short s;
+int i;
+unsigned char uc;
+unsigned short us;
+unsigned int ui;
+vector_char8 vc8;
+vector_short8 vs8;
+vector_int8 vi8;
+vector_uchar8 vuc8;
+vector_ushort8 vus8;
+vector_uint8 vui8;
+vector_char4 vc4;
+vector_short4 vs4;
+vector_int4 vi4;
+vector_uchar4 vuc4;
+vector_ushort4 vus4;
+vector_uint4 vui4;
+
+void foo() {
+  vc8 = 1 << vc8;
+// CHECK: [[t0:%.+]] = load <8 x i8>, <8 x i8>* {{@.+}},
+// CHECK: shl <8 x i8> , [[t0]]
+  vuc8 = 1 << vuc8;
+// CHEC

Re: [PATCH] D6974: [libcxx] Attempt to fix undefined behavior in list, forward_list and __tree.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF abandoned this revision.
EricWF added a comment.

Abandoning. All issues have been addressed by other commits.



Comment at: include/memory:5452-5458
@@ +5451,9 @@
+  {
+return static_cast<_To>(_FromPtrTraits::pointer_to(__e));
+  }
+
+  _LIBCPP_INLINE_VISIBILITY
+  static _To __from_pointer(_From & __f)
+  {
+return static_cast<_To>(__f);
+  }

rsmith wrote:
> It seems strange to use `static_cast` here and `reinterpret_cast` below. Even 
> assuming the `reinterpret_cast` approach works, don't we still have the same 
> problem if the user uses a fancy pointer type?
Yeah, I couldn't find a better way to convert fancy pointers. Perhaps we need 
to cast to a void pointer as a go between.


https://reviews.llvm.org/D6974



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


Re: [PATCH] D24602: [libc++] Fix and document visibility attributes for Clang, GCC and Windows.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 71570.
EricWF added a comment.

I'm going to go ahead and commit this w/o review because it's blocking more 
important changes. Post-commit comments on the documentation are appreciated.


https://reviews.llvm.org/D24602

Files:
  CMakeLists.txt
  docs/DesignDocs/VisibilityMacros.rst
  docs/index.rst
  include/__config
  include/__locale
  include/__string
  include/experimental/filesystem
  include/istream
  include/locale
  include/ostream
  include/streambuf
  include/string
  include/vector

Index: include/vector
===
--- include/vector
+++ include/vector
@@ -312,7 +312,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __vector_base_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
Index: include/string
===
--- include/string
+++ include/string
@@ -574,7 +574,7 @@
 #pragma warning( push )
 #pragma warning( disable: 4231 )
 #endif // _LIBCPP_MSVC
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common)
 #ifdef _LIBCPP_MSVC
 #pragma warning( pop )
 #endif // _LIBCPP_MSVC
@@ -1024,7 +1024,7 @@
 _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv) { return replace(__pos1, __n1, __sv.data(), __sv.size()); }
 basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
-_LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_INLINE_VISIBILITY
 basic_string& replace(size_type __pos1, size_type __n1, __self_view __sv, size_type __pos2, size_type __n2=npos);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
 basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
@@ -3910,8 +3910,8 @@
 }
 #endif
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string)
 _LIBCPP_EXTERN_TEMPLATE(string operator+, allocator >(char const*, string const&))
 
 _LIBCPP_END_NAMESPACE_STD
Index: include/streambuf
===
--- include/streambuf
+++ include/streambuf
@@ -574,11 +574,11 @@
 return traits_type::eof();
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf)
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/ostream
===
--- include/ostream
+++ include/ostream
@@ -1113,8 +1113,8 @@
  use_facet >(__os.getloc()).widen('1'));
 }
 
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
-_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
+_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream)
 
 _LIBCPP_END_NAMESPACE_STD
 
Index: include/locale
===
--- include/locale
+++ include/locale
@@ -523,8 +523,8 @@
 return 0;
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get)
 
 template  >
 class _LIBCPP_TYPE_VIS_ONLY num_get
@@ -1042,8 +1042,8 @@
 return __b;
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get)
-_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_TYPE_VIS num_get)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get)
+_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get)
 
 struct _LIBCPP_TYPE_VIS __num_put_base
 {
@@ -1192,8 +1192,8 @@
 __op = __ob + (__np - __nb);
 }
 
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put)
-_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_TYPE_VIS __num_put)
+_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_V

[libcxx] r281673 - [libc++] Fix and document visibility attributes for Clang, GCC and Windows.

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 17:27:07 2016
New Revision: 281673

URL: http://llvm.org/viewvc/llvm-project?rev=281673&view=rev
Log:
[libc++] Fix and document visibility attributes for Clang, GCC and Windows.

Summary:
This patch fixes a number of problems with the visibility macros across GCC (on 
Unix) and Windows (DLL import/export semantics). All of the visibility macros 
are now documented under `DesignDocs/VisibilityMacros.rst`. Now I'll no longer 
forget the subtleties of each!

This patch adds two new visibility macros:

* `_LIBCPP_ENUM_VIS` for controlling the typeinfo of enum types. Only Clang 
supports this.
* `_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS` for redefining visibility on explicit 
instantiation declarations. Clang and Windows require this.

After applying this patch GCC only emits one -Wattribute warning opposed to 30+.


Reviewers: mclow.lists, EricWF

Subscribers: beanz, mgorny, cfe-commits

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

Added:
libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/docs/index.rst
libcxx/trunk/include/__config
libcxx/trunk/include/__locale
libcxx/trunk/include/__string
libcxx/trunk/include/experimental/filesystem
libcxx/trunk/include/istream
libcxx/trunk/include/locale
libcxx/trunk/include/ostream
libcxx/trunk/include/streambuf
libcxx/trunk/include/string
libcxx/trunk/include/vector

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=281673&r1=281672&r2=281673&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Thu Sep 15 17:27:07 2016
@@ -342,7 +342,6 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "
 -Wno-covered-switch-default)
 elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
 add_compile_flags_if_supported(
--Wno-attributes # FIXME: Fix -Wattribute warnings.
 -Wno-literal-suffix
 -Wno-c++14-compat)
 endif()

Added: libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst?rev=281673&view=auto
==
--- libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst (added)
+++ libcxx/trunk/docs/DesignDocs/VisibilityMacros.rst Thu Sep 15 17:27:07 2016
@@ -0,0 +1,85 @@
+
+Symbol Visibility Macros
+
+
+.. contents::
+   :local:
+
+Overview
+
+
+Libc++ uses various "visibility" macros in order to provide a stable ABI in
+both the library and the headers. These macros work by changing the
+visibility and inlining characteristics of the symbols they are applied to.
+
+Visibility Macros
+=
+
+**_LIBCPP_HIDDEN**
+  Mark a symbol as hidden so it will not be exported from shared libraries.
+
+**_LIBCPP_FUNC_VIS**
+  Mark a symbol as being exported by the libc++ library. This attribute must
+  be applied to the declaration of all functions exported by the libc++ dylib.
+
+**_LIBCPP_INLINE_VISIBILITY**
+  Mark a function as hidden and force inlining whenever possible.
+
+**_LIBCPP_ALWAYS_INLINE**
+  A synonym for `_LIBCPP_INLINE_VISIBILITY`
+
+**_LIBCPP_TYPE_VIS**
+  Mark a type's typeinfo and vtable as having default visibility.
+  `_LIBCPP_TYPE_VIS`. This macro has no effect on the visibility of the
+  type's member functions. This attribute cannot be used on class templates.
+
+  **GCC Behavior**: GCC does not support Clang's `type_visibility(...)`
+  attribute. With GCC the `visibility(...)` attribute is used and member
+  functions are affected.
+
+**_LIBCPP_TYPE_VIS_ONLY**
+  The same as `_LIBCPP_TYPE_VIS` except that it may be applied to templates.
+
+  **Windows Behavior**: DLLs do not support dllimport/export on class 
templates.
+  The macro has an empty definition on this platform.
+
+  Note: This macro should be renamed `_LIBCPP_TEMPLATE_TYPE_VIS`.
+
+**_LIBCPP_ENUM_VIS**
+  Mark the typeinfo of an enum as having default visibility. This attribute
+  should be applied to all enum declarations.
+
+  **Windows Behavior**: DLLs do not support importing or exporting enumeration
+  typeinfo. The macro has an empty definition on this platform.
+
+  **GCC Behavior**: GCC un-hides the typeinfo for enumerations by default, even
+  if `-fvisibility=hidden` is specified. Additionally applying a visibility
+  attribute to an enum class results in a warning. The macro has an empty
+  definition with GCC.
+
+**_LIBCPP_EXTERN_TEMPLATE_TYPE_VIS**
+  Mark the member functions, typeinfo, and vtable of the type named in
+  a `_LIBCPP_EXTERN_TEMPLATE` declaration as being exported by the libc++ 
library.
+  This attribute must be specified on all extern class template declarations.
+
+  This macro is used to override the `_LIBCPP_TYPE_VIS_ONLY` attribute
+  

Re: [PATCH] D20811: [analyzer] Model some library functions

2016-09-15 Thread Devin Coughlin via cfe-commits
dcoughlin added a comment.

Thanks for adding the macros. I've provided some feedback inline.

I think a good rule of thumb for readability is: suppose you are a maintainer 
and need to add a summary for a new function. Can you copy the the summary for 
an existing function and figure out what each component means so you can change 
it for the new function?



Comment at: include/clang/StaticAnalyzer/Checkers/Checkers.td:419
@@ -418,1 +418,3 @@
 
+def StdLibraryFunctionsChecker : Checker<"StdLibraryFunctions">,
+  HelpText<"Improve modeling of standard library functions">,

I know you and Gábor already discussed this -- but shouldn't this be 
CStdLibraryFunctionsChecker or 'StdCLibraryFunctionsChecker'? Or is is your 
intent that both C and C++ standard libraries would be modeled by this checker?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:11
@@ +10,3 @@
+// This checker improves modeling of a few simple library functions.
+// It does not throw warnings.
+//

"throw" --> "generate"


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:534
@@ +533,3 @@
+// The isascii() family of functions.
+SPEC {
+  FOR_FUNCTION(isalnum),

Is "specification" the right term here? Or is this really a "summary"?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:536
@@ +535,3 @@
+  FOR_FUNCTION(isalnum),
+  SPEC_DATA {
+ARGUMENT_TYPES { IntTy },

'SPEC_DATA' doesn't seem to add much in terms of readability. Is it needed?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:537
@@ +536,3 @@
+  SPEC_DATA {
+ARGUMENT_TYPES { IntTy },
+RETURN_TYPE(IntTy),

The argument and return types seem like more a property of the function than 
than the summary. Why are they here and not with the function name?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:540
@@ +539,3 @@
+INVALIDATION_APPROACH(EvalCallAsPure),
+BRANCHES {
+  BRANCH { // Boils down to isupper() or islower() or isdigit()

"Cases" seems more appropriate than "branches" (branching is an implementation 
detail).


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:542
@@ +541,3 @@
+  BRANCH { // Boils down to isupper() or islower() or isdigit()
+RANGE {
+  ARG_NO(0), RANGE_KIND(WithinRange),

If I understand correctly, the first "argument" to branch describes the 
constraints on the function arguments and the second (if present) describes the 
resulting constraint on the return value when the argument constraint holds. Is 
there a way to make this apparent in the spelling of the summary?

As a straw proposal, what about renaming the first 'RANGE' to 
'ARGUMENT_CONSTRAINT' and the second the 'RETURN_VALUE_CONSTRAINT'?

Or, more jargony, "PRECONDITION" and "POSTCONDITION"?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:547
@@ +546,3 @@
+RANGE {
+  RET_VAL, RANGE_KIND(OutOfRange),
+  SET { POINT(0) }

Is it ever the case that this final 'RANGE" constrains anything other than the 
return value? If not, can 'RET_VAL' be elided?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:554
@@ +553,3 @@
+  ARG_NO(0), RANGE_KIND(WithinRange),
+  SET { SEG(128, 255) }
+}

What is the motivation behind the use of geometric terms here (i.e., "SEG", 
"POINT")? Why not "INTERVAL" and "EXACT_VALUE"?


Comment at: lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:560
@@ +559,3 @@
+  ARG_NO(0), RANGE_KIND(OutOfRange),
+  SET { SEG('0', '9') U SEG('A', 'Z')
+  U SEG('a', 'z') U SEG(128, 255)}

Would you be opposed to 'UNION' instead of 'U'?


https://reviews.llvm.org/D20811



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


[PATCH] D24639: [Sema] Warn when returning a lambda that captures a local variable by reference

2016-09-15 Thread Erik Pilkington via cfe-commits
erik.pilkington created this revision.
erik.pilkington added reviewers: faisalv, rsmith.
erik.pilkington added a subscriber: cfe-commits.

Previously, clang emitted no diagnostic for the following:
```
auto f() {
  int loc;
  return [&] { return loc; };
}
```
The problem being that this returns a dangling reference to the local variable 
'loc'. This patch warns on this by extending `-Wreturn-stack-address`.

This patch also warns on the following, where the lambda is stored in a 
variable:
```
auto f() {
  int loc;
  auto lam = [&loc] {};
  return lam; // warn
}
```
I believe that this is OK, I can't think of any valid way of mutating `lam` 
that would make the code not return a dangling pointer to `loc`.

Also, this diagnoses the following, where a pointer to a local is captured via 
an init-capture:
```
auto f() {
  int local;
  return [x = &local] {}; // warn
}
```
But not here, because we would have to verify that the pointer in `lam` wasn't 
mutated in a previous call of the lambda:
```
auto f() {
  int local;
  auto lam = [x = &local] {};
  return lam; // no warn
}
```

Thanks for taking a look!

https://reviews.llvm.org/D24639

Files:
  include/clang/AST/LambdaCapture.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp
  test/SemaCXX/cxx1y-init-captures.cpp
  test/SemaCXX/return-lambda-stack-addr.cpp

Index: test/SemaCXX/return-lambda-stack-addr.cpp
===
--- test/SemaCXX/return-lambda-stack-addr.cpp
+++ test/SemaCXX/return-lambda-stack-addr.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_cc1 -std=c++14 -verify -fsyntax-only %s
+
+auto basic() {
+  int local;
+
+  return [&]() {
+(void)local; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+  };
+}
+
+auto by_copy() {
+  int local;
+
+  return [=]() {
+(void)local; // no warning
+  };
+}
+
+auto nested() {
+  int local;
+
+  return [=] {
+return [&]() { (void)local; }; // no warning
+  };
+}
+
+auto nested2() {
+  int local;
+
+  return [&] {
+(void)[=] {
+  (void)local; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+};
+  };
+}
+
+auto nested3() {
+  int local;
+  return [&] {
+return [&] {
+  (void)local; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+};
+  };
+}
+
+struct function {
+  template 
+  function(T) {}
+};
+
+function to_function() {
+  int local;
+  return [&] { (void)local; };
+}
+
+auto lambda = [] {
+  int local;
+  return [&] { return local; }; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+};
+
+auto ref_copy() {
+  int x;
+  int &y = x;
+
+  return [=] { (void)y; };
+}
+
+auto ref_ref() {
+  int x;
+  int &y = x;  // expected-note{{binding reference variable 'y' here}}
+  return [&] { (void)y; }; // expected-warning{{address of stack memory associated with local variable 'x' returned}}
+}
+
+auto param(int p) {
+  return [&] { (void)p; }; // expected-warning{{address of stack memory associated with local variable 'p' returned}}
+}
+
+auto return_var() {
+  int local;
+  auto lam = [&local] {}; // expected-note 4 {{capturing local variable in lambda 'lam' here}}
+
+  auto &lam_ref = lam; // expected-note 2 {{binding reference variable 'lam_ref' here}}
+
+  if (0)
+return lam; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+  else if (0)
+return *&lam; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+  else if (0)
+return lam_ref; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+  else
+return *&lam_ref; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+}
+
+auto return_ptr_no_warn() {
+  int local;
+  auto lam = [ptr = &local]{};
+  return lam; // no warning
+}
+
+auto return_ptr_warn() {
+  int local;
+  return [ptr = &local]{}; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+}
+
+auto mutable_lambda_warn() {
+  int local;
+  auto mut = [&local]() mutable {}; // expected-note{{capturing local variable in lambda 'mut' here}}
+  return mut;   // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+}
+
+auto mutable_lambda_warn2() {
+  int local;
+  return [cap = &local]() mutable {}; // expected-warning{{address of stack memory associated with local variable 'local' returned}}
+}
+
+auto mutable_lambda_no_warn() {
+  int local;
+  auto mut = [cap = &local]() mutable {};
+  return mut; // no warning
+}
+
+auto ref_ptr() {
+  int local;
+  auto lam = [&local] {};  // expected-note{{capturing local variable in lambda 'lam' here}}
+  auto *const &lolwhat = &lam; /

Re: [PATCH] D22053: [Sema] Fix a C++1z bug where initializer for static constexpr data member was not instantiated

2016-09-15 Thread Erik Pilkington via cfe-commits
erik.pilkington added a comment.

Ping, sorry for the delay.


https://reviews.llvm.org/D22053



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


Re: Upgrade and fix clang-format-vs

2016-09-15 Thread Hans Wennborg via cfe-commits
Well, on my machine $(SDKToolsDir) doesn't work :-( I suspect the file
will need manual tweaking by whoever is trying to build the plugin.

Anyway, I've updated the solution to build with VS2015 in r281648 and
confirmed that it can still be used with older VS versions too.

Cheers,
Hans

On Thu, Aug 18, 2016 at 7:11 PM, Zachary Turner  wrote:
> The key.snk is generated when you build, the problem is the csproj file
> hardcodes the directory to the sdk instead of using the appropriate project
> system variable like $(SDKToolsDir)
>
> On Thu, Aug 18, 2016 at 7:09 PM Zachary Turner  wrote:
>>
>> Llvm doesn't support vs2012 anymore, as long as it supports vs2013 it's
>> fine
>> On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano 
>> wrote:
>>>
>>> Hi,
>>>
>>> What I meant by upgrade was simply making it build in VS 2015. However,
>>> you bring up a valid point about making sure the extension will continue to
>>> work in VS 2012. I will look into that. Like those references that go from
>>> 10 to 14 that point out; I wonder if instead I should be able to bring in
>>> those version 10 assemblies via NuGet. I'll take a closer look.
>>>
>>> Part of my change, however, seems to imply that the extension (vsix)
>>> project would not build correctly even in VS 2012. For instance, the missing
>>> Key.snk file. I don't have VS 2012 installed at the moment, so I cannot
>>> validate.
>>>
>>> Thanks,
>>>
>>> Antonio
>>>
>>>
>>>
>>> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg  wrote:

 Hi Antonio,

 On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
  wrote:
 > This patch for clang-format-vs includes the following:
 >
 > - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to
 > 4.5, and
 > upgrading Microsoft.VisualStudio references to v14 versions
 > - Fix build by removing dependency on "Key.snk" file which was never
 > checked
 > in (and not really required anyway)
 > - Add ".vs" directory to svn ignore (new folder that VS 2015 creates
 > for
 > user settings)

 "What does "Upgrade to VS 2015 mean? Adding support for running the
 plugin in VS2015, or does it mean requiring VS2015 for building?

 +zturner: I thought the plugin already worked in VS 2015?

 I mostly just build the plugin without knowing exactly how this stuff
 works, but looking at the patch I'm worried that you're increasing the
 required version for building it? I see a bunch of values going from
 10 (VS 2012) to 14 (VS 2015).

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


Re: Upgrade and fix clang-format-vs

2016-09-15 Thread Zachary Turner via cfe-commits
You may need to install the Visual Studio SDK.  Did you do that when you
initially installed VS 2015?

On Thu, Sep 15, 2016 at 4:15 PM Hans Wennborg  wrote:

> Well, on my machine $(SDKToolsDir) doesn't work :-( I suspect the file
> will need manual tweaking by whoever is trying to build the plugin.
>
> Anyway, I've updated the solution to build with VS2015 in r281648 and
> confirmed that it can still be used with older VS versions too.
>
> Cheers,
> Hans
>
> On Thu, Aug 18, 2016 at 7:11 PM, Zachary Turner 
> wrote:
> > The key.snk is generated when you build, the problem is the csproj file
> > hardcodes the directory to the sdk instead of using the appropriate
> project
> > system variable like $(SDKToolsDir)
> >
> > On Thu, Aug 18, 2016 at 7:09 PM Zachary Turner 
> wrote:
> >>
> >> Llvm doesn't support vs2012 anymore, as long as it supports vs2013 it's
> >> fine
> >> On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano 
> >> wrote:
> >>>
> >>> Hi,
> >>>
> >>> What I meant by upgrade was simply making it build in VS 2015. However,
> >>> you bring up a valid point about making sure the extension will
> continue to
> >>> work in VS 2012. I will look into that. Like those references that go
> from
> >>> 10 to 14 that point out; I wonder if instead I should be able to bring
> in
> >>> those version 10 assemblies via NuGet. I'll take a closer look.
> >>>
> >>> Part of my change, however, seems to imply that the extension (vsix)
> >>> project would not build correctly even in VS 2012. For instance, the
> missing
> >>> Key.snk file. I don't have VS 2012 installed at the moment, so I cannot
> >>> validate.
> >>>
> >>> Thanks,
> >>>
> >>> Antonio
> >>>
> >>>
> >>>
> >>> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg  wrote:
> 
>  Hi Antonio,
> 
>  On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
>   wrote:
>  > This patch for clang-format-vs includes the following:
>  >
>  > - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to
>  > 4.5, and
>  > upgrading Microsoft.VisualStudio references to v14 versions
>  > - Fix build by removing dependency on "Key.snk" file which was never
>  > checked
>  > in (and not really required anyway)
>  > - Add ".vs" directory to svn ignore (new folder that VS 2015 creates
>  > for
>  > user settings)
> 
>  "What does "Upgrade to VS 2015 mean? Adding support for running the
>  plugin in VS2015, or does it mean requiring VS2015 for building?
> 
>  +zturner: I thought the plugin already worked in VS 2015?
> 
>  I mostly just build the plugin without knowing exactly how this stuff
>  works, but looking at the patch I'm worried that you're increasing the
>  required version for building it? I see a bunch of values going from
>  10 (VS 2012) to 14 (VS 2015).
> 
>  Thanks,
>  Hans
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Upgrade and fix clang-format-vs

2016-09-15 Thread Hans Wennborg via cfe-commits
When I first opened the solution in VS it prompted me to install it and I did.

On Thu, Sep 15, 2016 at 4:17 PM, Zachary Turner  wrote:
> You may need to install the Visual Studio SDK.  Did you do that when you
> initially installed VS 2015?
>
> On Thu, Sep 15, 2016 at 4:15 PM Hans Wennborg  wrote:
>>
>> Well, on my machine $(SDKToolsDir) doesn't work :-( I suspect the file
>> will need manual tweaking by whoever is trying to build the plugin.
>>
>> Anyway, I've updated the solution to build with VS2015 in r281648 and
>> confirmed that it can still be used with older VS versions too.
>>
>> Cheers,
>> Hans
>>
>> On Thu, Aug 18, 2016 at 7:11 PM, Zachary Turner 
>> wrote:
>> > The key.snk is generated when you build, the problem is the csproj file
>> > hardcodes the directory to the sdk instead of using the appropriate
>> > project
>> > system variable like $(SDKToolsDir)
>> >
>> > On Thu, Aug 18, 2016 at 7:09 PM Zachary Turner 
>> > wrote:
>> >>
>> >> Llvm doesn't support vs2012 anymore, as long as it supports vs2013 it's
>> >> fine
>> >> On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano 
>> >> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> What I meant by upgrade was simply making it build in VS 2015.
>> >>> However,
>> >>> you bring up a valid point about making sure the extension will
>> >>> continue to
>> >>> work in VS 2012. I will look into that. Like those references that go
>> >>> from
>> >>> 10 to 14 that point out; I wonder if instead I should be able to bring
>> >>> in
>> >>> those version 10 assemblies via NuGet. I'll take a closer look.
>> >>>
>> >>> Part of my change, however, seems to imply that the extension (vsix)
>> >>> project would not build correctly even in VS 2012. For instance, the
>> >>> missing
>> >>> Key.snk file. I don't have VS 2012 installed at the moment, so I
>> >>> cannot
>> >>> validate.
>> >>>
>> >>> Thanks,
>> >>>
>> >>> Antonio
>> >>>
>> >>>
>> >>>
>> >>> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg  wrote:
>> 
>>  Hi Antonio,
>> 
>>  On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
>>   wrote:
>>  > This patch for clang-format-vs includes the following:
>>  >
>>  > - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to
>>  > 4.5, and
>>  > upgrading Microsoft.VisualStudio references to v14 versions
>>  > - Fix build by removing dependency on "Key.snk" file which was
>>  > never
>>  > checked
>>  > in (and not really required anyway)
>>  > - Add ".vs" directory to svn ignore (new folder that VS 2015
>>  > creates
>>  > for
>>  > user settings)
>> 
>>  "What does "Upgrade to VS 2015 mean? Adding support for running the
>>  plugin in VS2015, or does it mean requiring VS2015 for building?
>> 
>>  +zturner: I thought the plugin already worked in VS 2015?
>> 
>>  I mostly just build the plugin without knowing exactly how this stuff
>>  works, but looking at the patch I'm worried that you're increasing
>>  the
>>  required version for building it? I see a bunch of values going from
>>  10 (VS 2012) to 14 (VS 2015).
>> 
>>  Thanks,
>>  Hans
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Upgrade and fix clang-format-vs

2016-09-15 Thread Zachary Turner via cfe-commits
Strange.  FWIW you can dump all the variables that are present in your
environment.  You need to go to Tools -> Options -> Projects and Solutions
-> Build and Run and choose either Normal, Detailed, or Diagnostic for the
MSBuild project build output verbosity.  Then in the output window you will
get a ton of spam, some of which is the set of all MSBuild variables you
can take advantage of.

On Thu, Sep 15, 2016 at 4:25 PM Hans Wennborg  wrote:

> When I first opened the solution in VS it prompted me to install it and I
> did.
>
> On Thu, Sep 15, 2016 at 4:17 PM, Zachary Turner 
> wrote:
> > You may need to install the Visual Studio SDK.  Did you do that when you
> > initially installed VS 2015?
> >
> > On Thu, Sep 15, 2016 at 4:15 PM Hans Wennborg  wrote:
> >>
> >> Well, on my machine $(SDKToolsDir) doesn't work :-( I suspect the file
> >> will need manual tweaking by whoever is trying to build the plugin.
> >>
> >> Anyway, I've updated the solution to build with VS2015 in r281648 and
> >> confirmed that it can still be used with older VS versions too.
> >>
> >> Cheers,
> >> Hans
> >>
> >> On Thu, Aug 18, 2016 at 7:11 PM, Zachary Turner 
> >> wrote:
> >> > The key.snk is generated when you build, the problem is the csproj
> file
> >> > hardcodes the directory to the sdk instead of using the appropriate
> >> > project
> >> > system variable like $(SDKToolsDir)
> >> >
> >> > On Thu, Aug 18, 2016 at 7:09 PM Zachary Turner 
> >> > wrote:
> >> >>
> >> >> Llvm doesn't support vs2012 anymore, as long as it supports vs2013
> it's
> >> >> fine
> >> >> On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano <
> amaior...@gmail.com>
> >> >> wrote:
> >> >>>
> >> >>> Hi,
> >> >>>
> >> >>> What I meant by upgrade was simply making it build in VS 2015.
> >> >>> However,
> >> >>> you bring up a valid point about making sure the extension will
> >> >>> continue to
> >> >>> work in VS 2012. I will look into that. Like those references that
> go
> >> >>> from
> >> >>> 10 to 14 that point out; I wonder if instead I should be able to
> bring
> >> >>> in
> >> >>> those version 10 assemblies via NuGet. I'll take a closer look.
> >> >>>
> >> >>> Part of my change, however, seems to imply that the extension (vsix)
> >> >>> project would not build correctly even in VS 2012. For instance, the
> >> >>> missing
> >> >>> Key.snk file. I don't have VS 2012 installed at the moment, so I
> >> >>> cannot
> >> >>> validate.
> >> >>>
> >> >>> Thanks,
> >> >>>
> >> >>> Antonio
> >> >>>
> >> >>>
> >> >>>
> >> >>> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg 
> wrote:
> >> 
> >>  Hi Antonio,
> >> 
> >>  On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
> >>   wrote:
> >>  > This patch for clang-format-vs includes the following:
> >>  >
> >>  > - Upgrade to VS 2015, including .NET framework upgrade from 4.0
> to
> >>  > 4.5, and
> >>  > upgrading Microsoft.VisualStudio references to v14 versions
> >>  > - Fix build by removing dependency on "Key.snk" file which was
> >>  > never
> >>  > checked
> >>  > in (and not really required anyway)
> >>  > - Add ".vs" directory to svn ignore (new folder that VS 2015
> >>  > creates
> >>  > for
> >>  > user settings)
> >> 
> >>  "What does "Upgrade to VS 2015 mean? Adding support for running the
> >>  plugin in VS2015, or does it mean requiring VS2015 for building?
> >> 
> >>  +zturner: I thought the plugin already worked in VS 2015?
> >> 
> >>  I mostly just build the plugin without knowing exactly how this
> stuff
> >>  works, but looking at the patch I'm worried that you're increasing
> >>  the
> >>  required version for building it? I see a bunch of values going
> from
> >>  10 (VS 2012) to 14 (VS 2015).
> >> 
> >>  Thanks,
> >>  Hans
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14471: [AArch64] Fix a crash in driver

2016-09-15 Thread Akira Hatanaka via cfe-commits
ahatanak abandoned this revision.
ahatanak added a comment.

The crash I was trying to fix was fixed in https://reviews.llvm.org/D23643.


https://reviews.llvm.org/D14471



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


[PATCH] D24640: [CUDA] Don't try to run sanitizers on NVPTX.

2016-09-15 Thread Justin Lebar via cfe-commits
jlebar created this revision.
jlebar added a reviewer: kcc.
jlebar added subscribers: jhen, tra, cfe-commits.

Sanitizers aren't supported on NVPTX -- don't try to run them.

This lets you e.g. pass -fsanitize=address and get asan on your host
code.

https://reviews.llvm.org/D24640

Files:
  clang/lib/Driver/SanitizerArgs.cpp
  clang/test/Driver/cuda-no-sanitizers.cu

Index: clang/test/Driver/cuda-no-sanitizers.cu
===
--- /dev/null
+++ clang/test/Driver/cuda-no-sanitizers.cu
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 
-fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -608,6 +608,12 @@
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList 
&Args,
 llvm::opt::ArgStringList &CmdArgs,
 types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't 
require
   // sanitizers.


Index: clang/test/Driver/cuda-no-sanitizers.cu
===
--- /dev/null
+++ clang/test/Driver/cuda-no-sanitizers.cu
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -608,6 +608,12 @@
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs,
 types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't require
   // sanitizers.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24640: [CUDA] Don't try to run sanitizers on NVPTX.

2016-09-15 Thread Kostya Serebryany via cfe-commits
kcc accepted this revision.
kcc added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D24640



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


r281680 - [CUDA] Don't try to run sanitizers on NVPTX.

2016-09-15 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Sep 15 18:44:13 2016
New Revision: 281680

URL: http://llvm.org/viewvc/llvm-project?rev=281680&view=rev
Log:
[CUDA] Don't try to run sanitizers on NVPTX.

Summary:
Sanitizers aren't supported on NVPTX -- don't try to run them.

This lets you e.g. pass -fsanitize=address and get asan on your host
code.

Reviewers: kcc

Subscribers: cfe-commits, tra, jhen

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

Added:
cfe/trunk/test/Driver/cuda-no-sanitizers.cu
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=281680&r1=281679&r2=281680&view=diff
==
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Sep 15 18:44:13 2016
@@ -608,6 +608,12 @@ static void addIncludeLinkerOption(const
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList 
&Args,
 llvm::opt::ArgStringList &CmdArgs,
 types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't 
require
   // sanitizers.

Added: cfe/trunk/test/Driver/cuda-no-sanitizers.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-no-sanitizers.cu?rev=281680&view=auto
==
--- cfe/trunk/test/Driver/cuda-no-sanitizers.cu (added)
+++ cfe/trunk/test/Driver/cuda-no-sanitizers.cu Thu Sep 15 18:44:13 2016
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 
-fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"


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


Re: [PATCH] D24640: [CUDA] Don't try to run sanitizers on NVPTX.

2016-09-15 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281680: [CUDA] Don't try to run sanitizers on NVPTX. 
(authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D24640?vs=71572&id=71573#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24640

Files:
  cfe/trunk/lib/Driver/SanitizerArgs.cpp
  cfe/trunk/test/Driver/cuda-no-sanitizers.cu

Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -608,6 +608,12 @@
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList 
&Args,
 llvm::opt::ArgStringList &CmdArgs,
 types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't 
require
   // sanitizers.
Index: cfe/trunk/test/Driver/cuda-no-sanitizers.cu
===
--- cfe/trunk/test/Driver/cuda-no-sanitizers.cu
+++ cfe/trunk/test/Driver/cuda-no-sanitizers.cu
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 
-fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -608,6 +608,12 @@
 void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
 llvm::opt::ArgStringList &CmdArgs,
 types::ID InputType) const {
+  // NVPTX doesn't currently support sanitizers.  Bailing out here means that
+  // e.g. -fsanitize=address applies only to host code, which is what we want
+  // for now.
+  if (TC.getTriple().isNVPTX())
+return;
+
   // Translate available CoverageFeatures to corresponding clang-cc1 flags.
   // Do it even if Sanitizers.empty() since some forms of coverage don't require
   // sanitizers.
Index: cfe/trunk/test/Driver/cuda-no-sanitizers.cu
===
--- cfe/trunk/test/Driver/cuda-no-sanitizers.cu
+++ cfe/trunk/test/Driver/cuda-no-sanitizers.cu
@@ -0,0 +1,12 @@
+// Check that -fsanitize=foo doesn't get passed down to device-side
+// compilation.
+//
+// REQUIRES: clang-driver
+//
+// RUN: %clang -### -target x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 -fsanitize=address %s 2>&1 | \
+// RUN:   FileCheck %s
+
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-fsanitize=address"
+// CHECK-DAG: "-triple" "x86_64--linux-gnu"
+// CHECK: "-fsanitize=address"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24600: [libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI compatibility

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 71574.
EricWF added a comment.

- Update the patch based on r281673.
- Add doc for `_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY`
- Move all uses of `_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY` to the first 
declaration in order to support `__attribute__((internal_linkage))`. I took the 
liberty of moving many of the definitions in-line to reduce duplication.




https://reviews.llvm.org/D24600

Files:
  CMakeLists.txt
  docs/DesignDocs/VisibilityMacros.rst
  include/__config
  include/istream
  include/ostream
  include/streambuf
  include/string
  utils/sym_check/sym_diff.py

Index: utils/sym_check/sym_diff.py
===
--- utils/sym_check/sym_diff.py
+++ utils/sym_check/sym_diff.py
@@ -24,6 +24,10 @@
 help='Only print symbol names',
 action='store_true', default=False)
 parser.add_argument(
+'--removed-only', dest='removed_only',
+help='Only print removed symbols',
+action='store_true', default=False)
+parser.add_argument(
 '-o', '--output', dest='output',
 help='The output file. stdout is used if not given',
 type=str, action='store', default=None)
@@ -41,6 +45,8 @@
 new_syms_list = util.extract_or_load(args.new_syms)
 
 added, removed, changed = diff.diff(old_syms_list, new_syms_list)
+if args.removed_only:
+added = {}
 report, is_break = diff.report_diff(added, removed, changed,
 names_only=args.names_only,
 demangle=args.demangle)
Index: include/string
===
--- include/string
+++ include/string
@@ -1269,19 +1269,24 @@
  __align_it (__s+1)) - 1;}
 
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 void __init(const value_type* __s, size_type __sz, size_type __reserve);
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 void __init(const value_type* __s, size_type __sz);
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 void __init(size_type __n, value_type __c);
 
 template 
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 typename enable_if
 <
 __is_exactly_input_iterator<_InputIterator>::value,
 void
 >::type
 __init(_InputIterator __first, _InputIterator __last);
 
 template 
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 typename enable_if
 <
 __is_forward_iterator<_ForwardIterator>::value,
@@ -1430,9 +1435,9 @@
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
-void
-basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz, size_type __reserve)
+void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
+   size_type __sz,
+   size_type __reserve)
 {
 if (__reserve > max_size())
 this->__throw_length_error();
@@ -1455,7 +1460,6 @@
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
 {
@@ -1593,7 +1597,6 @@
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 void
 basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
 {
@@ -1690,7 +1693,6 @@
 
 template 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
 __is_exactly_input_iterator<_InputIterator>::value,
@@ -1718,7 +1720,6 @@
 
 template 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 typename enable_if
 <
 __is_forward_iterator<_ForwardIterator>::value,
Index: include/streambuf
===
--- include/streambuf
+++ include/streambuf
@@ -132,32 +132,96 @@
 virtual ~basic_streambuf();
 
 // 27.6.2.2.1 locales:
-locale pubimbue(const locale& __loc);
-locale getloc() const;
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
+locale pubimbue(const locale& __loc) {
+imbue(__loc);
+locale __r = __loc_;
+__loc_ = __loc;
+return __r;
+}
+
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
+locale getloc() const { return __loc_; }
 
 // 27.6.2.2.2 buffer and positioning:
-basic_streambuf* pubsetbuf(char_type* __s, streamsize __n);
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
+basic_streambuf* pubsetbuf(char_type* __s, streamsize __n)
+{ return setbuf(__s, __n); }
+
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 pos_type pubseekoff(off_type __off, ios_base::seekdir __way,
-ios_base::openmode __which = ios_base::in | ios_base::out);
+ios_base::openmode __which = ios_base::in | ios_base::out)
+{ return seekoff(__off, __way, __which); }
+
+inline _LIBCPP_EXTERN_TEMPLA

Re: [PATCH] D24600: [libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI compatibility

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a reviewer: EricWF.
EricWF added a comment.
This revision is now accepted and ready to land.

Accepting to commit. Post commit review is very welcome (but nobody likes 
looking at visibility patches).


https://reviews.llvm.org/D24600



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


[libcxx] r281681 - [libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI compatibility

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 19:00:48 2016
New Revision: 281681

URL: http://llvm.org/viewvc/llvm-project?rev=281681&view=rev
Log:
[libc++] Add _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY to support GCC ABI 
compatibility

Summary:
GCC and Clang handle visibility attributes on the out-of-line definition of 
externally instantiated templates differently. For example in the reproducer 
below Clang will emit both 'foo' and 'bar' with default visibility while GCC 
only emits a non-hidden 'foo'.  

```
// RUN: g++ -std=c++11 -shared -O3 test.cpp && sym_extract.py a.out
// RUN: clang++ -std=c++11 -shared -O3 test.cpp && sym_extract.py a.out
#define INLINE_VISIBILITY __attribute__((visibility("hidden"), always_inline))

template 
struct Foo {
  void foo();
  void bar();
};

template 
void Foo::foo() {}

template 
inline INLINE_VISIBILITY
void Foo::bar() {}

template struct Foo;
```

This difference creates ABI incompatibilities between Clang and GCC built 
dylibs. Specifically GCC built dylibs lack definitions for various member 
functions of `basic_string`, `basic_istream`, `basic_ostream`, 
`basic_iostream`, and `basic_streambuf` (All of these types are externally 
instantiated). 

Surprisingly these missing symbols don't cause many problems because the 
functions are marked `always_inline`  therefore the dylib definition is rarely 
needed. However when an out-of-line definition is required then GCC built 
dylibs will fail to link. For example [GCC built dylibs cannot build 
Clang](http://stackoverflow.com/questions/39454262/clang-build-errors).

This patch works around this issue by adding 
`_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY` which is used to mark externally 
instantiated member functions as always inline. When building the library 
`_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY` sets the symbol's visibility to 
"default" instead of "hidden", otherwise it acts exactly the same as 
`_LIBCPP_INLINE_VISIBILITY`.

After applying this patch GCC dylibs now contain:
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE7sungetcEv`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5gbumpEi`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE7sungetcEv`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE9sputbackcEc`
  * 
`_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE3getERNS_15basic_streambufIwS2_EE`
  * 
`_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEElsEPFRNS_9basic_iosIwS2_EES6_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE4setpEPcS4_`
  * 
`_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEEC1EPNS_15basic_streambufIwS2_EE`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6snextcEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE4swapERS3_`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE4swapERS3_`
  * 
`_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEErsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE9pubsetbufEPcl`
  * 
`_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE10pubseekoffExNS_8ios_base7seekdirEj`
  * 
`_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEErsEPFRNS_9basic_iosIwS2_EES6_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE5pbumpEi`
  * 
`_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5seekpENS_4fposI11__mbstate_tEE`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE7getlineEPcl`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sgetcEv`
  * 
`_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getERNS_15basic_streambufIcS2_EE`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE8in_availEv`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEErsEPFRNS_8ios_baseES5_E`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE6sbumpcEv`
  * 
`_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsEPFRNS_9basic_iosIcS2_EES6_E`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getERc`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE6snextcEv`
  * `_ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initEmw`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE7getlineEPwl`
  * `_ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5tellpEv`
  * `_ZNSt3__113basic_istreamIwNS_11char_traitsIwEEE3getERw`
  * `_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE7pubsyncEv`
  * `_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEE3getEPcl`
  * 
`_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEEC2EPNS_15basic_streambufIcS2_EE`
  * 
`_ZNSt3__113basic_istreamIcNS_11char_traitsIcEEErsEPFRNS_9basic_iosIcS2_EES6_E`
  * `_ZNSt3__115basic_streambufIwNS_11char_traitsIwEEE7pubsyncEv`
  * `_ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sputcEc`
  * 
`_ZNSt3__113basic_ostreamIwNS_11char_traitsIwEEE5seekpExNS_8ios_base7seekdirE`
  * `_ZNKSt3__115basic_streambufIcNS_11char_traitsIcEEE6getlocEv`
  * `_ZNSt3__115basi

Re: [PATCH] D21104: [CodeGen][ObjC] Block captures should inherit the type of the captured field in the enclosing lambda or block

2016-09-15 Thread Akira Hatanaka via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281682: [CodeGen][ObjC] Block captures should inherit the 
type of the captured (authored by ahatanak).

Changed prior to commit:
  https://reviews.llvm.org/D21104?vs=64199&id=71575#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D21104

Files:
  cfe/trunk/lib/CodeGen/CGBlocks.cpp
  cfe/trunk/lib/CodeGen/CGBlocks.h
  cfe/trunk/test/CodeGenObjCXX/lambda-expressions.mm

Index: cfe/trunk/test/CodeGenObjCXX/lambda-expressions.mm
===
--- cfe/trunk/test/CodeGenObjCXX/lambda-expressions.mm
+++ cfe/trunk/test/CodeGenObjCXX/lambda-expressions.mm
@@ -4,6 +4,8 @@
 typedef int (^fp)();
 fp f() { auto x = []{ return 3; }; return x; }
 
+// ARC: %[[LAMBDACLASS:.*]] = type { i32 }
+
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [5 x i8] c"copy\00"
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [12 x i8] c"autorelease\00"
 // MRC-LABEL: define i32 ()* @_Z1fv(
@@ -60,6 +62,40 @@
 }
 @end
 
+// ARC: define void @_ZN13LambdaCapture4foo1ERi(i32* dereferenceable(4) %{{.*}})
+// ARC:   %[[CAPTURE0:.*]] = getelementptr inbounds %[[LAMBDACLASS]], %[[LAMBDACLASS]]* %{{.*}}, i32 0, i32 0
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE0]]
+
+// ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_3clEv"(%[[LAMBDACLASS]]* %{{.*}})
+// ARC:   %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>
+// ARC:   %[[CAPTURE1:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE1]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke"
+// ARC:   %[[CAPTURE2:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE2]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke_2"(i8* %{{.*}})
+// ARC:   %[[CAPTURE3:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   %[[V1:.*]] = load i32, i32* %[[CAPTURE3]]
+// ARC:   store i32 %[[V1]], i32* @_ZN13LambdaCapture1iE
+
+namespace LambdaCapture {
+  int i;
+  void foo1(int &a) {
+auto lambda = [a]{
+  auto block1 = ^{
+auto block2 = ^{
+  i = a;
+};
+block2();
+  };
+  block1();
+};
+lambda();
+  }
+}
+
 // ARC-LABEL: define linkonce_odr i32 ()* @_ZZNK13StaticMembersIfE1fMUlvE_clEvENKUlvE_cvU13block_pointerFivEEv
 
 // Check lines for BlockInLambda test below
Index: cfe/trunk/lib/CodeGen/CGBlocks.h
===
--- cfe/trunk/lib/CodeGen/CGBlocks.h
+++ cfe/trunk/lib/CodeGen/CGBlocks.h
@@ -159,6 +159,11 @@
 EHScopeStack::stable_iterator Cleanup;
 CharUnits::QuantityType Offset;
 
+/// Type of the capture field. Normally, this is identical to the type of
+/// the capture's VarDecl, but can be different if there is an enclosing
+/// lambda.
+QualType FieldType;
+
   public:
 bool isIndex() const { return (Data & 1) != 0; }
 bool isConstant() const { return !isIndex(); }
@@ -185,10 +190,16 @@
   return reinterpret_cast(Data);
 }
 
-static Capture makeIndex(unsigned index, CharUnits offset) {
+QualType fieldType() const {
+  return FieldType;
+}
+
+static Capture makeIndex(unsigned index, CharUnits offset,
+ QualType FieldType) {
   Capture v;
   v.Data = (index << 1) | 1;
   v.Offset = offset.getQuantity();
+  v.FieldType = FieldType;
   return v;
 }
 
Index: cfe/trunk/lib/CodeGen/CGBlocks.cpp
===
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp
@@ -199,22 +199,23 @@
 Qualifiers::ObjCLifetime Lifetime;
 const BlockDecl::Capture *Capture; // null for 'this'
 llvm::Type *Type;
+QualType FieldType;
 
 BlockLayoutChunk(CharUnits align, CharUnits size,
  Qualifiers::ObjCLifetime lifetime,
  const BlockDecl::Capture *capture,
- llvm::Type *type)
+ llvm::Type *type, QualType fieldType)
   : Alignment(align), Size(size), Lifetime(lifetime),
-Capture(capture), Type(type) {}
+Capture(capture), Type(type), FieldType(fieldType) {}
 
 /// Tell the block info that this chunk has the given field index.
 void setIndex(CGBlockInfo &info, unsigned index, CharUnits offset) {
   if (!Capture) {
 info.CXXThisIndex = index;
 info.CXXThisOffset = offset;
 

r281682 - [CodeGen][ObjC] Block captures should inherit the type of the captured

2016-09-15 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Sep 15 19:02:06 2016
New Revision: 281682

URL: http://llvm.org/viewvc/llvm-project?rev=281682&view=rev
Log:
[CodeGen][ObjC] Block captures should inherit the type of the captured
field in the enclosing lambda or block.

This patch fixes a bug in code-gen where it uses the type of the
declared variable rather than the type of the capture of the enclosing
lambda or block for the block capture. For example, in the following
function, code-gen currently uses i32* for the block capture "a" because
"a" is passed to foo1 as a reference, but it should use i32 since the
enclosing lambda captures "a" by value.

void foo1(int &a) {
  auto lambda = [a]{
auto block1 = ^{
  i = a;
};
block1();
  };
  lambda();
}

rdar://problem/18586386

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBlocks.h
cfe/trunk/test/CodeGenObjCXX/lambda-expressions.mm

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=281682&r1=281681&r2=281682&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Sep 15 19:02:06 2016
@@ -199,13 +199,14 @@ namespace {
 Qualifiers::ObjCLifetime Lifetime;
 const BlockDecl::Capture *Capture; // null for 'this'
 llvm::Type *Type;
+QualType FieldType;
 
 BlockLayoutChunk(CharUnits align, CharUnits size,
  Qualifiers::ObjCLifetime lifetime,
  const BlockDecl::Capture *capture,
- llvm::Type *type)
+ llvm::Type *type, QualType fieldType)
   : Alignment(align), Size(size), Lifetime(lifetime),
-Capture(capture), Type(type) {}
+Capture(capture), Type(type), FieldType(fieldType) {}
 
 /// Tell the block info that this chunk has the given field index.
 void setIndex(CGBlockInfo &info, unsigned index, CharUnits offset) {
@@ -213,8 +214,8 @@ namespace {
 info.CXXThisIndex = index;
 info.CXXThisOffset = offset;
   } else {
-info.Captures.insert({Capture->getVariable(),
-  CGBlockInfo::Capture::makeIndex(index, offset)});
+auto C = CGBlockInfo::Capture::makeIndex(index, offset, FieldType);
+info.Captures.insert({Capture->getVariable(), C});
   }
 }
   };
@@ -363,7 +364,7 @@ static void computeBlockInfo(CodeGenModu
 
 layout.push_back(BlockLayoutChunk(tinfo.second, tinfo.first,
   Qualifiers::OCL_None,
-  nullptr, llvmType));
+  nullptr, llvmType, thisType));
   }
 
   // Next, all the block captures.
@@ -380,7 +381,7 @@ static void computeBlockInfo(CodeGenModu
 
   layout.push_back(BlockLayoutChunk(align, CGM.getPointerSize(),
 Qualifiers::OCL_None, &CI,
-CGM.VoidPtrTy));
+CGM.VoidPtrTy, variable->getType()));
   continue;
 }
 
@@ -436,6 +437,14 @@ static void computeBlockInfo(CodeGenModu
 }
 
 QualType VT = variable->getType();
+
+// If the variable is captured by an enclosing block or lambda expression,
+// use the type of the capture field.
+if (CGF->BlockInfo && CI.isNested())
+  VT = CGF->BlockInfo->getCapture(variable).fieldType();
+else if (auto *FD = CGF->LambdaCaptureFields.lookup(variable))
+  VT = FD->getType();
+
 CharUnits size = C.getTypeSizeInChars(VT);
 CharUnits align = C.getDeclAlign(variable);
 
@@ -444,7 +453,8 @@ static void computeBlockInfo(CodeGenModu
 llvm::Type *llvmType =
   CGM.getTypes().ConvertTypeForMem(VT);
 
-layout.push_back(BlockLayoutChunk(align, size, lifetime, &CI, llvmType));
+layout.push_back(
+BlockLayoutChunk(align, size, lifetime, &CI, llvmType, VT));
   }
 
   // If that was everything, we're done here.
@@ -775,7 +785,7 @@ llvm::Value *CodeGenFunction::EmitBlockL
 // Ignore constant captures.
 if (capture.isConstant()) continue;
 
-QualType type = variable->getType();
+QualType type = capture.fieldType();
 
 // This will be a [[type]]*, except that a byref entry will just be
 // an i8**.
@@ -1033,9 +1043,8 @@ Address CodeGenFunction::GetAddrOfBlockD
  variable->getName());
   }
 
-  if (auto refType = variable->getType()->getAs()) {
+  if (auto refType = capture.fieldType()->getAs())
 addr = EmitLoadOfReference(addr, refType);
-  }
 
   return addr;
 }

Modified: cfe/trunk/lib/CodeGen/CGBlocks.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.h?rev=281682&r1=281681&r2=281682&view=diff
==

[libcxx] r281683 - Move inline attributes in filesystem to first declaration

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 19:07:16 2016
New Revision: 281683

URL: http://llvm.org/viewvc/llvm-project?rev=281683&view=rev
Log:
Move inline attributes in filesystem to first declaration

Modified:
libcxx/trunk/include/experimental/filesystem

Modified: libcxx/trunk/include/experimental/filesystem
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/filesystem?rev=281683&r1=281682&r2=281683&view=diff
==
--- libcxx/trunk/include/experimental/filesystem (original)
+++ libcxx/trunk/include/experimental/filesystem Thu Sep 15 19:07:16 2016
@@ -1115,6 +1115,8 @@ public:
 
 private:
 friend class path;
+
+inline _LIBCPP_INLINE_VISIBILITY
 friend bool operator==(const iterator&, const iterator&);
 
 _LIBCPP_FUNC_VIS iterator& __increment();
@@ -1901,6 +1903,7 @@ public:
 { return __increment(&__ec); }
 
 private:
+inline _LIBCPP_INLINE_VISIBILITY
 friend bool operator==(const directory_iterator& __lhs,
const directory_iterator& __rhs) _NOEXCEPT;
 
@@ -2050,6 +2053,7 @@ private:
 _LIBCPP_FUNC_VIS
 void __pop(error_code* __ec=nullptr);
 
+inline _LIBCPP_INLINE_VISIBILITY
 friend bool operator==(const recursive_directory_iterator&,
const recursive_directory_iterator&) _NOEXCEPT;
 
@@ -2059,9 +2063,9 @@ private:
 }; // class recursive_directory_iterator
 
 
-_LIBCPP_INLINE_VISIBILITY
-inline bool operator==(const recursive_directory_iterator& __lhs,
-const recursive_directory_iterator& __rhs) _NOEXCEPT
+inline _LIBCPP_INLINE_VISIBILITY
+bool operator==(const recursive_directory_iterator& __lhs,
+const recursive_directory_iterator& __rhs) _NOEXCEPT
 {
 return __lhs.__imp_ == __rhs.__imp_;
 }


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


[libcxx] r281684 - Use _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY in valarray to support attribute((internal_linkage)).

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 19:13:55 2016
New Revision: 281684

URL: http://llvm.org/viewvc/llvm-project?rev=281684&view=rev
Log:
Use _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY in valarray to support 
attribute((internal_linkage)).

The externally instantiated member functions must be declared using
_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY, not _LIBCPP_INLINE_VISIBILITY, in
order to be properly exported when using __attribute__((internal_linkage)).

Otherwise the explicit instantiations will obviously have internal linkage and
will not be exported from the dylib.

Modified:
libcxx/trunk/include/valarray

Modified: libcxx/trunk/include/valarray
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/valarray?rev=281684&r1=281683&r2=281684&view=diff
==
--- libcxx/trunk/include/valarray (original)
+++ libcxx/trunk/include/valarray Thu Sep 15 19:13:55 2016
@@ -802,8 +802,8 @@ public:
 // construct/destroy:
 _LIBCPP_INLINE_VISIBILITY
 valarray() : __begin_(0), __end_(0) {}
-_LIBCPP_INLINE_VISIBILITY
-inline explicit valarray(size_t __n);
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
+explicit valarray(size_t __n);
 _LIBCPP_INLINE_VISIBILITY
 valarray(const value_type& __x, size_t __n);
 valarray(const value_type* __p, size_t __n);
@@ -819,7 +819,7 @@ public:
 valarray(const gslice_array& __ga);
 valarray(const mask_array& __ma);
 valarray(const indirect_array& __ia);
-inline _LIBCPP_INLINE_VISIBILITY
+inline _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
 ~valarray();
 
 // assignment:


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


[PATCH] D24642: Use __attribute__((internal_linkage)) when available.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF created this revision.
EricWF added reviewers: mclow.lists, eugenis.
EricWF added subscribers: cfe-commits, eugenis.

This patch has been a long time coming (Thanks @eugenis). It changes 
`_LIBCPP_INLINE_VISIBILITY` to use `__attribute__((internal_linkage))` instead 
of `__attribute__((visibility("hidden"), always_inline))`.

The point of `_LIBCPP_INLINE_VISIBILITY` is to prevent inline functions from 
being exported from both the libc++ library and from user libraries. This helps 
libc++ better manage it's ABI.
Previously this was done by forcing inlining and modifying the symbols 
visibility. However inlining isn't guaranteed and symbol visibility only 
affects shared libraries making this an imperfect solution.  `internal_linkage` 
improves this situation by making all symbols local to the TU they are emitted 
in, regardless of inlining or visibility. IIRC the effect of applying 
`__attribute__((internal_linkage))` to an inline function is the same as 
applying `static`.

Most of the work for this patch was done by @eugenis.


https://reviews.llvm.org/D24642

Files:
  include/__config
  src/string.cpp

Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string 
const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
@@ -49,6 +50,7 @@
 #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
 #elif _LIBCPP_ABI_VERSION == 1
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
 #if defined(__FreeBSD__)
@@ -610,15 +612,19 @@
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__))
+# else
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE
 #define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), 
__always_inline__))
 #endif
 
 #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY
-# ifdef _LIBCPP_BUILDING_LIBRARY
+# if defined(_LIBCPP_BUILDING_LIBRARY)
 #   define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY 
__attribute__((__visibility__("default"), __always_inline__))
 # else
 #   define _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY _LIBCPP_INLINE_VISIBILITY


Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   cha

Re: [PATCH] D24642: Use __attribute__((internal_linkage)) when available.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 71579.
EricWF added a comment.

Revert accidental change.


https://reviews.llvm.org/D24642

Files:
  include/__config
  src/string.cpp

Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string 
const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
@@ -49,6 +50,7 @@
 #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
 #elif _LIBCPP_ABI_VERSION == 1
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
 #if defined(__FreeBSD__)
@@ -610,7 +612,11 @@
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__))
+# else
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE


Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
@@ -49,6 +50,7 @@
 #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
 #elif _LIBCPP_ABI_VERSION == 1
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
 #if defined(__FreeBSD__)
@@ -610,7 +612,11 @@
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__))
+# else
+#   define _LIBCPP_INLI

Re: [PATCH] D24584: Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71581.
meikeb added a comment.

Rebase to current commit.


https://reviews.llvm.org/D24584

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  lib/Sema/SemaChecking.cpp
  test/CodeGenObjCXX/lambda-expressions.mm
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: test/CodeGenObjCXX/lambda-expressions.mm
===
--- test/CodeGenObjCXX/lambda-expressions.mm
+++ test/CodeGenObjCXX/lambda-expressions.mm
@@ -4,6 +4,8 @@
 typedef int (^fp)();
 fp f() { auto x = []{ return 3; }; return x; }
 
+// ARC: %[[LAMBDACLASS:.*]] = type { i32 }
+
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [5 x i8] c"copy\00"
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [12 x i8] c"autorelease\00"
 // MRC-LABEL: define i32 ()* @_Z1fv(
@@ -60,6 +62,40 @@
 }
 @end
 
+// ARC: define void @_ZN13LambdaCapture4foo1ERi(i32* dereferenceable(4) %{{.*}})
+// ARC:   %[[CAPTURE0:.*]] = getelementptr inbounds %[[LAMBDACLASS]], %[[LAMBDACLASS]]* %{{.*}}, i32 0, i32 0
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE0]]
+
+// ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_3clEv"(%[[LAMBDACLASS]]* %{{.*}})
+// ARC:   %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>
+// ARC:   %[[CAPTURE1:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE1]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke"
+// ARC:   %[[CAPTURE2:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE2]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke_2"(i8* %{{.*}})
+// ARC:   %[[CAPTURE3:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   %[[V1:.*]] = load i32, i32* %[[CAPTURE3]]
+// ARC:   store i32 %[[V1]], i32* @_ZN13LambdaCapture1iE
+
+namespace LambdaCapture {
+  int i;
+  void foo1(int &a) {
+auto lambda = [a]{
+  auto block1 = ^{
+auto block2 = ^{
+  i = a;
+};
+block2();
+  };
+  block1();
+};
+lambda();
+  }
+}
+
 // ARC-LABEL: define linkonce_odr i32 ()* @_ZZNK13StaticMembersIfE1fMUlvE_clEvENKUlvE_cvU13block_pointerFivEEv
 
 // Check lines for BlockInLambda test below
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3850,7 +3850,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  

Re: [PATCH] D24584: Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71583.
meikeb added a comment.

Try to drop randomly uploaded commit.


https://reviews.llvm.org/D24584

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3850,7 +3850,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else {
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  }
+
+  // We add an offset to a pointer here so we should support an offset as big as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  SourceLocation getLocationOfByte(
+  unsigned ByteNo, const SourceManager &SM

Re: [PATCH] D24584: Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71584.
meikeb added a comment.

Rebase


https://reviews.llvm.org/D24584

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBlocks.h
  lib/Sema/SemaChecking.cpp
  test/CodeGenObjCXX/lambda-expressions.mm
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: test/CodeGenObjCXX/lambda-expressions.mm
===
--- test/CodeGenObjCXX/lambda-expressions.mm
+++ test/CodeGenObjCXX/lambda-expressions.mm
@@ -4,6 +4,8 @@
 typedef int (^fp)();
 fp f() { auto x = []{ return 3; }; return x; }
 
+// ARC: %[[LAMBDACLASS:.*]] = type { i32 }
+
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [5 x i8] c"copy\00"
 // MRC: @OBJC_METH_VAR_NAME{{.*}} = private global [12 x i8] c"autorelease\00"
 // MRC-LABEL: define i32 ()* @_Z1fv(
@@ -60,6 +62,40 @@
 }
 @end
 
+// ARC: define void @_ZN13LambdaCapture4foo1ERi(i32* dereferenceable(4) %{{.*}})
+// ARC:   %[[CAPTURE0:.*]] = getelementptr inbounds %[[LAMBDACLASS]], %[[LAMBDACLASS]]* %{{.*}}, i32 0, i32 0
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE0]]
+
+// ARC: define internal void @"_ZZN13LambdaCapture4foo1ERiENK3$_3clEv"(%[[LAMBDACLASS]]* %{{.*}})
+// ARC:   %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>
+// ARC:   %[[CAPTURE1:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %[[BLOCK]], i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE1]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke"
+// ARC:   %[[CAPTURE2:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   store i32 %{{.*}}, i32* %[[CAPTURE2]]
+
+// ARC: define internal void @"___ZZN13LambdaCapture4foo1ERiENK3$_3clEv_block_invoke_2"(i8* %{{.*}})
+// ARC:   %[[CAPTURE3:.*]] = getelementptr inbounds <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>, <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i32 }>* %{{.*}}, i32 0, i32 5
+// ARC:   %[[V1:.*]] = load i32, i32* %[[CAPTURE3]]
+// ARC:   store i32 %[[V1]], i32* @_ZN13LambdaCapture1iE
+
+namespace LambdaCapture {
+  int i;
+  void foo1(int &a) {
+auto lambda = [a]{
+  auto block1 = ^{
+auto block2 = ^{
+  i = a;
+};
+block2();
+  };
+  block1();
+};
+lambda();
+  }
+}
+
 // ARC-LABEL: define linkonce_odr i32 ()* @_ZZNK13StaticMembersIfE1fMUlvE_clEvENKUlvE_cvU13block_pointerFivEEv
 
 // Check lines for BlockInLambda test below
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3850,7 +3850,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth =

Re: [PATCH] D24584: Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Meike Baumgärtner via cfe-commits
meikeb updated this revision to Diff 71585.
meikeb added a comment.

.


https://reviews.llvm.org/D24584

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/format-strings.c

Index: test/Sema/format-strings.c
===
--- test/Sema/format-strings.c
+++ test/Sema/format-strings.c
@@ -652,3 +652,38 @@
   // expected-note@-1{{treat the string as an argument to avoid this}}
 }
 #pragma GCC diagnostic warning "-Wformat-nonliteral"
+
+void test_char_pointer_arithmetic(int b) {
+  const char s1[] = "string";
+  const char s2[] = "%s string";
+
+  printf(s1 - 1);  // expected-warning {{format string is not a string literal (potentially insecure)}}
+  // expected-note@-1{{treat the string as an argument to avoid this}}
+
+  printf(s1 + 2);  // no-warning
+  printf(s2 + 2);  // no-warning
+
+  const char s3[] = "%s string";
+  printf((s3 + 2) - 2);  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + s2); // no-warning
+  printf(6 + s2 - 2); // no-warning
+  printf(2 + (b ? s1 : s2));  // no-warning
+
+  const char s5[] = "string %s";
+  printf(2 + (b ? s2 : s5));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(2 + (b ? s2 : s5), "");  // no-warning
+  printf(2 + (b ? s1 : s2 - 2), "");  // no-warning
+
+  const char s6[] = "%s string";
+  printf(2 + (b ? s1 : s6 - 2));  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+  printf(1 ? s2 + 2 : s2);  // no-warning
+  printf(0 ? s2 : s2 + 2);  // no-warning
+  printf(2 + s2 + 5 * 3 - 16, "");  // expected-warning{{data argument not used}}
+
+  const char s7[] = "%s string %s %s";
+  printf(s7 + 3, "");  // expected-warning{{more '%' conversions than data arguments}}
+  // expected-note@-2{{format string is defined here}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -3850,7 +3850,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else {
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  }
+
+  // We add an offset to a pointer here so we should support an offset as big as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  SourceLocation getLocationOfByte(
+  unsigned ByteNo, const SourceManager &SM, const LangOptions &Features,
+

r281686 - Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Stephen Hines via cfe-commits
Author: srhines
Date: Thu Sep 15 20:07:04 2016
New Revision: 281686

URL: http://llvm.org/viewvc/llvm-project?rev=281686&view=rev
Log:
Do not warn about format strings that are indexed string literals.

Summary:
The warning for a format string not being a string literal and therefore
being potentially insecure is overly strict for indices into string
literals. This fix checks if the index into the string literal is
precomputable. If that's the case it will check if the suffix of that
string literal is a valid format string string literal. It will still
issue the aforementioned warning for out of range indices into the
string literal.

Patch by Meike Baumgärtner (meikeb)

Reviewers: rsmith

Subscribers: srhines, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/format-strings.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=281686&r1=281685&r2=281686&view=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Sep 15 20:07:04 2016
@@ -3850,7 +3850,95 @@ enum StringLiteralCheckType {
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else {
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  }
+
+  // We add an offset to a pointer here so we should support an offset as big 
as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes 
correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  SourceLocation getLocationOfByte(
+  unsigned ByteNo, const SourceManager &SM, const LangOptions &Features,
+  const TargetInfo &Target, unsigned *StartToken = nullptr,
+  unsigned *StartTokenByteOffset = nullptr) const {
+return FExpr->getLocationOfByte(ByteNo + Offset, SM, Features, Target,
+StartToken, StartTokenByteOffset);
+  }
+
+  SourceLocation getLocStart() const LLVM_READONLY {
+return FExpr->getLocStart().getLocWithOffset(Offset);
+  }
+  SourceLocation getLocEnd() const LLVM_READONLY { return FExpr->getLocEnd(); }
+};
+}  // end anonymous namespace
+
+static void CheckFormatString(Sema &S, const FormatStringLiteral *FExpr,
   const Expr *OrigFormatExpr,
   ArrayRef Args,
   bool HasVAListArg, unsigned format_idx,
@@ -3871,8 +3959,11 @@ checkFormatStringExpr(Sema &S, const Exp
   unsigned firstDataArg, Sema::FormatStringType 

Re: [PATCH] D24584: Do not warn about format strings that are indexed string literals.

2016-09-15 Thread Stephen Hines via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281686: Do not warn about format strings that are indexed 
string literals. (authored by srhines).

Changed prior to commit:
  https://reviews.llvm.org/D24584?vs=71585&id=71586#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24584

Files:
  cfe/trunk/lib/Sema/SemaChecking.cpp
  cfe/trunk/test/Sema/format-strings.c

Index: cfe/trunk/lib/Sema/SemaChecking.cpp
===
--- cfe/trunk/lib/Sema/SemaChecking.cpp
+++ cfe/trunk/lib/Sema/SemaChecking.cpp
@@ -3850,7 +3850,95 @@
 };
 } // end anonymous namespace
 
-static void CheckFormatString(Sema &S, const StringLiteral *FExpr,
+static void sumOffsets(llvm::APSInt &Offset, llvm::APSInt Addend,
+ BinaryOperatorKind BinOpKind,
+ bool AddendIsRight) {
+  unsigned BitWidth = Offset.getBitWidth();
+  unsigned AddendBitWidth = Addend.getBitWidth();
+  // There might be negative interim results.
+  if (Addend.isUnsigned()) {
+Addend = Addend.zext(++AddendBitWidth);
+Addend.setIsSigned(true);
+  }
+  // Adjust the bit width of the APSInts.
+  if (AddendBitWidth > BitWidth) {
+Offset = Offset.sext(AddendBitWidth);
+BitWidth = AddendBitWidth;
+  } else if (BitWidth > AddendBitWidth) {
+Addend = Addend.sext(BitWidth);
+  }
+
+  bool Ov = false;
+  llvm::APSInt ResOffset = Offset;
+  if (BinOpKind == BO_Add)
+ResOffset = Offset.sadd_ov(Addend, Ov);
+  else {
+assert(AddendIsRight && BinOpKind == BO_Sub &&
+   "operator must be add or sub with addend on the right");
+ResOffset = Offset.ssub_ov(Addend, Ov);
+  }
+
+  // We add an offset to a pointer here so we should support an offset as big as
+  // possible.
+  if (Ov) {
+assert(BitWidth <= UINT_MAX / 2 && "index (intermediate) result too big");
+Offset.sext(2 * BitWidth);
+sumOffsets(Offset, Addend, BinOpKind, AddendIsRight);
+return;
+  }
+
+  Offset = ResOffset;
+}
+
+namespace {
+// This is a wrapper class around StringLiteral to support offsetted string
+// literals as format strings. It takes the offset into account when returning
+// the string and its length or the source locations to display notes correctly.
+class FormatStringLiteral {
+  const StringLiteral *FExpr;
+  int64_t Offset;
+
+ public:
+  FormatStringLiteral(const StringLiteral *fexpr, int64_t Offset = 0)
+  : FExpr(fexpr), Offset(Offset) {}
+
+  StringRef getString() const {
+return FExpr->getString().drop_front(Offset);
+  }
+
+  unsigned getByteLength() const {
+return FExpr->getByteLength() - getCharByteWidth() * Offset;
+  }
+  unsigned getLength() const { return FExpr->getLength() - Offset; }
+  unsigned getCharByteWidth() const { return FExpr->getCharByteWidth(); }
+
+  StringLiteral::StringKind getKind() const { return FExpr->getKind(); }
+
+  QualType getType() const { return FExpr->getType(); }
+
+  bool isAscii() const { return FExpr->isAscii(); }
+  bool isWide() const { return FExpr->isWide(); }
+  bool isUTF8() const { return FExpr->isUTF8(); }
+  bool isUTF16() const { return FExpr->isUTF16(); }
+  bool isUTF32() const { return FExpr->isUTF32(); }
+  bool isPascal() const { return FExpr->isPascal(); }
+
+  SourceLocation getLocationOfByte(
+  unsigned ByteNo, const SourceManager &SM, const LangOptions &Features,
+  const TargetInfo &Target, unsigned *StartToken = nullptr,
+  unsigned *StartTokenByteOffset = nullptr) const {
+return FExpr->getLocationOfByte(ByteNo + Offset, SM, Features, Target,
+StartToken, StartTokenByteOffset);
+  }
+
+  SourceLocation getLocStart() const LLVM_READONLY {
+return FExpr->getLocStart().getLocWithOffset(Offset);
+  }
+  SourceLocation getLocEnd() const LLVM_READONLY { return FExpr->getLocEnd(); }
+};
+}  // end anonymous namespace
+
+static void CheckFormatString(Sema &S, const FormatStringLiteral *FExpr,
   const Expr *OrigFormatExpr,
   ArrayRef Args,
   bool HasVAListArg, unsigned format_idx,
@@ -3871,8 +3959,11 @@
   unsigned firstDataArg, Sema::FormatStringType Type,
   Sema::VariadicCallType CallType, bool InFunctionCall,
   llvm::SmallBitVector &CheckedVarArgs,
-  UncoveredArgHandler &UncoveredArg) {
+  UncoveredArgHandler &UncoveredArg,
+  llvm::APSInt Offset) {
  tryAgain:
+  assert(Offset.isSigned() && "invalid offset");
+
   if (E->isTypeDependent() || E->isValueDependent())
 return SLCT_NotALiteral;
 
@@ -3906,23 +3997,28 @@
 CheckLeft = false;
 }
 
+// We need to maintain the offsets for the right and the left hand side
+// separately to check if every possible indexed expression is a valid
+// string literal. They might h

Re: [PATCH] D24642: Use __attribute__((internal_linkage)) when available.

2016-09-15 Thread Evgeniy Stepanov via cfe-commits
eugenis accepted this revision.
eugenis added a comment.
This revision is now accepted and ready to land.

Looks great.
Thank you for seeing it through!


https://reviews.llvm.org/D24642



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


Re: [PATCH] D24639: [Sema] Warn when returning a lambda that captures a local variable by reference

2016-09-15 Thread Richard Smith via cfe-commits
rsmith added a comment.

> But not here, because we would have to verify that the pointer in lam wasn't 
> mutated in a previous call of the lambda:


Isn't that guaranteed, because the lambda is not marked `mutable`?



Comment at: lib/Sema/SemaChecking.cpp:6594
@@ -6590,1 +6593,3 @@
+if (LambdaDecl->isLambda())
+  stackE = EvalVal(RetValExp, refVars, /*ParentDecl=*/nullptr);
   }

I don't think it makes sense to use `EvalVal` for this. `EvalVal` is intended 
to handle the case of a glvalue that is being returned from the function, which 
isn't quite the same thing you want to check here -- I think you would be 
better off instead directly checking the captures of the lambda from here 
(`LambdaDecl` can give you a list) rather than calling this.

It also seems like the `RetValExp` doesn't actually matter at all here in most 
cases. If the closure type captures a local by reference, we should warn, 
regardless of the initialization expression, and likewise if it's not `mutable` 
and captures a local by address through an init-capture. For `mutable` lambdas 
with init-captures that capture by address, perhaps we could do a quick 
localized walk here on the `RetValExp` to see if it's returned directly.


Comment at: lib/Sema/SemaChecking.cpp:6845
@@ -6832,3 +6844,3 @@
const Decl *ParentDecl) {
-  do {
+  for (;;) {
 // We should only be called for evaluating non-pointer expressions, or

We prefer `while (true)` over `for (;;)` (but I agree the existing `do ... 
while (true);` is terrible).


Comment at: lib/Sema/SemaChecking.cpp:6886-6887
@@ -6873,3 +6885,4 @@
 if (V->hasLocalStorage()) {
-  if (!V->getType()->isReferenceType())
+  auto *RD = V->getType()->getAsCXXRecordDecl();
+  if (!V->getType()->isReferenceType() && !(RD && RD->isLambda()))
 return DR;

This is the kind of problem I was worried about. Given:

  auto &f() {
auto lam = [] {};
return lam;
  }

... we'll currently diagnose that we're returning the address of a local, from 
here. But with this change applied, we lose that diagnostic because `EvalVal` 
can't tell the difference between this case (returning by reference) and 
returning the lambda by value.


Comment at: test/SemaCXX/cxx1y-generic-lambdas-capturing.cpp:185
@@ -184,3 +184,3 @@
   f(y, d);
-  f(z, d);
+  f(z, d); // expected-warning {{address of stack memory associated 
with local variable 'z' returned}}
   decltype(a) A = a;

This diagnostic looks like it'll be confusing. Can you add a note pointing at 
the `return` statement in question (we're warning about the one on line 179, I 
assume)?


Comment at: test/SemaCXX/cxx1y-init-captures.cpp:123-124
@@ -122,3 +122,4 @@
   };
-  return M;
+  // FIXME: We shouldn't emit this warning here.
+  return M; // expected-warning{{stack memory}}
 };

Do you know why this happens? It looks like `EvalVal` should bail out on the 
`DeclRefExpr` in the init-capture, because it 
`refersToEnclosingVariableOrCapture`.


Comment at: test/SemaCXX/return-lambda-stack-addr.cpp:68-72
@@ +67,7 @@
+
+auto ref_ref() {
+  int x;
+  int &y = x;  // expected-note{{binding reference variable 'y' 
here}}
+  return [&] { (void)y; }; // expected-warning{{address of stack memory 
associated with local variable 'x' returned}}
+}
+

I'd like to see another testcase for the case when a local reference is safely 
captured by reference:

  auto ref_ref_ok(int &r) {
int &y = r;
return [&] { return y; }; // no warning
  }


https://reviews.llvm.org/D24639



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


[libcxx] r281691 - Move _LIBCPP_INLINE_VISIBILITY to first declaration in sstream.

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 21:09:26 2016
New Revision: 281691

URL: http://llvm.org/viewvc/llvm-project?rev=281691&view=rev
Log:
Move _LIBCPP_INLINE_VISIBILITY to first declaration in sstream.

Modified:
libcxx/trunk/include/sstream

Modified: libcxx/trunk/include/sstream
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/sstream?rev=281691&r1=281690&r2=281691&view=diff
==
--- libcxx/trunk/include/sstream (original)
+++ libcxx/trunk/include/sstream Thu Sep 15 21:09:26 2016
@@ -207,7 +207,9 @@ private:
 
 public:
 // 27.8.1.1 Constructors:
+inline _LIBCPP_INLINE_VISIBILITY
 explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | 
ios_base::out);
+inline _LIBCPP_INLINE_VISIBILITY
 explicit basic_stringbuf(const string_type& __s,
  ios_base::openmode __wch = ios_base::in | 
ios_base::out);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -231,12 +233,12 @@ protected:
 virtual int_type overflow (int_type __c = traits_type::eof());
 virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
  ios_base::openmode __wch = ios_base::in | 
ios_base::out);
+inline _LIBCPP_INLINE_VISIBILITY
 virtual pos_type seekpos(pos_type __sp,
  ios_base::openmode __wch = ios_base::in | 
ios_base::out);
 };
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_stringbuf<_CharT, _Traits, 
_Allocator>::basic_stringbuf(ios_base::openmode __wch)
 : __hm_(0),
   __mode_(__wch)
@@ -245,7 +247,6 @@ basic_stringbuf<_CharT, _Traits, _Alloca
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const 
string_type& __s,
  ios_base::openmode __wch)
 : __hm_(0),
@@ -607,7 +608,6 @@ basic_stringbuf<_CharT, _Traits, _Alloca
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
 basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp,
   ios_base::openmode __wch)
@@ -636,25 +636,31 @@ private:
 
 public:
 // 27.8.2.1 Constructors:
+inline _LIBCPP_INLINE_VISIBILITY
 explicit basic_istringstream(ios_base::openmode __wch = ios_base::in);
+inline _LIBCPP_INLINE_VISIBILITY
 explicit basic_istringstream(const string_type& __s,
  ios_base::openmode __wch = ios_base::in);
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
+inline _LIBCPP_INLINE_VISIBILITY
 basic_istringstream(basic_istringstream&& __rhs);
 
 // 27.8.2.2 Assign and swap:
 basic_istringstream& operator=(basic_istringstream&& __rhs);
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
+inline _LIBCPP_INLINE_VISIBILITY
 void swap(basic_istringstream& __rhs);
 
 // 27.8.2.3 Members:
+inline _LIBCPP_INLINE_VISIBILITY
 basic_stringbuf* rdbuf() const;
+inline _LIBCPP_INLINE_VISIBILITY
 string_type str() const;
+inline _LIBCPP_INLINE_VISIBILITY
 void str(const string_type& __s);
 };
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_istringstream<_CharT, _Traits, 
_Allocator>::basic_istringstream(ios_base::openmode __wch)
 : basic_istream<_CharT, _Traits>(&__sb_),
   __sb_(__wch | ios_base::in)
@@ -662,7 +668,6 @@ basic_istringstream<_CharT, _Traits, _Al
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const 
string_type& __s,
   
ios_base::openmode __wch)
 : basic_istream<_CharT, _Traits>(&__sb_),
@@ -673,7 +678,6 @@ basic_istringstream<_CharT, _Traits, _Al
 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_istringstream<_CharT, _Traits, 
_Allocator>::basic_istringstream(basic_istringstream&& __rhs)
 : basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)),
   __sb_(_VSTD::move(__rhs.__sb_))
@@ -693,9 +697,7 @@ basic_istringstream<_CharT, _Traits, _Al
 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
-void
-basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& 
__rhs)
+void basic_istringstream<_CharT, _Traits, 
_Allocator>::swap(basic_istringstream& __rhs)
 {
 basic_istream::swap(__rhs);
 __sb_.swap(__rhs.__sb_);
@@ -711,7 +713,6 @@ swap(basic_istringstream<_CharT, _Traits
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_stringbuf<_CharT, _Traits, _Allocator>*
 basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const
 {
@@ -719,7 +720,6 @@ basic_istringstream<_CharT, _Traits, _Al
 }
 
 template 
-inline _LIBCPP_INLINE_VISIBILITY
 basic_string<_CharT, _Traits, _Allocator>
 basic_istringstream<_CharT, _Traits, _Allocator>::str() const
 {
@@ -727,9 +727,7 @@ basic_istringstream<_C

[libcxx] r281692 - Move _LIBCPP_INLINE_VISIBILITY to first declaration in

2016-09-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Sep 15 21:16:23 2016
New Revision: 281692

URL: http://llvm.org/viewvc/llvm-project?rev=281692&view=rev
Log:
Move _LIBCPP_INLINE_VISIBILITY to first declaration in 

Modified:
libcxx/trunk/include/experimental/propagate_const

Modified: libcxx/trunk/include/experimental/propagate_const
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/experimental/propagate_const?rev=281692&r1=281691&r2=281692&view=diff
==
--- libcxx/trunk/include/experimental/propagate_const (original)
+++ libcxx/trunk/include/experimental/propagate_const Thu Sep 15 21:16:23 2016
@@ -123,8 +123,14 @@ _LIBCPP_BEGIN_NAMESPACE_LFTS_V2
 
 template 
 class propagate_const;
-template  _LIBCPP_CONSTEXPR const _Up& get_underlying(const 
propagate_const<_Up>& __pu) _NOEXCEPT;
-template  _LIBCPP_CONSTEXPR _Up& 
get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT;
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+const _Up& get_underlying(const propagate_const<_Up>& __pu) _NOEXCEPT;
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
+_Up& get_underlying(propagate_const<_Up>& __pu) _NOEXCEPT;
 
 template 
 class propagate_const
@@ -462,14 +468,12 @@ _LIBCPP_CONSTEXPR void swap(propagate_co
 }
 
 template 
-_LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR const _Tp& get_underlying(const propagate_const<_Tp>& __pt) 
_NOEXCEPT
 {
   return __pt.__t_;
 }
 
 template 
-_LIBCPP_INLINE_VISIBILITY
 _LIBCPP_CONSTEXPR _Tp& get_underlying(propagate_const<_Tp>& __pt) _NOEXCEPT
 {
   return __pt.__t_;


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


Re: [PATCH] D24642: Use __attribute__((internal_linkage)) when available.

2016-09-15 Thread Eric Fiselier via cfe-commits
EricWF updated this revision to Diff 71590.
EricWF added a comment.

- Add `always_inline` to _LIBCPP_INLINE_VISIBILITY. In future I think only 
_LIBCPP_ALWAYS_INLINE should actually apply `always_inline`, but I'll make that 
change separately.
- Change `_LIBCPP_ALWAYS_INLINE` to use `internal_linkage` as well.


https://reviews.llvm.org/D24642

Files:
  include/__config
  src/string.cpp

Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string 
const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
@@ -49,6 +50,7 @@
 #define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
 #define _LIBCPP_ABI_VARIADIC_LOCK_GUARD
 #elif _LIBCPP_ABI_VERSION == 1
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 1
 // Feature macros for disabling pre ABI v1 features. All of these options
 // are deprecated.
 #if defined(__FreeBSD__)
@@ -610,11 +612,19 @@
 #endif
 
 #ifndef _LIBCPP_INLINE_VISIBILITY
-#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__((__internal_linkage__, 
__always_inline__))
+# else
+#   define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_ALWAYS_INLINE
-#define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# if __has_attribute(__internal_linkage__)
+#   define _LIBCPP_ALWAYS_INLINE __attribute__((__internal_linkage__, 
__always_inline__))
+# else
+#   define _LIBCPP_ALWAYS_INLINE  __attribute__ ((__visibility__("hidden"), 
__always_inline__))
+# endif
 #endif
 
 #ifndef _LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY


Index: src/string.cpp
===
--- src/string.cpp
+++ src/string.cpp
@@ -29,6 +29,29 @@
 string
 operator+, allocator >(char const*, string const&);
 
+// These external instantiations are required to maintain dylib compatibility
+// for ABI v1 when using __attribute__((internal_linkage)) as opposed to
+// __attribute__((visibility("hidden"), always_inline)).
+#if _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION == 1
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string::iterator
+basic_string::insert(basic_string::const_iterator,
+  wchar_t const *, wchar_t const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   char const *, char const *);
+
+template basic_string &
+basic_string::replace(basic_string::const_iterator,
+   basic_string::const_iterator,
+   wchar_t const *, wchar_t const *);
+#endif // _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION
+
 namespace
 {
 
Index: include/__config
===
--- include/__config
+++ include/__config
@@ -34,6 +34,7 @@
 #endif
 
 #if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
+#define _LIBCPP_ABI_EXTERN_TEMPLATE_SYMBOLS_VERSION 2
 // Change short string representation so that string data starts at offset 0,
 // improving its alignment in some cases.
 #define _LIBCPP_ABI_ALTERNATE_STRIN

  1   2   >