[PATCH] D37057: [clang] Require address space to be specified when creating functions (3/3)

2017-12-09 Thread Dylan McKay via Phabricator via cfe-commits
dylanmckay updated this revision to Diff 126270.
dylanmckay added a comment.

Rebase on trunk


Repository:
  rC Clang

https://reviews.llvm.org/D37057

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/CodeGen/CGCUDANV.cpp
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGException.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGGPUBuiltin.cpp
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCGNU.cpp
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp

Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -8974,7 +8974,7 @@
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
   auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
-   &CGF.CGM.getModule());
+   CGF.CGM.getModule());
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);
   auto &Builder = CGF.Builder;
@@ -9032,7 +9032,7 @@
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
   auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, Name,
-   &CGF.CGM.getModule());
+   CGF.CGM.getModule());
   F->addFnAttr("enqueued-block");
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1928,7 +1928,7 @@
   llvm::FunctionType *ThunkTy = CGM.getTypes().GetFunctionType(FnInfo);
   llvm::Function *ThunkFn =
   llvm::Function::Create(ThunkTy, llvm::Function::ExternalLinkage,
- ThunkName.str(), &CGM.getModule());
+ ThunkName.str(), CGM.getModule());
   assert(ThunkFn->getName() == ThunkName && "name was uniqued!");
 
   ThunkFn->setLinkage(MD->isExternallyVisible()
@@ -3856,7 +3856,7 @@
   const CXXRecordDecl *RD = CD->getParent();
   QualType RecordTy = getContext().getRecordType(RD);
   llvm::Function *ThunkFn = llvm::Function::Create(
-  ThunkTy, getLinkageForRTTI(RecordTy), ThunkName.str(), &CGM.getModule());
+  ThunkTy, getLinkageForRTTI(RecordTy), ThunkName.str(), CGM.getModule());
   ThunkFn->setCallingConv(static_cast(
   FnInfo.getEffectiveCallingConvention()));
   if (ThunkFn->isWeakForLinker())
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -2291,7 +2291,7 @@
   llvm::FunctionType *FnTy = CGM.getTypes().GetFunctionType(FI);
   llvm::Function *Wrapper =
   llvm::Function::Create(FnTy, getThreadLocalWrapperLinkage(VD, CGM),
- WrapperName.str(), &CGM.getModule());
+ WrapperName.str(), CGM.getModule());
 
   CGM.SetLLVMFunctionAttributes(nullptr, FI, Wrapper);
 
@@ -2398,7 +2398,7 @@
   llvm::FunctionType *FnTy = llvm::FunctionType::get(CGM.VoidTy, false);
   Init = llvm::Function::Create(FnTy,
 llvm::GlobalVariable::ExternalWeakLinkage,
-InitFnName.str(), &CGM.getModule());
+InitFnName.str(), CGM.getModule());
   const CGFunctionInfo &FI = CGM.getTypes().arrangeNullaryFunction();
   CGM.SetLLVMFunctionAttributes(nullptr, FI, cast(Init));
 }
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2124,7 +2124,7 @@
 
   llvm::Function *F =
   llvm::Function::Create(FTy, llvm::Function::ExternalLinkage,
- Entry ? StringRef() : MangledName, &getModule());
+ Entry ? StringRef() : MangledName, getModule());
 
   // If we already created a function with the same mangled name (but different
   // type) before, take its name and add it to the list of functions to be
Index: lib/CodeGen/CGStmtOpenMP.cpp
===
--- lib/CodeGen/CGStmtOpenMP.cpp
+++ lib/CodeGen/CGStmtOpenMP.cpp
@@ -389,7 +389,7 @@
 
   llvm::Function *F =
   llvm::Function::Create(FuncLLVMTy, llvm::GlobalValue::InternalLinkage,
- FO.FunctionName, &CGM.getModule());
+ FO.FunctionName, CG

r320250 - Switch to gnu++14 as the default dialect.

2017-12-09 Thread Tim Northover via cfe-commits
Author: tnorthover
Date: Sat Dec  9 04:09:54 2017
New Revision: 320250

URL: http://llvm.org/viewvc/llvm-project?rev=320250&view=rev
Log:
Switch to gnu++14 as the default dialect.

This is C++14 with conforming GNU extensions.

Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGenCXX/new-overflow.cpp
cfe/trunk/test/CodeGenCXX/new.cpp
cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
cfe/trunk/test/Lexer/cxx-features.cpp
cfe/trunk/test/Lexer/half-literal.cpp
cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_reduction_codegen.cpp
cfe/trunk/test/Parser/cxx1z-nested-namespace-definition.cpp
cfe/trunk/test/SemaCXX/new-array-size-conv.cpp
cfe/trunk/test/SemaCXX/new-delete.cpp
cfe/trunk/test/SemaCXX/unknown-type-name.cpp
cfe/trunk/test/SemaTemplate/class-template-decl.cpp
cfe/trunk/test/SemaTemplate/explicit-instantiation.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=320250&r1=320249&r2=320250&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Sat Dec  9 04:09:54 2017
@@ -176,7 +176,10 @@ C11 Feature Support
 C++ Language Changes in Clang
 -
 
-...
+- Clang's default C++ dialect is now ``gnu++14`` instead of ``gnu++98``. This
+  means Clang will by default accept code using features from C++14 and
+  conforming GNU extensions. Projects incompatible with C++14 can add
+  ``-std=gnu++98`` to their build settings to restore the previous behaviour.
 
 C++1z Feature Support
 ^

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=320250&r1=320249&r2=320250&view=diff
==
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Dec  9 04:09:54 2017
@@ -1729,11 +1729,7 @@ void CompilerInvocation::setLangDefaults
   break;
 case InputKind::CXX:
 case InputKind::ObjCXX:
-  // The PS4 uses C++11 as the default C++ standard.
-  if (T.isPS4())
-LangStd = LangStandard::lang_gnucxx11;
-  else
-LangStd = LangStandard::lang_gnucxx98;
+  LangStd = LangStandard::lang_gnucxx14;
   break;
 case InputKind::RenderScript:
   LangStd = LangStandard::lang_c99;

Modified: cfe/trunk/test/CodeGenCXX/new-overflow.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new-overflow.cpp?rev=320250&r1=320249&r2=320250&view=diff
==
--- cfe/trunk/test/CodeGenCXX/new-overflow.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new-overflow.cpp Sat Dec  9 04:09:54 2017
@@ -85,9 +85,7 @@ namespace test4 {
 
   // CHECK:define [[A:%.*]]* @_ZN5test44testEs(i16 signext
   // CHECK:  [[N:%.*]] = sext i16 {{%.*}} to i32
-  // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0
-  // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]]
-  // CHECK-NEXT: call i8* @_Znaj(i32 [[T1]])
+  // CHECK-NEXT: call i8* @_Znaj(i32 [[N]])
   // CHECK:  getelementptr inbounds {{.*}}, i32 [[N]]
   elt *test(short s) {
 return new elt[s];
@@ -104,9 +102,7 @@ namespace test5 {
 
   // CHECK:define [[A:%.*]]* @_ZN5test54testEi(i32
   // CHECK:  [[N:%.*]] = load i32, i32*
-  // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0
-  // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]]
-  // CHECK-NEXT: call i8* @_Znaj(i32 [[T1]])
+  // CHECK-NEXT: call i8* @_Znaj(i32 [[N]])
   // CHECK:  getelementptr inbounds {{.*}}, i32 [[N]]
   elt *test(int s) {
 return new elt[s];
@@ -169,13 +165,11 @@ namespace test8 {
 
   // CHECK:define [[A:%.*]]* @_ZN5test84testEx(i64
   // CHECK:  [[N:%.*]] = load i64, i64*
-  // CHECK-NEXT: [[T0:%.*]] = icmp uge i64 [[N]], 4294967296
   // CHECK-NEXT: [[T1:%.*]] = trunc i64 [[N]] to i32
   // CHECK-NEXT: [[T2:%.*]] = call { i32, i1 } 
@llvm.umul.with.overflow.i32(i32 [[T1]], i32 4)
   // CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 1
-  // CHECK-NEXT: [[T4:%.*]] = or i1 [[T0]], [[T3]]
   // CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T2]], 0
-  // CHECK-NEXT: [[T6:%.*]] = select i1 [[T4]], i32 -1, i32 [[T5]]
+  // CHECK-NEXT: [[T6:%.*]] = select i1 [[T3]], i32 -1, i32 [[T5]]
   // CHECK-NEXT: call i8* @_Znaj(i32 [[T6]])
   // CHECK:  getelementptr inbounds {{.*}}, i32 [[T1]]
   elt *test(long long s) {
@@ -194,13 +188,11 @@ namespace test9 {
 
   // CHECK:define [[A:%.*]]* @_ZN5test94testEy(i64
   // CHECK:  [[N:%.*]] = load i64, i64*
-  // CHECK-NEXT: [[T0:%.*]] = icmp uge i64 [[N]], 4294967296
   // 

[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-12-09 Thread Ben Craig via Phabricator via cfe-commits
bcraig updated this revision to Diff 126275.
bcraig added a comment.

Rebased


https://reviews.llvm.org/D32411

Files:
  CMakeLists.txt
  docs/DesignDocs/IncludeNextEmulation.rst
  include/__config
  include/__config_site.in
  include/complex.h
  include/cstddef
  include/ctype.h
  include/errno.h
  include/float.h
  include/inttypes.h
  include/limits.h
  include/locale.h
  include/math.h
  include/setjmp.h
  include/stdbool.h
  include/stddef.h
  include/stdint.h
  include/stdio.h
  include/stdlib.h
  include/string.h
  include/wchar.h
  include/wctype.h
  utils/libcxx/test/config.py

Index: utils/libcxx/test/config.py
===
--- utils/libcxx/test/config.py
+++ utils/libcxx/test/config.py
@@ -670,6 +670,8 @@
 self.cxx.compile_flags += [define]
 if m == '_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS':
 continue
+if m.startswith('_LIBCPP_INCLUDE_NEXT'):
+continue
 if m == '_LIBCPP_ABI_VERSION':
 self.config.available_features.add('libcpp-abi-version-v%s'
 % feature_macros[m])
Index: include/wctype.h
===
--- include/wctype.h
+++ include/wctype.h
@@ -51,7 +51,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(wctype.h)
+#else
 #include_next 
+#endif
 
 #ifdef __cplusplus
 
Index: include/wchar.h
===
--- include/wchar.h
+++ include/wchar.h
@@ -14,7 +14,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(wchar.h)
+#else
 #include_next 
+#endif
 
 #elif !defined(_LIBCPP_WCHAR_H)
 #define _LIBCPP_WCHAR_H
@@ -116,7 +120,11 @@
 #define __CORRECT_ISO_CPP_WCHAR_H_PROTO
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(wchar.h)
+#else
 #include_next 
+#endif
 
 // Determine whether we have const-correct overloads for wcschr and friends.
 #if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
Index: include/string.h
===
--- include/string.h
+++ include/string.h
@@ -58,7 +58,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(string.h)
+#else
 #include_next 
+#endif
 
 // MSVCRT, GNU libc and its derivates may already have the correct prototype in
 // . This macro can be defined by users if their C library provides
Index: include/stdlib.h
===
--- include/stdlib.h
+++ include/stdlib.h
@@ -14,7 +14,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stdlib.h)
+#else
 #include_next 
+#endif
 
 #elif !defined(_LIBCPP_STDLIB_H)
 #define _LIBCPP_STDLIB_H
@@ -91,7 +95,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stdlib.h)
+#else
 #include_next 
+#endif
 
 #ifdef __cplusplus
 
Index: include/stdio.h
===
--- include/stdio.h
+++ include/stdio.h
@@ -14,7 +14,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stdio.h)
+#else
 #include_next 
+#endif
 
 #elif !defined(_LIBCPP_STDIO_H)
 #define _LIBCPP_STDIO_H
@@ -105,7 +109,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stdio.h)
+#else
 #include_next 
+#endif
 
 #ifdef __cplusplus
 
Index: include/stdint.h
===
--- include/stdint.h
+++ include/stdint.h
@@ -116,6 +116,10 @@
 #   define __STDC_CONSTANT_MACROS
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_VC(stdint.h)
+#else
 #include_next 
+#endif
 
 #endif  // _LIBCPP_STDINT_H
Index: include/stddef.h
===
--- include/stddef.h
+++ include/stddef.h
@@ -15,7 +15,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stddef.h)
+#else
 #include_next 
+#endif
 
 #elif !defined(_LIBCPP_STDDEF_H)
 #define _LIBCPP_STDDEF_H
@@ -43,7 +47,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_UCRT(stddef.h)
+#else
 #include_next 
+#endif
 
 #ifdef __cplusplus
 
Index: include/stdbool.h
===
--- include/stdbool.h
+++ include/stdbool.h
@@ -26,7 +26,11 @@
 #pragma GCC system_header
 #endif
 
+#if defined(_LIBCPP_HAS_NO_INCLUDE_NEXT)
+#include _LIBCPP_INCLUDE_NEXT_VC(stdbool.h)
+#else
 #include_next 

[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-09 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter created this revision.

Fixes #35578.


https://reviews.llvm.org/D41048

Files:
  include/tuple


Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -1012,10 +1012,21 @@
 
 template 
 struct __find_exactly_one_checked {
-  static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+#if defined(__clang__) && __clang_major__ > 5 && __cplusplus > 201402L
+// Workaround https://bugs.llvm.org/show_bug.cgi?id=28385
+inline _LIBCPP_INLINE_VISIBILITY
+static constexpr size_t __index()
+{
+constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+return __find_detail::__find_idx(0, __matches);
+}
+static constexpr size_t value = __index();
+#else
+static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
-static_assert (value != __not_found, "type not found in type list" );
-static_assert(value != __ambiguous,"type occurs more than once in type 
list");
+#endif
+static_assert(value != __not_found, "type not found in type list" );
+static_assert(value != __ambiguous, "type occurs more than once in type 
list");
 };
 
 template 


Index: include/tuple
===
--- include/tuple
+++ include/tuple
@@ -1012,10 +1012,21 @@
 
 template 
 struct __find_exactly_one_checked {
-  static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+#if defined(__clang__) && __clang_major__ > 5 && __cplusplus > 201402L
+// Workaround https://bugs.llvm.org/show_bug.cgi?id=28385
+inline _LIBCPP_INLINE_VISIBILITY
+static constexpr size_t __index()
+{
+constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
+return __find_detail::__find_idx(0, __matches);
+}
+static constexpr size_t value = __index();
+#else
+static constexpr bool __matches[] = {is_same<_T1, _Args>::value...};
 static constexpr size_t value = __find_detail::__find_idx(0, __matches);
-static_assert (value != __not_found, "type not found in type list" );
-static_assert(value != __ambiguous,"type occurs more than once in type list");
+#endif
+static_assert(value != __not_found, "type not found in type list" );
+static_assert(value != __ambiguous, "type occurs more than once in type list");
 };
 
 template 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-09 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Test?


https://reviews.llvm.org/D41048



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


[PATCH] D41048: [libcxx] workaround PR 28385 in __find_exactly_one_checked

2017-12-09 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added a comment.

In https://reviews.llvm.org/D41048#950424, @lebedev.ri wrote:

> Test?


Four of the existing variant tests fail without this change (Using the clang-6 
dailies from apt.llvm.org and -std=c++2a):

Failing Tests (4):

libc++ :: std/utilities/variant/variant.get/get_if_type.pass.cpp
libc++ :: std/utilities/variant/variant.get/get_type.pass.cpp
libc++ :: std/utilities/variant/variant.get/holds_alternative.pass.cpp
libc++ :: 
std/utilities/variant/variant.variant/variant.mod/emplace_type_init_list_args.pass.cpp
  
  Expected Passes: 36
  Unexpected Failures: 4

I think that's plenty of test coverage.


https://reviews.llvm.org/D41048



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


[PATCH] D30691: [analyzer] Support for naive cross translational unit analysis

2017-12-09 Thread George Karpenkov via Phabricator via cfe-commits
george.karpenkov added a comment.

Python part looks good to me. I don't know whether @dcoughlin or @NoQ would 
want to insert additional comments on C++ parts.


https://reviews.llvm.org/D30691



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


[PATCH] D41050: Fix over-release of return value of lambda implicitly converted to block

2017-12-09 Thread Dan Zimmerman via Phabricator via cfe-commits
danzimm created this revision.
Herald added subscribers: cfe-commits, kosarev.

Clang has a pretty cool feature right now that will allow you to use a lambda 
as a block. Unfortunately there's a bug in this conversion if the return value 
of the block is an ObjC object and arc is enabled -- the return value gets 
over-released. An example of this causing a crash that shouldn't occur can be 
seen below:

  typedef id (^Go)();
  
  int main() {
Go g = []() -> id {
  return [NSObject new];
};
id sss = nil;
@autoreleasepool {
  id ss = g();
  sss = ss;
}
NSLog(@"%@", sss);
return 0;
  }

It looks like when a lambda is auto-converted to a block it generates a block 
that just wraps the lambda and forwards all args to it and the return value of 
the lambda back to be the return value of the block. Currently if the block 
returns an ObjC object both the lambda that's generated and the block that 
wraps it autorelease the return value, which effectively over-releases the 
return value. There are a few options that I considered and one that stuck out 
to me:

1. Add a retain call on the return value after invoking the enclosed lambda -- 
this way we maintain proper retain count
2. Stop autoreleasing the return value of the lambda
3. Stop autoreleasing the return value of the block

I opted against the first case since it would mean unnecessary extra reference 
count churn. I didn't see an easy way to implement the second option as the 
enclosing lambda is generated as a global function definition, without the 
metadata that a block encloses it (and thus there's no easy way that I could 
see to differentiate the lambda-converted-to-block function definition from 
other global function definitions). Thus I came to the third option which is 
easily implementable since the codegen for blocks must recognize whether or not 
it encloses a lambda (as it changes what it generates if it does).

The test I wrote relies on the optimizer inlining the lambda invocation -- I'm 
not sure if that's an ok assumption to make. The IR generated previous to this 
patch is kind of fun:

  define internal i8* @___Z5test0P11objc_object_block_invoke(i8* nocapture 
readonly %.block_descriptor) #0 {
  entry:
%block.capture.addr = getelementptr inbounds i8, i8* %.block_descriptor, 
i64 32
%0 = bitcast i8* %block.capture.addr to i8**
%1 = load i8*, i8** %0, align 8, !tbaa !7
%2 = tail call i8* @objc_retain(i8* %1) #2
%3 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) #2
%4 = tail call i8* @objc_autoreleaseReturnValue(i8* %1) #2
ret i8* %1
  }


Repository:
  rC Clang

https://reviews.llvm.org/D41050

Files:
  lib/CodeGen/CGBlocks.cpp
  test/CodeGenObjCXX/arc-block-lambda-conversion.mm


Index: test/CodeGenObjCXX/arc-block-lambda-conversion.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/arc-block-lambda-conversion.mm
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -std=c++11 -O2 -o - %s | FileCheck %s
+
+void test0(id x) {
+  extern void test0_helper(id (^)(void));
+  test0_helper([=]() { return x; });
+  // CHECK-LABEL: define internal i8* @___Z5test0P11objc_object_block_invoke
+  // CHECK: {{%.*}} = tail call i8* @objc_retain(i8* [[T0:%.*]])
+  // CHECK-NEXT: {{%.*}} = tail call i8* @objc_autoreleaseReturnValue(i8* 
[[T0]])
+  // CHECK-NEXT: ret i8* [[T0]]
+}
Index: lib/CodeGen/CGBlocks.cpp
===
--- lib/CodeGen/CGBlocks.cpp
+++ lib/CodeGen/CGBlocks.cpp
@@ -1450,9 +1450,12 @@
   llvm::BasicBlock::iterator entry_ptr = Builder.GetInsertPoint();
   --entry_ptr;
 
-  if (IsLambdaConversionToBlock)
+  if (IsLambdaConversionToBlock) {
+// The lambda that's generated will emit a call to
+// objc_autoreleaseReturnValue for us if necessary
+AutoreleaseResult = false;
 EmitLambdaBlockInvokeBody();
-  else {
+  } else {
 PGO.assignRegionCounters(GlobalDecl(blockDecl), fn);
 incrementProfileCounter(blockDecl->getBody());
 EmitStmt(blockDecl->getBody());


Index: test/CodeGenObjCXX/arc-block-lambda-conversion.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/arc-block-lambda-conversion.mm
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.12.0 -emit-llvm -fblocks -fobjc-arc -fobjc-runtime-has-weak -std=c++11 -O2 -o - %s | FileCheck %s
+
+void test0(id x) {
+  extern void test0_helper(id (^)(void));
+  test0_helper([=]() { return x; });
+  // CHECK-LABEL: define internal i8* @___Z5test0P11objc_object_block_invoke
+  // CHECK: {{%.*}} = tail call i8* @objc_retain(i8* [[T0:%.*]])
+  // CHECK-NEXT: {{%.*}} = tail call i8* @objc_autoreleaseReturnValue(i8* [[T0]])
+  // CHECK-NEXT: ret i8* [[T0]]
+}
Index: lib/CodeGen/CGBlocks.cpp
=

[PATCH] D41050: Fix over-release of return value of lambda implicitly converted to block

2017-12-09 Thread Xin Tong via Phabricator via cfe-commits
trentxintong added a comment.

@gottesmm can you please take a look ? Thanks.


Repository:
  rC Clang

https://reviews.llvm.org/D41050



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


r320271 - Update Clang CMake cache to use cxx-headers, NFC

2017-12-09 Thread Duncan P. N. Exon Smith via cfe-commits
Author: dexonsmith
Date: Sat Dec  9 15:44:42 2017
New Revision: 320271

URL: http://llvm.org/viewvc/llvm-project?rev=320271&view=rev
Log:
Update Clang CMake cache to use cxx-headers, NFC

Apparently libcxx-headers is going away.  Fixes PR35584.

Modified:
cfe/trunk/cmake/caches/Apple-stage2.cmake

Modified: cfe/trunk/cmake/caches/Apple-stage2.cmake
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/cmake/caches/Apple-stage2.cmake?rev=320271&r1=320270&r2=320271&view=diff
==
--- cfe/trunk/cmake/caches/Apple-stage2.cmake (original)
+++ cfe/trunk/cmake/caches/Apple-stage2.cmake Sat Dec  9 15:44:42 2017
@@ -61,7 +61,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
   LTO
   clang-format
   clang-headers
-  libcxx-headers
+  cxx-headers
   ${LLVM_TOOLCHAIN_TOOLS}
   CACHE STRING "")
 


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


Re: r320250 - Switch to gnu++14 as the default dialect.

2017-12-09 Thread Richard Smith via cfe-commits
Thank you and everyone else who has helped to make this happen!

On 9 Dec 2017 04:10, "Tim Northover via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> Author: tnorthover
> Date: Sat Dec  9 04:09:54 2017
> New Revision: 320250
>
> URL: http://llvm.org/viewvc/llvm-project?rev=320250&view=rev
> Log:
> Switch to gnu++14 as the default dialect.
>
> This is C++14 with conforming GNU extensions.
>
> Modified:
> cfe/trunk/docs/ReleaseNotes.rst
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> cfe/trunk/test/CodeGenCXX/new-overflow.cpp
> cfe/trunk/test/CodeGenCXX/new.cpp
> cfe/trunk/test/CodeGenCXX/vtable-available-externally.cpp
> cfe/trunk/test/Lexer/cxx-features.cpp
> cfe/trunk/test/Lexer/half-literal.cpp
> cfe/trunk/test/OpenMP/taskloop_reduction_codegen.cpp
> cfe/trunk/test/OpenMP/taskloop_simd_reduction_codegen.cpp
> cfe/trunk/test/Parser/cxx1z-nested-namespace-definition.cpp
> cfe/trunk/test/SemaCXX/new-array-size-conv.cpp
> cfe/trunk/test/SemaCXX/new-delete.cpp
> cfe/trunk/test/SemaCXX/unknown-type-name.cpp
> cfe/trunk/test/SemaTemplate/class-template-decl.cpp
> cfe/trunk/test/SemaTemplate/explicit-instantiation.cpp
>
> Modified: cfe/trunk/docs/ReleaseNotes.rst
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/
> ReleaseNotes.rst?rev=320250&r1=320249&r2=320250&view=diff
> 
> ==
> --- cfe/trunk/docs/ReleaseNotes.rst (original)
> +++ cfe/trunk/docs/ReleaseNotes.rst Sat Dec  9 04:09:54 2017
> @@ -176,7 +176,10 @@ C11 Feature Support
>  C++ Language Changes in Clang
>  -
>
> -...
> +- Clang's default C++ dialect is now ``gnu++14`` instead of ``gnu++98``.
> This
> +  means Clang will by default accept code using features from C++14 and
> +  conforming GNU extensions. Projects incompatible with C++14 can add
> +  ``-std=gnu++98`` to their build settings to restore the previous
> behaviour.
>
>  C++1z Feature Support
>  ^
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/
> Frontend/CompilerInvocation.cpp?rev=320250&r1=320249&r2=320250&view=diff
> 
> ==
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Dec  9 04:09:54 2017
> @@ -1729,11 +1729,7 @@ void CompilerInvocation::setLangDefaults
>break;
>  case InputKind::CXX:
>  case InputKind::ObjCXX:
> -  // The PS4 uses C++11 as the default C++ standard.
> -  if (T.isPS4())
> -LangStd = LangStandard::lang_gnucxx11;
> -  else
> -LangStd = LangStandard::lang_gnucxx98;
> +  LangStd = LangStandard::lang_gnucxx14;
>break;
>  case InputKind::RenderScript:
>LangStd = LangStandard::lang_c99;
>
> Modified: cfe/trunk/test/CodeGenCXX/new-overflow.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
> CodeGenCXX/new-overflow.cpp?rev=320250&r1=320249&r2=320250&view=diff
> 
> ==
> --- cfe/trunk/test/CodeGenCXX/new-overflow.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/new-overflow.cpp Sat Dec  9 04:09:54 2017
> @@ -85,9 +85,7 @@ namespace test4 {
>
>// CHECK:define [[A:%.*]]* @_ZN5test44testEs(i16 signext
>// CHECK:  [[N:%.*]] = sext i16 {{%.*}} to i32
> -  // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0
> -  // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]]
> -  // CHECK-NEXT: call i8* @_Znaj(i32 [[T1]])
> +  // CHECK-NEXT: call i8* @_Znaj(i32 [[N]])
>// CHECK:  getelementptr inbounds {{.*}}, i32 [[N]]
>elt *test(short s) {
>  return new elt[s];
> @@ -104,9 +102,7 @@ namespace test5 {
>
>// CHECK:define [[A:%.*]]* @_ZN5test54testEi(i32
>// CHECK:  [[N:%.*]] = load i32, i32*
> -  // CHECK-NEXT: [[T0:%.*]] = icmp slt i32 [[N]], 0
> -  // CHECK-NEXT: [[T1:%.*]] = select i1 [[T0]], i32 -1, i32 [[N]]
> -  // CHECK-NEXT: call i8* @_Znaj(i32 [[T1]])
> +  // CHECK-NEXT: call i8* @_Znaj(i32 [[N]])
>// CHECK:  getelementptr inbounds {{.*}}, i32 [[N]]
>elt *test(int s) {
>  return new elt[s];
> @@ -169,13 +165,11 @@ namespace test8 {
>
>// CHECK:define [[A:%.*]]* @_ZN5test84testEx(i64
>// CHECK:  [[N:%.*]] = load i64, i64*
> -  // CHECK-NEXT: [[T0:%.*]] = icmp uge i64 [[N]], 4294967296
>// CHECK-NEXT: [[T1:%.*]] = trunc i64 [[N]] to i32
>// CHECK-NEXT: [[T2:%.*]] = call { i32, i1 }
> @llvm.umul.with.overflow.i32(i32 [[T1]], i32 4)
>// CHECK-NEXT: [[T3:%.*]] = extractvalue { i32, i1 } [[T2]], 1
> -  // CHECK-NEXT: [[T4:%.*]] = or i1 [[T0]], [[T3]]
>// CHECK-NEXT: [[T5:%.*]] = extractvalue { i32, i1 } [[T2]], 0
> -  // CHECK-NEXT: [[T6:%.*]] = select i1 [[T4]], i32 -1, i32 [[T5]]
> +  // CHECK-NEXT: [[T6:%.*]] = select i1 [[T3]]

[PATCH] D41054: Teach clang/NetBSD about additional dependencies for sanitizers

2017-12-09 Thread Kamil Rytarowski via Phabricator via cfe-commits
krytarowski created this revision.
krytarowski added a project: Sanitizers.

Sanitizers on NetBSD require additional linkage:

- libutil for forkpty(3)
- libexecinfo for backtrace(3)

Sponsored by 


Repository:
  rL LLVM

https://reviews.llvm.org/D41054

Files:
  lib/Driver/ToolChains/CommonArgs.cpp


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -549,6 +549,12 @@
   TC.getTriple().getOS() != llvm::Triple::NetBSD &&
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
+  // Required for forkpty on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lutil");
+  // Required for backtrace on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lexecinfo");
 }
 
 static void


Index: lib/Driver/ToolChains/CommonArgs.cpp
===
--- lib/Driver/ToolChains/CommonArgs.cpp
+++ lib/Driver/ToolChains/CommonArgs.cpp
@@ -549,6 +549,12 @@
   TC.getTriple().getOS() != llvm::Triple::NetBSD &&
   TC.getTriple().getOS() != llvm::Triple::RTEMS)
 CmdArgs.push_back("-ldl");
+  // Required for forkpty on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lutil");
+  // Required for backtrace on some OSes
+  if (TC.getTriple().getOS() == llvm::Triple::NetBSD)
+CmdArgs.push_back("-lexecinfo");
 }
 
 static void
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41055: [debuginfo-tests] Add support for moving debuginfo-tests from clang/test to llvm/projects or monorepo.

2017-12-09 Thread Don Hinton via Phabricator via cfe-commits
hintonda created this revision.
Herald added subscribers: cfe-commits, JDevlieghere, mgorny.

The new version of debuginfo-tests will have it's own
lit.cfg.py file which is incompatible with the one in clang/test.
This change supports both the old and new versions, and can be used
until the bots actually move debuginfo-tests to either clang/test or
the monorepo.

This is a prerequisite for https://reviews.llvm.org/D40971.


Repository:
  rC Clang

https://reviews.llvm.org/D41055

Files:
  test/CMakeLists.txt
  test/lit.cfg.py


Index: test/lit.cfg.py
===
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -58,12 +58,20 @@
 
 tools = [
 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt',
-ToolSubst('%test_debuginfo', command=os.path.join(
-config.llvm_src_root, 'utils', 'test_debuginfo.pl')),
 ToolSubst('%clang_func_map', command=FindTool(
 'clang-func-mapping'), unresolved='ignore'),
 ]
 
+# FIXME: This logic can be removed once all buildbots have moved
+# debuginfo-test from clang/test to llvm/projects or monorepo.
+if os.path.exists(os.path.join(config.test_source_root, 'debuginfo-tests')):
+  if os.path.isfile(
+  os.path.join(config.test_source_root, 'debuginfo-tests', 'lit.cfg.py')):
+config.excludes.append('debuginfo-tests')
+  else:
+tools.append(ToolSubst('%test_debuginfo', command=os.path.join(
+  config.llvm_src_root, 'utils', 'test_debuginfo.pl')))
+
 if config.clang_examples:
 tools.append('clang-interpreter')
 
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -131,3 +131,12 @@
 add_custom_target(clang-test)
 add_dependencies(clang-test check-clang)
 set_target_properties(clang-test PROPERTIES FOLDER "Clang tests")
+
+# FIXME: This logic can be removed once all buildbots have moved
+# debuginfo-test from clang/test to llvm/projects or monorepo.
+if(EXISTS debuginfo-tests)
+  message(WARNING "Including debuginfo-tests in clang/test is deprecated.  
Move to llvm/projects or use monorepo.")
+  if(EXISTS debuginfo-tests/CMakeLists.txt)
+add_subdirectory(debuginfo-tests)
+  endif()
+endif()


Index: test/lit.cfg.py
===
--- test/lit.cfg.py
+++ test/lit.cfg.py
@@ -58,12 +58,20 @@
 
 tools = [
 'c-index-test', 'clang-check', 'clang-diff', 'clang-format', 'opt',
-ToolSubst('%test_debuginfo', command=os.path.join(
-config.llvm_src_root, 'utils', 'test_debuginfo.pl')),
 ToolSubst('%clang_func_map', command=FindTool(
 'clang-func-mapping'), unresolved='ignore'),
 ]
 
+# FIXME: This logic can be removed once all buildbots have moved
+# debuginfo-test from clang/test to llvm/projects or monorepo.
+if os.path.exists(os.path.join(config.test_source_root, 'debuginfo-tests')):
+  if os.path.isfile(
+  os.path.join(config.test_source_root, 'debuginfo-tests', 'lit.cfg.py')):
+config.excludes.append('debuginfo-tests')
+  else:
+tools.append(ToolSubst('%test_debuginfo', command=os.path.join(
+  config.llvm_src_root, 'utils', 'test_debuginfo.pl')))
+
 if config.clang_examples:
 tools.append('clang-interpreter')
 
Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -131,3 +131,12 @@
 add_custom_target(clang-test)
 add_dependencies(clang-test check-clang)
 set_target_properties(clang-test PROPERTIES FOLDER "Clang tests")
+
+# FIXME: This logic can be removed once all buildbots have moved
+# debuginfo-test from clang/test to llvm/projects or monorepo.
+if(EXISTS debuginfo-tests)
+  message(WARNING "Including debuginfo-tests in clang/test is deprecated.  Move to llvm/projects or use monorepo.")
+  if(EXISTS debuginfo-tests/CMakeLists.txt)
+add_subdirectory(debuginfo-tests)
+  endif()
+endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D40998: [driver][darwin] Take the OS version specified in "-target" as the target OS instead of inferring it from SDK / environment

2017-12-09 Thread Bob Wilson via Phabricator via cfe-commits
bob.wilson requested changes to this revision.
bob.wilson added inline comments.
This revision now requires changes to proceed.



Comment at: lib/Driver/ToolChains/Darwin.cpp:1518-1523
+  // Warn about superfluous OS_DEPLOYMENT_TARGET environment variable.
+  Optional EnvTarget =
+  getDeploymentTargetFromEnvironmentVariables(getDriver(), 
getTriple());
+  if (EnvTarget)
+getDriver().Diag(clang::diag::warn_drv_unused_environment_variable)
+<< EnvTarget->getAsString(Args, Opts);

I don't think there should be a warning in this case. It is common (at least 
within Apple) to set the environment variable as a default but then override it 
for some cases. Warning would be really annoying, and for anyone using -Werror 
it will break their builds.


Repository:
  rC Clang

https://reviews.llvm.org/D40998



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