r339438 - [CodeGen] Merge equivalent block copy/helper functions.

2018-08-10 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Aug 10 08:09:24 2018
New Revision: 339438

URL: http://llvm.org/viewvc/llvm-project?rev=339438&view=rev
Log:
[CodeGen] Merge equivalent block copy/helper functions.

Clang generates copy and dispose helper functions for each block literal
on the stack. Often these functions are equivalent for different blocks.
This commit makes changes to merge equivalent copy and dispose helper
functions and reduce code size.

To enable merging equivalent copy/dispose functions, the captured object
infomation is encoded into the helper function name. This allows IRGen
to check whether an equivalent helper function has already been emitted
and reuse the function instead of generating a new helper function
whenever a block is defined. In addition, the helper functions are
marked as linkonce_odr to enable merging helper functions that have the
same name across translation units and marked as unnamed_addr to enable
the linker's deduplication pass to merge functions that have different
names but the same content.

rdar://problem/42640608

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

Added:
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/PCH/block-helpers.h
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBlocks.h
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/blocks-1.c
cfe/trunk/test/CodeGen/blocks.c
cfe/trunk/test/CodeGen/sanitize-thread-no-checking-at-run-time.m
cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/cxx-block-objects.cpp
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjC/debug-info-block-helper.m
cfe/trunk/test/CodeGenObjC/debug-info-blocks.m
cfe/trunk/test/CodeGenObjC/mrc-weak.m
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm
cfe/trunk/test/CodeGenObjCXX/mrc-weak.mm

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=339438&r1=339437&r2=339438&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Aug 10 08:09:24 2018
@@ -22,6 +22,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/PrettyPrinter.h"
@@ -150,6 +151,22 @@ struct TypeInfo {
 /// Holds long-lived AST nodes (such as types and decls) that can be
 /// referred to throughout the semantic analysis of a file.
 class ASTContext : public RefCountedBase {
+public:
+  /// Copy initialization expr of a __block variable and a boolean flag that
+  /// indicates whether the expression can throw.
+  struct BlockVarCopyInit {
+BlockVarCopyInit() = default;
+BlockVarCopyInit(Expr *CopyExpr, bool CanThrow)
+: ExprAndFlag(CopyExpr, CanThrow) {}
+void setExprAndFlag(Expr *CopyExpr, bool CanThrow) {
+  ExprAndFlag.setPointerAndInt(CopyExpr, CanThrow);
+}
+Expr *getCopyExpr() const { return ExprAndFlag.getPointer(); }
+bool canThrow() const { return ExprAndFlag.getInt(); }
+llvm::PointerIntPair ExprAndFlag;
+  };
+
+private:
   friend class NestedNameSpecifier;
 
   mutable SmallVector Types;
@@ -244,8 +261,8 @@ class ASTContext : public RefCountedBase
   /// interface.
   llvm::DenseMap 
ObjCMethodRedecls;
 
-  /// Mapping from __block VarDecls to their copy initialization expr.
-  llvm::DenseMap BlockVarCopyInits;
+  /// Mapping from __block VarDecls to BlockVarCopyInit.
+  llvm::DenseMap BlockVarCopyInits;
 
   /// Mapping from class scope functions specialization to their
   /// template patterns.
@@ -2664,12 +2681,13 @@ public:
   /// otherwise returns null.
   const ObjCInterfaceDecl *getObjContainingInterface(const NamedDecl *ND) 
const;
 
-  /// Set the copy inialization expression of a block var decl.
-  void setBlockVarCopyInits(VarDecl*VD, Expr* Init);
+  /// Set the copy inialization expression of a block var decl. \p CanThrow
+  /// indicates whether the copy expression can throw or not.
+  void setBlockVarCopyInit(const VarDecl* VD, Expr *CopyExpr, bool CanThrow);
 
   /// Get the copy initialization expression of the VarDecl \p VD, or
   /// nullptr if none exists.
-  Expr *getBlockVarCopyInits(const VarDecl* VD);
+  BlockVarCopyInit getBlockVarC

r339452 - Make changes to the check strings so that the test I modified in r339438

2018-08-10 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Aug 10 10:07:27 2018
New Revision: 339452

URL: http://llvm.org/viewvc/llvm-project?rev=339452&view=rev
Log:
Make changes to the check strings so that the test I modified in r339438
passes on 32-bit targets.

Modified:
cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp

Modified: cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp?rev=339452&r1=339451&r2=339452&view=diff
==
--- cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/block-byref-cxx-objc.cpp Fri Aug 10 10:07:27 2018
@@ -26,12 +26,12 @@ int testA() {
 // CHECK-LABEL: define internal void @__Block_byref_object_dispose_
 // CHECK: call {{.*}} @_ZN1AD1Ev
 
-// CHECK-LABEL: define linkonce_odr hidden void 
@__copy_helper_block_e8_32rc40rc(
+// CHECK-LABEL: define linkonce_odr hidden void 
@__copy_helper_block_e{{4|8}}_{{20|32}}rc{{24|40}}rc(
 // CHECK: call void @_Block_object_assign(
 // CHECK: invoke void @_Block_object_assign(
 // CHECK: call void @_Block_object_dispose({{.*}}) #[[NOUNWIND_ATTR:[0-9]+]]
 
-// CHECK-LABEL: define linkonce_odr hidden void 
@__destroy_helper_block_e8_32rd40rd(
+// CHECK-LABEL: define linkonce_odr hidden void 
@__destroy_helper_block_e{{4|8}}_{{20|32}}rd{{24|40}}rd(
 // CHECK: invoke void @_Block_object_dispose(
 // CHECK: call void @_Block_object_dispose(
 // CHECK: invoke void @_Block_object_dispose(
@@ -48,7 +48,7 @@ int testB() {
 // CHECK: call {{.*}} @_ZN1BD1Ev
 
 // CHECK-NOT: define{{.*}}@__copy_helper_block
-// CHECK: define linkonce_odr hidden void @__destroy_helper_block_e8_32r40r(
+// CHECK: define linkonce_odr hidden void 
@__destroy_helper_block_e{{4|8}}_{{20|32}}r{{24|40}}r(
 
 // CHECK: attributes #[[NOUNWIND_ATTR]] = {{{.*}}nounwind{{.*}}}
 


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


r339613 - Convert if/else to a switch. NFC.

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 13:59:57 2018
New Revision: 339613

URL: http://llvm.org/viewvc/llvm-project?rev=339613&view=rev
Log:
Convert if/else to a switch. NFC.

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=339613&r1=339612&r2=339613&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Aug 13 13:59:57 2018
@@ -1874,57 +1874,65 @@ CodeGenFunction::GenerateCopyHelperFunct
 Address srcField = Builder.CreateStructGEP(src, index, 
capture.getOffset());
 Address dstField = Builder.CreateStructGEP(dst, index, 
capture.getOffset());
 
-// If there's an explicit copy expression, we do that.
-if (CI.getCopyExpr()) {
-  assert(CopiedCapture.Kind == BlockCaptureEntityKind::CXXRecord);
+switch (CopiedCapture.Kind) {
+case BlockCaptureEntityKind::CXXRecord:
+  // If there's an explicit copy expression, we do that.
+  assert(CI.getCopyExpr() && "copy expression for variable is missing");
   EmitSynthesizedCXXCopyCtor(dstField, srcField, CI.getCopyExpr());
-} else if (CopiedCapture.Kind == BlockCaptureEntityKind::ARCWeak) {
+  break;
+case BlockCaptureEntityKind::ARCWeak:
   EmitARCCopyWeak(dstField, srcField);
-// If this is a C struct that requires non-trivial copy construction, emit 
a
-// call to its copy constructor.
-} else if (CopiedCapture.Kind ==
-   BlockCaptureEntityKind::NonTrivialCStruct) {
+  break;
+case BlockCaptureEntityKind::NonTrivialCStruct: {
+  // If this is a C struct that requires non-trivial copy construction,
+  // emit a call to its copy constructor.
   QualType varType = CI.getVariable()->getType();
   callCStructCopyConstructor(MakeAddrLValue(dstField, varType),
  MakeAddrLValue(srcField, varType));
-} else {
+  break;
+}
+case BlockCaptureEntityKind::ARCStrong: {
   llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src");
-  if (CopiedCapture.Kind == BlockCaptureEntityKind::ARCStrong) {
-// At -O0, store null into the destination field (so that the
-// storeStrong doesn't over-release) and then call storeStrong.
-// This is a workaround to not having an initStrong call.
-if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
-  auto *ty = cast(srcValue->getType());
-  llvm::Value *null = llvm::ConstantPointerNull::get(ty);
-  Builder.CreateStore(null, dstField);
-  EmitARCStoreStrongCall(dstField, srcValue, true);
-
-// With optimization enabled, take advantage of the fact that
-// the blocks runtime guarantees a memcpy of the block data, and
-// just emit a retain of the src field.
-} else {
-  EmitARCRetainNonBlock(srcValue);
+  // At -O0, store null into the destination field (so that the
+  // storeStrong doesn't over-release) and then call storeStrong.
+  // This is a workaround to not having an initStrong call.
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0) {
+auto *ty = cast(srcValue->getType());
+llvm::Value *null = llvm::ConstantPointerNull::get(ty);
+Builder.CreateStore(null, dstField);
+EmitARCStoreStrongCall(dstField, srcValue, true);
 
-  // Unless EH cleanup is required, we don't need this anymore, so kill
-  // it. It's not quite worth the annoyance to avoid creating it in the
-  // first place.
-  if (!needsEHCleanup(captureType.isDestructedType()))
-cast(dstField.getPointer())->eraseFromParent();
-}
+  // With optimization enabled, take advantage of the fact that
+  // the blocks runtime guarantees a memcpy of the block data, and
+  // just emit a retain of the src field.
   } else {
-assert(CopiedCapture.Kind == BlockCaptureEntityKind::BlockObject);
-srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy);
-llvm::Value *dstAddr =
-  Builder.CreateBitCast(dstField.getPointer(), VoidPtrTy);
-llvm::Value *args[] = {
-  dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, 
flags.getBitMask())
-};
+EmitARCRetainNonBlock(srcValue);
 
-if (CI.isByRef() && C.getBlockVarCopyInit(CI.getVariable()).canThrow())
-  EmitRuntimeCallOrInvoke(CGM.getBlockObjectAssign(), args);
-else
-  EmitNounwindRuntimeCall(CGM.getBlockObjectAssign(), args);
+// Unless EH cleanup is required, we don't need this anymore, so kill
+// it. It's not quite worth the annoyance to avoid creating it in the
+// first place.
+if (!needsEHCleanup(captureType.isDestructedType()))
+  cast(dstField.getPointer())->eraseFromParent();
   }

r339632 - Fix check strings in test/CodeGenObjC/arc-blocks.m in preperation for

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 17:15:41 2018
New Revision: 339632

URL: http://llvm.org/viewvc/llvm-project?rev=339632&view=rev
Log:
Fix check strings in test/CodeGenObjC/arc-blocks.m in preperation for
fixing a bug introduced in r339438.

Check the descriptor global variables in the IR at both -O0 and -O2.

Modified:
cfe/trunk/test/CodeGenObjC/arc-blocks.m

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=339632&r1=339631&r2=339632&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Mon Aug 13 17:15:41 2018
@@ -1,16 +1,16 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck 
%s
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-UNOPT %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -O2 -disable-llvm-passes -o - %s | FileCheck 
-check-prefix=CHECK -check-prefix=CHECK-COMMON %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fblocks 
-fobjc-arc -fobjc-runtime-has-weak -o - %s | FileCheck 
-check-prefix=CHECK-UNOPT -check-prefix=CHECK-COMMON %s
 
-// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK-UNOPT: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, void 
(i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK-UNOPT: @[[BLOCK_DESCRIPTOR_TMP44:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 256 }, 
align 8
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP46:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i8* } { i64 0, i64 48, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* 
getelementptr inbounds ([3 x i8], [3 x i8]* @{{.*}}, i32 0, i32 0) }, align 8
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP48:.*]] = internal constant { i64, i64, void 
(i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32b, void (i8*)* @__destroy_helper_block_8_32s, i8* 
getelementptr inbounds ([9 x i8], [9 x i8]* @.str.47, i32 0, i32 0), i64 256 }, 
align 8
+// CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
+// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } 
{ i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to 
i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
+// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
+// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, 
void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void

r339633 - [CodeGen] Before returning a copy/dispose helper function, bitcast it to

2018-08-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Aug 13 17:15:42 2018
New Revision: 339633

URL: http://llvm.org/viewvc/llvm-project?rev=339633&view=rev
Log:
[CodeGen] Before returning a copy/dispose helper function, bitcast it to
a void pointer type.

This fixes a bug introduced in r339438.

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGen/blocks.c
cfe/trunk/test/CodeGenObjC/arc-blocks.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=339633&r1=339632&r2=339633&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Mon Aug 13 17:15:42 2018
@@ -1816,7 +1816,7 @@ CodeGenFunction::GenerateCopyHelperFunct
/*IsCopyHelper*/ true, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return Func;
+return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
 
   ASTContext &C = getContext();
 
@@ -2010,7 +2010,7 @@ CodeGenFunction::GenerateDestroyHelperFu
/*IsCopyHelper*/ false, CGM);
 
   if (llvm::GlobalValue *Func = CGM.getModule().getNamedValue(FuncName))
-return Func;
+return llvm::ConstantExpr::getBitCast(Func, VoidPtrTy);
 
   ASTContext &C = getContext();
 

Modified: cfe/trunk/test/CodeGen/blocks.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/blocks.c?rev=339633&r1=339632&r2=339633&view=diff
==
--- cfe/trunk/test/CodeGen/blocks.c (original)
+++ cfe/trunk/test/CodeGen/blocks.c Mon Aug 13 17:15:42 2018
@@ -2,7 +2,8 @@
 
 // CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i32, i32 }
 
-// CHECK: @[[BLOCK_DESCRIPTOR_TMP21:.*]] = internal constant { i32, i32, void 
(i8*, i8*)*, void (i8*)*, i8*, i8* } { i32 0, i32 24, void (i8*, i8*)* 
@__copy_helper_block_4_20r, void (i8*)* @__destroy_helper_block_4_20r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* null }, 
align 4
+// CHECK: @{{.*}} = internal constant { i32, i32, i8*, i8*, i8*, i8* } { i32 
0, i32 24, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_4_20r to i8*), 
i8* bitcast (void (i8*)* @__destroy_helper_block_4_20r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i8* null }, 
align 4
+// CHECK: @[[BLOCK_DESCRIPTOR_TMP21:.*]] = internal constant { i32, i32, i8*, 
i8*, i8*, i8* } { i32 0, i32 24, i8* bitcast (void (i8*, i8*)* 
@__copy_helper_block_4_20r to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block_4_20r to i8*), i8* getelementptr inbounds ([6 x i8], [6 
x i8]* @{{.*}}, i32 0, i32 0), i8* null }, align 4
 
 void (^f)(void) = ^{};
 
@@ -118,6 +119,6 @@ void testConstCaptureInCopyAndDestroyHel
 }
 // CHECK-LABEL: define void @testConstCaptureInCopyAndDestroyHelpers(
 // CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, i8* }>* %{{.*}}, i32 0, i32 4
-// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, void (i8*, 
i8*)*, void (i8*)*, i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP21]] to 
%[[STRUCT_BLOCK_DESCRIPTOR]]*), %[[STRUCT_BLOCK_DESCRIPTOR]]** 
%[[BLOCK_DESCRIPTOR]], align 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i32, i32, i8*, i8*, 
i8*, i8* }* @[[BLOCK_DESCRIPTOR_TMP21]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 4
 
 // CHECK-LABEL: define internal void 
@__testConstCaptureInCopyAndDestroyHelpers_block_invoke

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=339633&r1=339632&r2=339633&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Mon Aug 13 17:15:42 2018
@@ -3,14 +3,14 @@
 
 // CHECK-COMMON: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
 // CHECK-COMMON: @{{.*}} = internal constant { i64, i64, i8*, i8*, i8*, i64 } 
{ i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_8_32r to 
i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_8_32r to i8*), i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-COMMON: @[[BLOCK_DESCRIPTOR_TMP9:.*]] = internal constant { i64, i64, 
void (i8*, i8*)*, void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32r, void (i8*)* @__destroy_helper_block_8_32r, i8* 
getelementptr inbounds ([6 x i8], [6 x i8]* @{{.*}}, i32 0, i32 0), i64 16 }, 
align 8
-// CHECK-COMMON: @{{.*}} = internal constant { i64, i64, void (i8*, i8*)*, 
void (i8*)*, i8*, i64 } { i64 0, i64 40, void (i8*, i8*)* 
@__copy_helper_block_8_32s, void (i

r340041 - [CodeGen] Merge identical block descriptor global variables.

2018-08-17 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Aug 17 08:46:07 2018
New Revision: 340041

URL: http://llvm.org/viewvc/llvm-project?rev=340041&view=rev
Log:
[CodeGen] Merge identical block descriptor global variables.

Currently, clang generates a new block descriptor global variable for
each new block literal. This commit merges block descriptors that are
identical inside and across translation units using the same approach
taken in r339438.

To enable merging identical block descriptors, the size and signature of
the block and information about the captures are encoded into the name
of the block descriptor variable. Also, the block descriptor variable is
marked as linkonce_odr and unnamed_addr.

rdar://problem/42640703

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBlocks.h
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjC/arc-captured-32bit-block-var-layout-2.m
cfe/trunk/test/CodeGenObjC/fragile-arc.m
cfe/trunk/test/CodeGenObjC/noescape.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=340041&r1=340040&r2=340041&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Aug 17 08:46:07 2018
@@ -65,6 +65,107 @@ static llvm::Constant *buildDisposeHelpe
   return CodeGenFunction(CGM).GenerateDestroyHelperFunction(blockInfo);
 }
 
+namespace {
+
+/// Represents a type of copy/destroy operation that should be performed for an
+/// entity that's captured by a block.
+enum class BlockCaptureEntityKind {
+  CXXRecord, // Copy or destroy
+  ARCWeak,
+  ARCStrong,
+  NonTrivialCStruct,
+  BlockObject, // Assign or release
+  None
+};
+
+/// Represents a captured entity that requires extra operations in order for
+/// this entity to be copied or destroyed correctly.
+struct BlockCaptureManagedEntity {
+  BlockCaptureEntityKind CopyKind, DisposeKind;
+  BlockFieldFlags CopyFlags, DisposeFlags;
+  const BlockDecl::Capture *CI;
+  const CGBlockInfo::Capture *Capture;
+
+  BlockCaptureManagedEntity(BlockCaptureEntityKind CopyType,
+BlockCaptureEntityKind DisposeType,
+BlockFieldFlags CopyFlags,
+BlockFieldFlags DisposeFlags,
+const BlockDecl::Capture &CI,
+const CGBlockInfo::Capture &Capture)
+  : CopyKind(CopyType), DisposeKind(DisposeType), CopyFlags(CopyFlags),
+DisposeFlags(DisposeFlags), CI(&CI), Capture(&Capture) {}
+
+  bool operator<(const BlockCaptureManagedEntity &Other) const {
+return Capture->getOffset() < Other.Capture->getOffset();
+  }
+};
+
+enum class CaptureStrKind {
+  // String for the copy helper.
+  CopyHelper,
+  // String for the dispose helper.
+  DisposeHelper,
+  // Merge the strings for the copy helper and dispose helper.
+  Merged
+};
+
+} // end anonymous namespace
+
+static void findBlockCapturedManagedEntities(
+const CGBlockInfo &BlockInfo, const LangOptions &LangOpts,
+SmallVectorImpl &ManagedCaptures);
+
+static std::string getBlockCaptureStr(const BlockCaptureManagedEntity &E,
+  CaptureStrKind StrKind,
+  CharUnits BlockAlignment,
+  CodeGenModule &CGM);
+
+static std::string getBlockDescriptorName(const CGBlockInfo &BlockInfo,
+  CodeGenModule &CGM) {
+  std::string Name = "__block_descriptor_";
+  Name += llvm::to_string(BlockInfo.BlockSize.getQuantity()) + "_";
+
+  if (BlockInfo.needsCopyDisposeHelpers()) {
+if (CGM.getLangOpts().Exceptions)
+  Name += "e";
+if (CGM.getCodeGenOpts().ObjCAutoRefCountExceptions)
+  Name += "a";
+Name += llvm::to_string(BlockInfo.BlockAlign.getQuantity()) + "_";
+
+SmallVector ManagedCaptures;
+findBlockCapturedManagedEntities(BlockInfo, CGM.getContext().getLangOpts(),
+ ManagedCaptures);
+
+for (const BlockCaptureManagedEntity &E : ManagedCaptures) {
+  Name += llvm::to_string(E.Capture->getOffset().getQuantity());
+
+  if (E.CopyKind == E.DisposeKind) {
+// If CopyKind and DisposeKind are the same, merge the capture
+// information.
+assert(E.CopyKind != BlockCaptureEntityKind::None &&
+   "shouldn't see BlockCaptureManagedEntity that is None");
+Name += getBlockCaptureStr(E, CaptureStrKind::Merged,
+   BlockInfo.BlockAlign, CGM);
+  } else {
+// If CopyKind and DisposeKind are not the same, which can happen when
+// either Kind is None or the captured o

r340408 - [CodeGen] Look at the type of a block capture field rather than the type

2018-08-22 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Aug 22 06:41:19 2018
New Revision: 340408

URL: http://llvm.org/viewvc/llvm-project?rev=340408&view=rev
Log:
[CodeGen] Look at the type of a block capture field rather than the type
of the captured variable when determining whether the capture needs
special handing when the block is copied or disposed.

This fixes bugs in the handling of variables captured by a block that is
nested inside a lambda that captures the variables by reference.

rdar://problem/43540889

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

Added:
cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.mm
Removed:
cfe/trunk/test/CodeGenObjCXX/block-nested-in-lambda.cpp
Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=340408&r1=340407&r2=340408&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Aug 22 06:41:19 2018
@@ -557,6 +557,10 @@ static void computeBlockInfo(CodeGenModu
   CharUnits align = CGM.getPointerAlign();
   maxFieldAlign = std::max(maxFieldAlign, align);
 
+  // Since a __block variable cannot be captured by lambdas, its type and
+  // the capture field type should always match.
+  assert(getCaptureFieldType(*CGF, CI) == variable->getType() &&
+ "capture type differs from the variable type");
   layout.push_back(BlockLayoutChunk(align, CGM.getPointerSize(),
 Qualifiers::OCL_None, &CI,
 CGM.VoidPtrTy, variable->getType()));
@@ -570,10 +574,11 @@ static void computeBlockInfo(CodeGenModu
   continue;
 }
 
+QualType VT = getCaptureFieldType(*CGF, CI);
+
 // If we have a lifetime qualifier, honor it for capture purposes.
 // That includes *not* copying it if it's __unsafe_unretained.
-Qualifiers::ObjCLifetime lifetime =
-  variable->getType().getObjCLifetime();
+Qualifiers::ObjCLifetime lifetime = VT.getObjCLifetime();
 if (lifetime) {
   switch (lifetime) {
   case Qualifiers::OCL_None: llvm_unreachable("impossible");
@@ -587,10 +592,10 @@ static void computeBlockInfo(CodeGenModu
   }
 
 // Block pointers require copy/dispose.  So do Objective-C pointers.
-} else if (variable->getType()->isObjCRetainableType()) {
+} else if (VT->isObjCRetainableType()) {
   // But honor the inert __unsafe_unretained qualifier, which doesn't
   // actually make it into the type system.
-   if (variable->getType()->isObjCInertUnsafeUnretainedType()) {
+   if (VT->isObjCInertUnsafeUnretainedType()) {
 lifetime = Qualifiers::OCL_ExplicitNone;
   } else {
 info.NeedsCopyDispose = true;
@@ -602,21 +607,18 @@ static void computeBlockInfo(CodeGenModu
 } else if (CI.hasCopyExpr()) {
   info.NeedsCopyDispose = true;
   info.HasCXXObject = true;
-  if (!variable->getType()->getAsCXXRecordDecl()->isExternallyVisible())
+  if (!VT->getAsCXXRecordDecl()->isExternallyVisible())
 info.CapturesNonExternalType = true;
 
 // So do C structs that require non-trivial copy construction or
 // destruction.
-} else if (variable->getType().isNonTrivialToPrimitiveCopy() ==
-   QualType::PCK_Struct ||
-   variable->getType().isDestructedType() ==
-   QualType::DK_nontrivial_c_struct) {
+} else if (VT.isNonTrivialToPrimitiveCopy() == QualType::PCK_Struct ||
+   VT.isDestructedType() == QualType::DK_nontrivial_c_struct) {
   info.NeedsCopyDispose = true;
 
 // And so do types with destructors.
 } else if (CGM.getLangOpts().CPlusPlus) {
-  if (const CXXRecordDecl *record =
-variable->getType()->getAsCXXRecordDecl()) {
+  if (const CXXRecordDecl *record = VT->getAsCXXRecordDecl()) {
 if (!record->hasTrivialDestructor()) {
   info.HasCXXObject = true;
   info.NeedsCopyDispose = true;
@@ -626,7 +628,6 @@ static void computeBlockInfo(CodeGenModu
   }
 }
 
-QualType VT = getCaptureFieldType(*CGF, CI);
 CharUnits size = C.getTypeSizeInChars(VT);
 CharUnits align = C.getDeclAlign(variable);
 
@@ -1717,10 +1718,9 @@ static void findBlockCapturedManagedEnti
 if (Capture.isConstant())
   continue;
 
-auto CopyInfo =
-   computeCopyInfoForBlockCapture(CI, Variable->getType(), LangOpts);
-auto DisposeInfo =
-   computeDestroyInfoForBlockCapture(CI, Variable->getType(), LangOpts);
+QualType VT = Capture.fieldType();
+auto CopyInfo = computeCopyInfoForBlockCapture(CI, VT, LangOpts);
+auto DisposeInfo = computeDestroyInfoForBlockCapture(CI, VT, LangOpts);
 if (CopyInfo.first != BlockCaptureEntityKind::None ||
 DisposeInfo.first != BlockCaptureEntityKind::None)
   

r332397 - Address post-commit review comments after r328731. NFC.

2018-05-15 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue May 15 14:00:30 2018
New Revision: 332397

URL: http://llvm.org/viewvc/llvm-project?rev=332397&view=rev
Log:
Address post-commit review comments after r328731. NFC.

- Define a function (canPassInRegisters) that determines whether a
record can be passed in registers based on language rules and
target-specific ABI rules.

- Set flag RecordDecl::ParamDestroyedInCallee to true in MSVC mode and
remove ASTContext::isParamDestroyedInCallee, which is no longer needed.

- Use the same type (unsigned) for RecordDecl's bit-field members.

For more background, see the following discussions that took place on
cfe-commits.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180326/223498.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180402/223688.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180409/224754.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180423/226494.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180507/227647.html

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=332397&r1=332396&r2=332397&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue May 15 14:00:30 2018
@@ -1181,10 +1181,6 @@ public:
const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten = false);
 
-  /// Determine whether a type is a class that should be detructed in the
-  /// callee function.
-  bool isParamDestroyedInCallee(QualType T) const;
-
   /// Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T) const;

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=332397&r1=332396&r2=332397&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue May 15 14:00:30 2018
@@ -3572,40 +3572,38 @@ private:
   /// This is true if this struct ends with a flexible
   /// array member (e.g. int X[]) or if this union contains a struct that does.
   /// If so, this cannot be contained in arrays or other structs as a member.
-  bool HasFlexibleArrayMember : 1;
+  unsigned HasFlexibleArrayMember : 1;
 
   /// Whether this is the type of an anonymous struct or union.
-  bool AnonymousStructOrUnion : 1;
+  unsigned AnonymousStructOrUnion : 1;
 
   /// This is true if this struct has at least one member
   /// containing an Objective-C object pointer type.
-  bool HasObjectMember : 1;
+  unsigned HasObjectMember : 1;
 
   /// This is true if struct has at least one member of
   /// 'volatile' type.
-  bool HasVolatileMember : 1;
+  unsigned HasVolatileMember : 1;
 
   /// Whether the field declarations of this record have been loaded
   /// from external storage. To avoid unnecessary deserialization of
   /// methods/nested types we allow deserialization of just the fields
   /// when needed.
-  mutable bool LoadedFieldsFromExternalStorage : 1;
+  mutable unsigned LoadedFieldsFromExternalStorage : 1;
 
   /// Basic properties of non-trivial C structs.
-  bool NonTrivialToPrimitiveDefaultInitialize : 1;
-  bool NonTrivialToPrimitiveCopy : 1;
-  bool NonTrivialToPrimitiveDestroy : 1;
-
-  /// Indicates whether this struct is destroyed in the callee. This flag is
-  /// meaningless when Microsoft ABI is used since parameters are always
-  /// destroyed in the callee.
+  unsigned NonTrivialToPrimitiveDefaultInitialize : 1;
+  unsigned NonTrivialToPrimitiveCopy : 1;
+  unsigned NonTrivialToPrimitiveDestroy : 1;
+
+  /// Indicates whether this struct is destroyed in the callee.
   ///
   /// Please note that MSVC won't merge adjacent bitfields if they don't have
   /// the same type.
-  uint8_t ParamDestroyedInCallee : 1;
+  unsigned ParamDestroyedInCallee : 1;
 
   /// Represents the way this type is passed to a function.
-  uint8_t ArgPassingRestrictions : 2;
+  unsigned ArgPassingRestrictions : 2;
 
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=332397&r1=332396&r2=332397&view=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue May 15 14

[libcxx] r333103 - Teach __libcpp_is_floating_point that __fp16 and _Float16 are

2018-05-23 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed May 23 10:31:09 2018
New Revision: 333103

URL: http://llvm.org/viewvc/llvm-project?rev=333103&view=rev
Log:
Teach __libcpp_is_floating_point that __fp16 and _Float16 are
floating-point types.

rdar://problem/40377353

Added:
libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp
Modified:
libcxx/trunk/include/type_traits

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=333103&r1=333102&r2=333103&view=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed May 23 10:31:09 2018
@@ -733,6 +733,10 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
 // is_floating_point
 
 template  struct __libcpp_is_floating_point  : public 
false_type {};
+template <>  struct __libcpp_is_floating_point<__fp16>  : public 
true_type {};
+#ifdef __FLT16_MANT_DIG__
+template <>  struct __libcpp_is_floating_point<_Float16>: public 
true_type {};
+#endif
 template <>  struct __libcpp_is_floating_point   : public 
true_type {};
 template <>  struct __libcpp_is_floating_point  : public 
true_type {};
 template <>  struct __libcpp_is_floating_point : public 
true_type {};

Added: libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp?rev=333103&view=auto
==
--- libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp (added)
+++ libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp Wed May 23 
10:31:09 2018
@@ -0,0 +1,22 @@
+//===--===//
+//
+// 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.
+//
+//===--===//
+//
+// 
+//
+// Test that is_floating_point::value is true when T=__fp16 or T=_Float16.
+
+#include 
+
+int main() {
+  static_assert(std::is_floating_point<__fp16>::value, "");
+#ifdef __FLT16_MANT_DIG__
+  static_assert(std::is_floating_point<_Float16>::value, "");
+#endif
+  return 0;
+}


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


[libcxx] r333108 - Do not define template specialization __libcpp_is_floating_point<__fp16>

2018-05-23 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed May 23 10:50:41 2018
New Revision: 333108

URL: http://llvm.org/viewvc/llvm-project?rev=333108&view=rev
Log:
Do not define template specialization __libcpp_is_floating_point<__fp16>
if the compiler is not clang.

gcc doesn't allow using __fp16 on non-ARM targets.

Modified:
libcxx/trunk/include/type_traits
libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=333108&r1=333107&r2=333108&view=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Wed May 23 10:50:41 2018
@@ -733,7 +733,9 @@ _LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR boo
 // is_floating_point
 
 template  struct __libcpp_is_floating_point  : public 
false_type {};
+#ifdef __clang__
 template <>  struct __libcpp_is_floating_point<__fp16>  : public 
true_type {};
+#endif
 #ifdef __FLT16_MANT_DIG__
 template <>  struct __libcpp_is_floating_point<_Float16>: public 
true_type {};
 #endif

Modified: libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp?rev=333108&r1=333107&r2=333108&view=diff
==
--- libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp (original)
+++ libcxx/trunk/test/libcxx/type_traits/is_floating_point.pass.cpp Wed May 23 
10:50:41 2018
@@ -14,7 +14,9 @@
 #include 
 
 int main() {
+#ifdef __clang__
   static_assert(std::is_floating_point<__fp16>::value, "");
+#endif
 #ifdef __FLT16_MANT_DIG__
   static_assert(std::is_floating_point<_Float16>::value, "");
 #endif


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


r333447 - [CodeGen][Darwin] Set the calling-convention of thread-local variable

2018-05-29 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue May 29 11:28:49 2018
New Revision: 333447

URL: http://llvm.org/viewvc/llvm-project?rev=333447&view=rev
Log:
[CodeGen][Darwin] Set the calling-convention of thread-local variable
initialization functions to 'cxx_fast_tlscc'.

This fixes a bug where instructions calling initialization functions for
thread-local static members of c++ template classes were using calling
convention 'cxx_fast_tlscc' while the called functions weren't annotated
with the calling convention.

rdar://problem/40447463

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

Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=333447&r1=333446&r2=333447&view=diff
==
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Tue May 29 11:28:49 2018
@@ -2450,8 +2450,12 @@ void ItaniumCXXABI::EmitThreadLocalInitF
 if (InitIsInitFunc) {
   if (Init) {
 llvm::CallInst *CallVal = Builder.CreateCall(Init);
-if (isThreadWrapperReplaceable(VD, CGM))
+if (isThreadWrapperReplaceable(VD, CGM)) {
   CallVal->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
+  llvm::Function *Fn =
+  
cast(cast(Init)->getAliasee());
+  Fn->setCallingConv(llvm::CallingConv::CXX_FAST_TLS);
+}
   }
 } else {
   // Don't know whether we have an init function. Call it if it exists.

Modified: cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp?rev=333447&r1=333446&r2=333447&view=diff
==
--- cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cxx11-thread-local.cpp Tue May 29 11:28:49 2018
@@ -166,7 +166,8 @@ int f() {
 // DARWIN: call cxx_fast_tlscc void @_ZTHN1XIiE1mE()
 // CHECK: ret {{.*}}* @_ZN1XIiE1mE
 
-// CHECK: define internal {{.*}} @[[VF_M_INIT]]()
+// LINUX: define internal void @[[VF_M_INIT]]()
+// DARWIN: define internal cxx_fast_tlscc void @[[VF_M_INIT]]()
 // LINUX-SAME: comdat($_ZN1VIfE1mE)
 // DARWIN-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIfE1mE to i8*)
@@ -178,7 +179,8 @@ int f() {
 // CHECK: store i64 1, i64* @_ZGVN1VIfE1mE
 // CHECK: br label
 
-// CHECK: define internal {{.*}} @[[XF_M_INIT]]()
+// LINUX: define internal void @[[XF_M_INIT]]()
+// DARWIN: define internal cxx_fast_tlscc void @[[XF_M_INIT]]()
 // LINUX-SAME: comdat($_ZN1XIfE1mE)
 // DARWIN-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIfE1mE to i8*)
@@ -268,7 +270,8 @@ void set_anon_i() {
 // LINUX-LABEL: define internal i32* @_ZTWN12_GLOBAL__N_16anon_iE()
 // DARWIN-LABEL: define internal cxx_fast_tlscc i32* 
@_ZTWN12_GLOBAL__N_16anon_iE()
 
-// CHECK: define internal {{.*}} @[[V_M_INIT]]()
+// LINUX: define internal void @[[V_M_INIT]]()
+// DARWIN: define internal cxx_fast_tlscc void @[[V_M_INIT]]()
 // LINUX-SAME: comdat($_ZN1VIiE1mE)
 // DARWIN-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1VIiE1mE to i8*)
@@ -280,7 +283,8 @@ void set_anon_i() {
 // CHECK: store i64 1, i64* @_ZGVN1VIiE1mE
 // CHECK: br label
 
-// CHECK: define internal {{.*}} @[[X_M_INIT]]()
+// LINUX: define internal void @[[X_M_INIT]]()
+// DARWIN: define internal cxx_fast_tlscc void @[[X_M_INIT]]()
 // LINUX-SAME: comdat($_ZN1XIiE1mE)
 // DARWIN-NOT: comdat
 // CHECK: load i8, i8* bitcast (i64* @_ZGVN1XIiE1mE to i8*)


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


r314370 - Look through parentheses.

2017-09-27 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Sep 27 18:31:17 2017
New Revision: 314370

URL: http://llvm.org/viewvc/llvm-project?rev=314370&view=rev
Log:
Look through parentheses.

This fixes a bug where clang would emit instructions to reclaim a value
that's going to be __bridge-casted to CF.

rdar://problem/34687542

Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=314370&r1=314369&r2=314370&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Sep 27 18:31:17 2017
@@ -4322,7 +4322,7 @@ static Expr *maybeUndoReclaimObject(Expr
   // problems here.  To catch them all, we'd need to rebuild arbitrary
   // value-propagating subexpressions --- we can't reliably rebuild
   // in-place because of expression sharing.
-  if (ImplicitCastExpr *ice = dyn_cast(e))
+  if (auto *ice = dyn_cast(e->IgnoreParens()))
 if (ice->getCastKind() == CK_ARCReclaimReturnedObject)
   return ice->getSubExpr();
 

Modified: cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m?rev=314370&r1=314369&r2=314370&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m Wed Sep 27 18:31:17 2017
@@ -97,3 +97,10 @@ void bridge_of_cf(int *i) {
   // CHECK-NEXT: ret void
 }
 
+// CHECK-LABEL: define %struct.__CFString* @bridge_of_paren_expr()
+CFStringRef bridge_of_paren_expr() {
+  // CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue(
+  // CHECK-NOT: call void @objc_release(
+  CFStringRef r = (__bridge CFStringRef)(CreateNSString());
+  return r;
+}


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


r315045 - [CodeGen] Emit a helper function for __builtin_os_log_format to reduce

2017-10-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct  6 00:12:46 2017
New Revision: 315045

URL: http://llvm.org/viewvc/llvm-project?rev=315045&view=rev
Log:
[CodeGen] Emit a helper function for __builtin_os_log_format to reduce
code size.

Currently clang expands a call to __builtin_os_log_format into a long
sequence of instructions at the call site, causing code size to
increase in some cases.

This commit attempts to reduce code size by emitting a helper function
that can be shared by calls to __builtin_os_log_format with similar
formats and arguments. The helper function has linkonce_odr linkage to
enable the linker to merge identical functions across translation units.
Attribute 'noinline' is attached to the helper function at -Oz so that
the inliner doesn't inline functions that can potentially be merged.

This commit also fixes a bug where the generated IR writes past the end
of the buffer when "%m" is the last specifier appearing in the format
string passed to __builtin_os_log_format.

Original patch by Duncan Exon Smith.

rdar://problem/34065973
rdar://problem/34196543

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

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGen/builtins.c
cfe/trunk/test/CodeGenObjC/os_log.m

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=315045&r1=315044&r2=315045&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Oct  6 00:12:46 2017
@@ -663,6 +663,179 @@ Value *CodeGenFunction::EmitCheckedArgFo
   return ArgValue;
 }
 
+/// Get the argument type for arguments to os_log_helper.
+static CanQualType getOSLogArgType(ASTContext &C, int Size) {
+  QualType UnsignedTy = C.getIntTypeForBitwidth(Size * 8, /*Signed=*/false);
+  return C.getCanonicalType(UnsignedTy);
+}
+
+llvm::Function *CodeGenFunction::generateBuiltinOSLogHelperFunction(
+const analyze_os_log::OSLogBufferLayout &Layout,
+CharUnits BufferAlignment) {
+  ASTContext &Ctx = getContext();
+
+  llvm::SmallString<64> Name;
+  {
+raw_svector_ostream OS(Name);
+OS << "__os_log_helper";
+OS << "_" << BufferAlignment.getQuantity();
+OS << "_" << int(Layout.getSummaryByte());
+OS << "_" << int(Layout.getNumArgsByte());
+for (const auto &Item : Layout.Items)
+  OS << "_" << int(Item.getSizeByte()) << "_"
+ << int(Item.getDescriptorByte());
+  }
+
+  if (llvm::Function *F = CGM.getModule().getFunction(Name))
+return F;
+
+  llvm::SmallVector Params;
+  Params.emplace_back(Ctx, nullptr, SourceLocation(), 
&Ctx.Idents.get("buffer"),
+  Ctx.VoidPtrTy, ImplicitParamDecl::Other);
+
+  for (unsigned int I = 0, E = Layout.Items.size(); I < E; ++I) {
+char Size = Layout.Items[I].getSizeByte();
+if (!Size)
+  continue;
+
+Params.emplace_back(Ctx, nullptr, SourceLocation(),
+&Ctx.Idents.get(std::string("arg") + 
std::to_string(I)),
+getOSLogArgType(Ctx, Size), ImplicitParamDecl::Other);
+  }
+
+  FunctionArgList Args;
+  for (auto &P : Params)
+Args.push_back(&P);
+
+  // The helper function has linkonce_odr linkage to enable the linker to merge
+  // identical functions. To ensure the merging always happens, 'noinline' is
+  // attached to the function when compiling with -Oz.
+  const CGFunctionInfo &FI =
+  CGM.getTypes().arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Args);
+  llvm::FunctionType *FuncTy = CGM.getTypes().GetFunctionType(FI);
+  llvm::Function *Fn = llvm::Function::Create(
+  FuncTy, llvm::GlobalValue::LinkOnceODRLinkage, Name, &CGM.getModule());
+  Fn->setVisibility(llvm::GlobalValue::HiddenVisibility);
+  CGM.SetLLVMFunctionAttributes(nullptr, FI, Fn);
+  CGM.SetLLVMFunctionAttributesForDefinition(nullptr, Fn);
+
+  // Attach 'noinline' at -Oz.
+  if (CGM.getCodeGenOpts().OptimizeSize == 2)
+Fn->addFnAttr(llvm::Attribute::NoInline);
+
+  auto NL = ApplyDebugLocation::CreateEmpty(*this);
+  IdentifierInfo *II = &Ctx.Idents.get(Name);
+  FunctionDecl *FD = FunctionDecl::Create(
+  Ctx, Ctx.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), 
II,
+  Ctx.VoidTy, nullptr, SC_PrivateExtern, false, false);
+
+  StartFunction(FD, Ctx.VoidTy, Fn, FI, Args);
+
+  // Create a scope with an artificial location for the body of this function.
+  auto AL = ApplyDebugLocation::CreateArtificial(*this);
+
+  CharUnits Offset;
+  Address BufAddr(Builder.CreateLoad(GetAddrOfLocalVar(&Params[0]), "buf"),
+  BufferAlignment);
+  Builder.CreateStore(Builder.getInt8(Layout.getSummaryByte()),
+  Builder.CreateConstByteGEP(BufAddr, Offset++, 
"summary"));
+  Builder.CreateStore(Builder.getInt8(Layout.getNumArgsByte()),
+  Builder.CreateConstByteGEP(BufAddr,

r315046 - Fix check strings in test case and use llvm::to_string instead of

2017-10-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct  6 00:47:47 2017
New Revision: 315046

URL: http://llvm.org/viewvc/llvm-project?rev=315046&view=rev
Log:
Fix check strings in test case and use llvm::to_string instead of
std::to_string.

These changes were needed to fix bots that started failing after
r315045.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenObjC/os_log.m

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=315046&r1=315045&r2=315046&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Fri Oct  6 00:47:47 2017
@@ -30,6 +30,7 @@
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/MDBuilder.h"
+#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/ConvertUTF.h"
 #include 
 
@@ -698,9 +699,10 @@ llvm::Function *CodeGenFunction::generat
 if (!Size)
   continue;
 
-Params.emplace_back(Ctx, nullptr, SourceLocation(),
-&Ctx.Idents.get(std::string("arg") + 
std::to_string(I)),
-getOSLogArgType(Ctx, Size), ImplicitParamDecl::Other);
+Params.emplace_back(
+Ctx, nullptr, SourceLocation(),
+&Ctx.Idents.get(std::string("arg") + llvm::to_string(I)),
+getOSLogArgType(Ctx, Size), ImplicitParamDecl::Other);
   }
 
   FunctionArgList Args;

Modified: cfe/trunk/test/CodeGenObjC/os_log.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/os_log.m?rev=315046&r1=315045&r2=315046&view=diff
==
--- cfe/trunk/test/CodeGenObjC/os_log.m (original)
+++ cfe/trunk/test/CodeGenObjC/os_log.m Fri Oct  6 00:47:47 2017
@@ -19,10 +19,10 @@ extern __attribute__((visibility("defaul
 void *test_builtin_os_log(void *buf) {
   return __builtin_os_log_format(buf, "capabilities: %@", GenString());
 
-  // CHECK: %[[CALL:.*]] = tail call %[[V0:.*]]* (...) @GenString()
-  // CHECK: %[[V0]] = bitcast %[[V0]]* %[[CALL]] to i8*
+  // CHECK: %[[CALL:.*]] = tail call %[[TY0:.*]]* (...) @GenString()
+  // CHECK: %[[V0:.*]] = bitcast %[[TY0]]* %[[CALL]] to i8*
   // CHECK: %[[V1:.*]] = tail call i8* @objc_retainAutoreleasedReturnValue(i8* 
%[[V0]])
-  // CHECK: %[[V2:.*]] = ptrtoint %[[V0]]* %[[CALL]] to i64
+  // CHECK: %[[V2:.*]] = ptrtoint %[[TY0]]* %[[CALL]] to i64
   // CHECK: store i8 2, i8* %[[BUF]], align 1
   // CHECK: %[[NUMARGS_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 1
   // CHECK: store i8 1, i8* %[[NUMARGS_I]], align 1
@@ -43,13 +43,13 @@ void *test_builtin_os_log(void *buf) {
   // CHECK-O0: %[[BUF_ADDR:.*]] = alloca i8*, align 8
   // CHECK-O0: store i8* %[[BUF]], i8** %[[BUF_ADDR]], align 8
   // CHECK-O0: %[[V0:.*]] = load i8*, i8** %[[BUF_ADDR]], align 8
-  // CHECK-O0: %[[CALL:.*]] = call %[[V0]]* (...) @GenString()
-  // CHECK-O0: %[[V1:.*]] = bitcast %[[V0]]* %[[CALL]] to i8*
+  // CHECK-O0: %[[CALL:.*]] = call %[[TY0:.*]]* (...) @GenString()
+  // CHECK-O0: %[[V1:.*]] = bitcast %[[TY0]]* %[[CALL]] to i8*
   // CHECK-O0: %[[V2:.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* 
%[[V1]])
   // CHECK-O0: %[[V3:.*]] = bitcast i8* %[[V2]] to %[[V0]]*
-  // CHECK-O0: %[[V4:.*]] = ptrtoint %[[V0]]* %[[V3]] to i64
+  // CHECK-O0: %[[V4:.*]] = ptrtoint %[[TY0]]* %[[V3]] to i64
   // CHECK-O0: call void @__os_log_helper_1_2_1_8_64(i8* %[[V0]], i64 %[[V4]])
-  // CHECK-O0: %[[V5:.*]] = bitcast %[[V0]]* %[[V3]] to i8*
+  // CHECK-O0: %[[V5:.*]] = bitcast %[[TY0]]* %[[V3]] to i8*
   // CHECK-O0-NOT call void (...) @clang.arc.use({{.*}}
   // CHECK-O0: call void @objc_release(i8* %[[V5]])
   // CHECK-O0: ret i8* %[[V0]]


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


r315047 - Fix one more check string after r315045.

2017-10-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct  6 01:05:34 2017
New Revision: 315047

URL: http://llvm.org/viewvc/llvm-project?rev=315047&view=rev
Log:
Fix one more check string after r315045.

Modified:
cfe/trunk/test/CodeGenObjC/os_log.m

Modified: cfe/trunk/test/CodeGenObjC/os_log.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/os_log.m?rev=315047&r1=315046&r2=315047&view=diff
==
--- cfe/trunk/test/CodeGenObjC/os_log.m (original)
+++ cfe/trunk/test/CodeGenObjC/os_log.m Fri Oct  6 01:05:34 2017
@@ -33,7 +33,7 @@ void *test_builtin_os_log(void *buf) {
   // CHECK: %[[ARGDATA_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 4
   // CHECK: %[[ARGDATACAST_I:.*]] = bitcast i8* %[[ARGDATA_I]] to i64*
   // CHECK: store i64 %[[V2]], i64* %[[ARGDATACAST_I]], align 1
-  // CHECK: tail call void (...) @clang.arc.use(%[[V0]]* %[[CALL]])
+  // CHECK: tail call void (...) @clang.arc.use(%[[TY0]]* %[[CALL]])
   // CHECK: tail call void @objc_release(i8* %[[V0]])
   // CHECK: ret i8* %[[BUF]]
 


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


r315049 - Fix one more check string after r315045.

2017-10-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct  6 01:19:31 2017
New Revision: 315049

URL: http://llvm.org/viewvc/llvm-project?rev=315049&view=rev
Log:
Fix one more check string after r315045.

Modified:
cfe/trunk/test/CodeGenObjC/os_log.m

Modified: cfe/trunk/test/CodeGenObjC/os_log.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/os_log.m?rev=315049&r1=315048&r2=315049&view=diff
==
--- cfe/trunk/test/CodeGenObjC/os_log.m (original)
+++ cfe/trunk/test/CodeGenObjC/os_log.m Fri Oct  6 01:19:31 2017
@@ -46,7 +46,7 @@ void *test_builtin_os_log(void *buf) {
   // CHECK-O0: %[[CALL:.*]] = call %[[TY0:.*]]* (...) @GenString()
   // CHECK-O0: %[[V1:.*]] = bitcast %[[TY0]]* %[[CALL]] to i8*
   // CHECK-O0: %[[V2:.*]] = call i8* @objc_retainAutoreleasedReturnValue(i8* 
%[[V1]])
-  // CHECK-O0: %[[V3:.*]] = bitcast i8* %[[V2]] to %[[V0]]*
+  // CHECK-O0: %[[V3:.*]] = bitcast i8* %[[V2]] to %[[TY0]]*
   // CHECK-O0: %[[V4:.*]] = ptrtoint %[[TY0]]* %[[V3]] to i64
   // CHECK-O0: call void @__os_log_helper_1_2_1_8_64(i8* %[[V0]], i64 %[[V4]])
   // CHECK-O0: %[[V5:.*]] = bitcast %[[TY0]]* %[[V3]] to i8*


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


r315261 - [Sema][ObjC] Preserve syntactic sugar when removing

2017-10-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Oct  9 18:24:33 2017
New Revision: 315261

URL: http://llvm.org/viewvc/llvm-project?rev=315261&view=rev
Log:
[Sema][ObjC] Preserve syntactic sugar when removing
ARCReclaimReturnedObject cast.

This is a follow-up to r314370.

Rather than throwing away the enclosing parentheses, this commit walks
down the expression until an ARCReclaimReturnedObject cast is found and
removes just the cast, preserving the syntactic sugar expressions
(parens and casts) that were visited up to that point.

rdar://problem/34705720

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

Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=315261&r1=315260&r2=315261&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Mon Oct  9 18:24:33 2017
@@ -4317,14 +4317,37 @@ bool Sema::CheckObjCARCUnavailableWeakCo
 
 /// Look for an ObjCReclaimReturnedObject cast and destroy it.
 static Expr *maybeUndoReclaimObject(Expr *e) {
-  // For now, we just undo operands that are *immediately* reclaim
-  // expressions, which prevents the vast majority of potential
-  // problems here.  To catch them all, we'd need to rebuild arbitrary
-  // value-propagating subexpressions --- we can't reliably rebuild
-  // in-place because of expression sharing.
-  if (auto *ice = dyn_cast(e->IgnoreParens()))
-if (ice->getCastKind() == CK_ARCReclaimReturnedObject)
-  return ice->getSubExpr();
+  Expr *curExpr = e, *prevExpr = nullptr;
+
+  // Walk down the expression until we hit an implicit cast of kind
+  // ARCReclaimReturnedObject or an Expr that is neither a Paren nor a Cast.
+  while (true) {
+if (auto *pe = dyn_cast(curExpr)) {
+  prevExpr = curExpr;
+  curExpr = pe->getSubExpr();
+  continue;
+}
+
+if (auto *ce = dyn_cast(curExpr)) {
+  if (auto *ice = dyn_cast(ce))
+if (ice->getCastKind() == CK_ARCReclaimReturnedObject) {
+  if (!prevExpr)
+return ice->getSubExpr();
+  if (auto *pe = dyn_cast(prevExpr))
+pe->setSubExpr(ice->getSubExpr());
+  else
+cast(prevExpr)->setSubExpr(ice->getSubExpr());
+  return e;
+}
+
+  prevExpr = curExpr;
+  curExpr = ce->getSubExpr();
+  continue;
+}
+
+// Break out of the loop if curExpr is neither a Paren nor a Cast.
+break;
+  }
 
   return e;
 }

Modified: cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m?rev=315261&r1=315260&r2=315261&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-bridged-cast.m Mon Oct  9 18:24:33 2017
@@ -102,5 +102,6 @@ CFStringRef bridge_of_paren_expr() {
   // CHECK-NOT: call i8* @objc_retainAutoreleasedReturnValue(
   // CHECK-NOT: call void @objc_release(
   CFStringRef r = (__bridge CFStringRef)(CreateNSString());
+  r = (__bridge CFStringRef)((NSString *)(CreateNSString()));
   return r;
 }


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


r315639 - [Sema][ObjC] Complete merging ObjC methods before checking their

2017-10-12 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Oct 12 16:24:38 2017
New Revision: 315639

URL: http://llvm.org/viewvc/llvm-project?rev=315639&view=rev
Log:
[Sema][ObjC] Complete merging ObjC methods before checking their
overriding methods.

This should fix test case Analysis/retain-release.m that was failing on
the reverse iteration bot:

http://lab.llvm.org:8011/builders/reverse-iteration

The test used to fail because the loop in CheckObjCMethodOverrides would
merge attribute ns_returns_retained on methods while checking whether
the overriding methods were compatible. Since OverrideSearch::Overridden
is a SmallPtrSet and the order in which the elements of the set are
visited is non-deterministic, the test would fail when method 'clone' of
the protocol 'F18P' was visited before F18(Cat)'s method 'clone' was
visited.

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=315639&r1=315638&r2=315639&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Oct 12 16:24:38 2017
@@ -3580,8 +3580,6 @@ void Sema::mergeObjCMethodDecls(ObjCMeth
  ni = newMethod->param_begin(), ne = newMethod->param_end();
ni != ne && oi != oe; ++ni, ++oi)
 mergeParamDeclAttributes(*ni, *oi, *this);
-
-  CheckObjCMethodOverride(newMethod, oldMethod);
 }
 
 static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl* Old) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=315639&r1=315638&r2=315639&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Oct 12 16:24:38 2017
@@ -4223,6 +4223,10 @@ void Sema::CheckObjCMethodOverrides(ObjC
 
 // Then merge the declarations.
 mergeObjCMethodDecls(ObjCMethod, overridden);
+  }
+
+  for (ObjCMethodDecl *overridden : overrides) {
+CheckObjCMethodOverride(ObjCMethod, overridden);
 
 if (ObjCMethod->isImplicit() && overridden->isImplicit())
   continue; // Conflicting properties are detected elsewhere.


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


r316531 - [Sema][ObjC] Look for either objc_bridge or objc_bridge_mutable when

2017-10-24 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Oct 24 16:38:14 2017
New Revision: 316531

URL: http://llvm.org/viewvc/llvm-project?rev=316531&view=rev
Log:
[Sema][ObjC] Look for either objc_bridge or objc_bridge_mutable when
determining whether a RecordDecl is CFError.

CFErrorRef used to be declared with "objc_bridge(NSError)" but is now
declared with "objc_bridge_mutable(NSError)". Look for either when
checking whether a RecordDecl is CFError.

rdar://problem/35034779

Added:
cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h
cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm
Modified:
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=316531&r1=316530&r2=316531&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue Oct 24 16:38:14 2017
@@ -3482,13 +3482,20 @@ classifyPointerDeclarator(Sema &S, QualT
 isCFError = (S.CFError == recordDecl);
   } else {
 // Check whether this is CFError, which we identify based on its bridge
-// to NSError.
+// to NSError. CFErrorRef used to be declared with "objc_bridge" but is
+// now declared with "objc_bridge_mutable", so look for either one of
+// the two attributes.
 if (recordDecl->getTagKind() == TTK_Struct && numNormalPointers > 0) {
-  if (auto bridgeAttr = recordDecl->getAttr()) {
-if (bridgeAttr->getBridgedType() == S.getNSErrorIdent()) {
-  S.CFError = recordDecl;
-  isCFError = true;
-}
+  IdentifierInfo *bridgedType = nullptr;
+  if (auto bridgeAttr = recordDecl->getAttr())
+bridgedType = bridgeAttr->getBridgedType();
+  else if (auto bridgeAttr =
+   recordDecl->getAttr())
+bridgedType = bridgeAttr->getBridgedType();
+
+  if (bridgedType == S.getNSErrorIdent()) {
+S.CFError = recordDecl;
+isCFError = true;
   }
 }
   }

Added: cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h?rev=316531&view=auto
==
--- cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h (added)
+++ cfe/trunk/test/SemaObjCXX/Inputs/nullability-completeness-cferror.h Tue Oct 
24 16:38:14 2017
@@ -0,0 +1,13 @@
+@class NSError;
+
+#pragma clang assume_nonnull begin
+
+#ifdef USE_MUTABLE
+typedef struct __attribute__((objc_bridge_mutable(NSError))) __CFError * 
CFErrorRef;
+#else
+typedef struct __attribute__((objc_bridge(NSError))) __CFError * CFErrorRef;
+#endif
+
+void func1(CFErrorRef *error);
+
+#pragma clang assume_nonnull end

Added: cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm?rev=316531&view=auto
==
--- cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm (added)
+++ cfe/trunk/test/SemaObjCXX/nullability-completeness-cferror.mm Tue Oct 24 
16:38:14 2017
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs -x objective-c 
-Wnullability-completeness -Werror -verify %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs -x objective-c 
-Wnullability-completeness -Werror -verify -DUSE_MUTABLE %s
+// expected-no-diagnostics
+
+#include "nullability-completeness-cferror.h"


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


r340854 - Define variables in test case rather than using values from functions

2018-08-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Aug 28 11:18:01 2018
New Revision: 340854

URL: http://llvm.org/viewvc/llvm-project?rev=340854&view=rev
Log:
Define variables in test case rather than using values from functions
emitted ealier.

Modified:
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm

Modified: cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm?rev=340854&r1=340853&r2=340854&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm Tue Aug 28 11:18:01 2018
@@ -141,7 +141,7 @@ namespace test1 {
 
 // CHECK: [[LPAD]]:
 // CHECK: invoke void @_ZN5test12S0D1Ev(%[[STRUCT_TEST1_S0]]* %[[V5]])
-// CHECK: to label %[[INVOKE_CONT3:.*]] unwind label %[[TERMINATE_LPAD]]
+// CHECK: to label %[[INVOKE_CONT3:.*]] unwind label %[[TERMINATE_LPAD:.*]]
 
 // CHECK: [[LPAD1]]
 // CHECK: br label %[[EHCLEANUP:.*]]
@@ -154,7 +154,7 @@ namespace test1 {
 // CHECK: %[[V14:.*]] = load i8*, i8** %[[V2]], align 8
 // CHECK: call void @_Block_object_dispose(i8* %[[V14]], i32 8)
 // CHECK: call void @objc_storeStrong(i8** %[[V4]], i8* null)
-// CHECK: br label %[[EH_RESUME]]
+// CHECK: br label %[[EH_RESUME:.*]]
 
 // CHECK: [[EH_RESUME]]:
 // CHECK: resume { i8*, i32 }


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


r341629 - [Sema] Check that the destructor for each element of class type is

2018-09-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Sep  6 19:38:01 2018
New Revision: 341629

URL: http://llvm.org/viewvc/llvm-project?rev=341629&view=rev
Log:
[Sema] Check that the destructor for each element of class type is
accessible from the context where aggregate initialization occurs.

rdar://problem/38168772

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

Added:
cfe/trunk/test/CodeGenObjCXX/arc-list-init-destruct.mm
Modified:
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/SemaCXX/aggregate-initialization.cpp

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=341629&r1=341628&r2=341629&view=diff
==
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Thu Sep  6 19:38:01 2018
@@ -1818,6 +1818,30 @@ bool InitListChecker::CheckFlexibleArray
   return FlexArrayDiag != diag::ext_flexible_array_init;
 }
 
+/// Check if the type of a class element has an accessible destructor.
+///
+/// Aggregate initialization requires a class element's destructor be
+/// accessible per 11.6.1 [dcl.init.aggr]:
+///
+/// The destructor for each element of class type is potentially invoked
+/// (15.4 [class.dtor]) from the context where the aggregate initialization
+/// occurs.
+static bool hasAccessibleDestructor(QualType ElementType, SourceLocation Loc,
+Sema &SemaRef) {
+  auto *CXXRD = ElementType->getAsCXXRecordDecl();
+  if (!CXXRD)
+return false;
+
+  CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
+  SemaRef.CheckDestructorAccess(Loc, Destructor,
+SemaRef.PDiag(diag::err_access_dtor_temp)
+<< ElementType);
+  SemaRef.MarkFunctionReferenced(Loc, Destructor);
+  if (SemaRef.DiagnoseUseOfDecl(Destructor, Loc))
+return true;
+  return false;
+}
+
 void InitListChecker::CheckStructUnionTypes(
 const InitializedEntity &Entity, InitListExpr *IList, QualType DeclType,
 CXXRecordDecl::base_class_range Bases, RecordDecl::field_iterator Field,
@@ -1838,6 +1862,15 @@ void InitListChecker::CheckStructUnionTy
   if (DeclType->isUnionType() && IList->getNumInits() == 0) {
 RecordDecl *RD = DeclType->getAs()->getDecl();
 
+if (!VerifyOnly)
+  for (FieldDecl *FD : RD->fields()) {
+QualType ET = SemaRef.Context.getBaseElementType(FD->getType());
+if (hasAccessibleDestructor(ET, IList->getEndLoc(), SemaRef)) {
+  hadError = true;
+  return;
+}
+  }
+
 // If there's a default initializer, use it.
 if (isa(RD) && 
cast(RD)->hasInClassInitializer()) {
   if (VerifyOnly)
@@ -1874,13 +1907,13 @@ void InitListChecker::CheckStructUnionTy
   // If we have any base classes, they are initialized prior to the fields.
   for (auto &Base : Bases) {
 Expr *Init = Index < IList->getNumInits() ? IList->getInit(Index) : 
nullptr;
-SourceLocation InitLoc = Init ? Init->getBeginLoc() : IList->getEndLoc();
 
 // Designated inits always initialize fields, so if we see one, all
 // remaining base classes have no explicit initializer.
 if (Init && isa(Init))
   Init = nullptr;
 
+SourceLocation InitLoc = Init ? Init->getBeginLoc() : IList->getEndLoc();
 InitializedEntity BaseEntity = InitializedEntity::InitializeBase(
 SemaRef.Context, &Base, false, &Entity);
 if (Init) {
@@ -1890,6 +1923,12 @@ void InitListChecker::CheckStructUnionTy
 } else if (VerifyOnly) {
   CheckEmptyInitializable(BaseEntity, InitLoc);
 }
+
+if (!VerifyOnly)
+  if (hasAccessibleDestructor(Base.getType(), InitLoc, SemaRef)) {
+hadError = true;
+return;
+  }
   }
 
   // If structDecl is a forward declaration, this loop won't do
@@ -1900,9 +1939,11 @@ void InitListChecker::CheckStructUnionTy
   RecordDecl::field_iterator FieldEnd = RD->field_end();
   bool CheckForMissingFields =
 !IList->isIdiomaticZeroInitializer(SemaRef.getLangOpts());
+  bool HasDesignatedInit = false;
 
   while (Index < IList->getNumInits()) {
 Expr *Init = IList->getInit(Index);
+SourceLocation InitLoc = Init->getBeginLoc();
 
 if (DesignatedInitExpr *DIE = dyn_cast(Init)) {
   // If we're not the subobject that matches up with the '{' for
@@ -1911,6 +1952,8 @@ void InitListChecker::CheckStructUnionTy
   if (!SubobjectIsDesignatorContext)
 return;
 
+  HasDesignatedInit = true;
+
   // Handle this designated initializer. Field will be updated to
   // the next field that we'll be initializing.
   if (CheckDesignatedInitializer(Entity, IList, DIE, 0,
@@ -1918,6 +1961,17 @@ void InitListChecker::CheckStructUnionTy
  StructuredList, StructuredIndex,
  true, TopLevelObject))
 hadError = true;
+  else if (!VerifyOnly) {
+// Fi

r341754 - Distinguish `__block` variables that are captured by escaping blocks

2018-09-08 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Sep  8 13:03:00 2018
New Revision: 341754

URL: http://llvm.org/viewvc/llvm-project?rev=341754&view=rev
Log:
Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

rdar://problem/39352313

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

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/block-byref-aggr.c
cfe/trunk/test/CodeGen/blocks-seq.c
cfe/trunk/test/CodeGen/exceptions.c
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/block-capture.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/noescape.cpp
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/arc-unoptimized-byref-var.m
cfe/trunk/test/CodeGenObjC/blocks-1.m
cfe/trunk/test/CodeGenObjC/noescape.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/SemaObjCXX/blocks.mm
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=341754&r1=341753&r2=341754&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Sep  8 13:03:00 2018
@@ -965,6 +965,8 @@ protected:
 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
 /// something else.
 unsigned ImplicitParamKind : 3;
+
+unsigned EscapingByref : 1;
   };
 
   union {
@@ -1407,6 +1409,19 @@ public:
 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
   }
 
+  /// Indicates the capture is a __block variable that is captured by a block
+  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
+  /// returns false).
+  bool isEscapingByref() const;
+
+  /// Indicates the capture is a __block variable that is never captured by an
+  /// escaping block.
+  bool isNonEscapingByref() const;
+
+  void setEscapingByref() {
+NonParmVarDeclBits.EscapingByref = true;
+  }
+
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;
@@ -3858,6 +3873,14 @@ public:
 /// variable.
 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
 
+bool isEscapingByref() const {
+  return getVariable()->isEscapingByref();
+}
+
+bool isNonEscapingByref() const {
+  return getVariable()->isNonEscapingByref();
+}
+
 /// Whether this is a nested capture, i.e. the variable captured
 /// is not from outside the immediately enclosing function/block.
 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=341754&r1=341753&r2=341754&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Sat Sep  8 13:03:00 2018
@@ -31,6 +31,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
@@ -202,6 +203,12 @@ public:
   /// function.
   SmallVector CompoundScopes;
 
+  /// The set of blocks that are introduced in this function.
+  llvm::SmallPtrSet Blocks;
+
+  /// The set of __block variables that are introduced in this function.
+  

r341757 - Revert r341754.

2018-09-08 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Sep  8 22:22:49 2018
New Revision: 341757

URL: http://llvm.org/viewvc/llvm-project?rev=341757&view=rev
Log:
Revert r341754.

The commit broke a couple of bots:

http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/12347
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/7310

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/block-byref-aggr.c
cfe/trunk/test/CodeGen/blocks-seq.c
cfe/trunk/test/CodeGen/exceptions.c
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/block-capture.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/noescape.cpp
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/arc-unoptimized-byref-var.m
cfe/trunk/test/CodeGenObjC/blocks-1.m
cfe/trunk/test/CodeGenObjC/noescape.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/SemaObjCXX/blocks.mm
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=341757&r1=341756&r2=341757&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Sep  8 22:22:49 2018
@@ -965,8 +965,6 @@ protected:
 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
 /// something else.
 unsigned ImplicitParamKind : 3;
-
-unsigned EscapingByref : 1;
   };
 
   union {
@@ -1409,19 +1407,6 @@ public:
 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
   }
 
-  /// Indicates the capture is a __block variable that is captured by a block
-  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
-  /// returns false).
-  bool isEscapingByref() const;
-
-  /// Indicates the capture is a __block variable that is never captured by an
-  /// escaping block.
-  bool isNonEscapingByref() const;
-
-  void setEscapingByref() {
-NonParmVarDeclBits.EscapingByref = true;
-  }
-
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;
@@ -3873,14 +3858,6 @@ public:
 /// variable.
 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
 
-bool isEscapingByref() const {
-  return getVariable()->isEscapingByref();
-}
-
-bool isNonEscapingByref() const {
-  return getVariable()->isNonEscapingByref();
-}
-
 /// Whether this is a nested capture, i.e. the variable captured
 /// is not from outside the immediately enclosing function/block.
 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=341757&r1=341756&r2=341757&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Sat Sep  8 22:22:49 2018
@@ -31,7 +31,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
@@ -203,12 +202,6 @@ public:
   /// function.
   SmallVector CompoundScopes;
 
-  /// The set of blocks that are introduced in this function.
-  llvm::SmallPtrSet Blocks;
-
-  /// The set of __block variables that are introduced in this function.
-  llvm::TinyPtrVector ByrefBlockVars;
-
   /// A list of PartialDiagnostics created but delayed within the
   /// current function scope.  These diagnostics are vetted for reachability
   /// prior to being emitted.
@@ -433,16 +426,6 @@ public:
   (HasBranchProtectedScope && HasBranchIntoScope));
   }
 
-  // Add a block introduced in this function.
-  void addBlock(const BlockDecl *BD) {
-Blocks.insert(BD);
-  }
-
-  // Add a __block variable introduced in this function.
-  void addByrefBlockVar(VarDecl *VD) {
-ByrefBlockVars.push_back(VD);
-  }
-
   bool isCoroutine() const { return !FirstCo

r337580 - [CodeGen][ObjC] Make copying and disposing of a non-escaping block

2018-07-20 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Jul 20 10:10:32 2018
New Revision: 337580

URL: http://llvm.org/viewvc/llvm-project?rev=337580&view=rev
Log:
[CodeGen][ObjC] Make copying and disposing of a non-escaping block
no-ops.

A non-escaping block on the stack will never be called after its
lifetime ends, so it doesn't have to be copied to the heap. To prevent
a non-escaping block from being copied to the heap, this patch sets
field 'isa' of the block object to NSConcreteGlobalBlock and sets the
BLOCK_IS_GLOBAL bit of field 'flags', which causes the runtime to treat
the block as if it were a global block (calling _Block_copy on the block
just returns the original block and calling _Block_release is a no-op).

Also, a new flag bit 'BLOCK_IS_NOESCAPE' is added, which allows the
runtime or tools to distinguish between true global blocks and
non-escaping blocks.

rdar://problem/39352313

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

Modified:
cfe/trunk/docs/Block-ABI-Apple.rst
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGBlocks.h
cfe/trunk/test/CodeGenObjC/noescape.m

Modified: cfe/trunk/docs/Block-ABI-Apple.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Block-ABI-Apple.rst?rev=337580&r1=337579&r2=337580&view=diff
==
--- cfe/trunk/docs/Block-ABI-Apple.rst (original)
+++ cfe/trunk/docs/Block-ABI-Apple.rst Fri Jul 20 10:10:32 2018
@@ -61,6 +61,14 @@ The following flags bits are in use thus
 .. code-block:: c
 
 enum {
+// Set to true on blocks that have captures (and thus are not true
+// global blocks) but are known not to escape for various other
+// reasons. For backward compatiblity with old runtimes, whenever
+// BLOCK_IS_NOESCAPE is set, BLOCK_IS_GLOBAL is set too. Copying a
+// non-escaping block returns the original block and releasing such a
+// block is a no-op, which is exactly how global blocks are handled.
+BLOCK_IS_NOESCAPE  =  (1 << 23),
+
 BLOCK_HAS_COPY_DISPOSE =  (1 << 25),
 BLOCK_HAS_CTOR =  (1 << 26), // helpers have C++ code
 BLOCK_IS_GLOBAL = (1 << 28),

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=337580&r1=337579&r2=337580&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Jul 20 10:10:32 2018
@@ -104,7 +104,7 @@ static llvm::Constant *buildBlockDescrip
   elements.addInt(ulong, blockInfo.BlockSize.getQuantity());
 
   // Optional copy/dispose helpers.
-  if (blockInfo.NeedsCopyDispose) {
+  if (blockInfo.needsCopyDisposeHelpers()) {
 // copy_func_helper_decl
 elements.add(buildCopyHelper(CGM, blockInfo));
 
@@ -159,6 +159,7 @@ static llvm::Constant *buildBlockDescrip
 
 /// These are the flags (with corresponding bit number) that the
 /// compiler is actually supposed to know about.
+///  23. BLOCK_IS_NOESCAPE - indicates that the block is non-escaping
 ///  25. BLOCK_HAS_COPY_DISPOSE - indicates that the block
 ///   descriptor provides copy and dispose helper functions
 ///  26. BLOCK_HAS_CXX_OBJ - indicates that there's a captured
@@ -778,8 +779,13 @@ llvm::Value *CodeGenFunction::EmitBlockL
   llvm::Constant *descriptor;
   BlockFlags flags;
   if (!IsOpenCL) {
-isa = llvm::ConstantExpr::getBitCast(CGM.getNSConcreteStackBlock(),
- VoidPtrTy);
+// If the block is non-escaping, set field 'isa 'to NSConcreteGlobalBlock
+// and set the BLOCK_IS_GLOBAL bit of field 'flags'. Copying a non-escaping
+// block just returns the original block and releasing it is a no-op.
+llvm::Constant *blockISA = blockInfo.getBlockDecl()->doesNotEscape()
+   ? CGM.getNSConcreteGlobalBlock()
+   : CGM.getNSConcreteStackBlock();
+isa = llvm::ConstantExpr::getBitCast(blockISA, VoidPtrTy);
 
 // Build the block descriptor.
 descriptor = buildBlockDescriptor(CGM, blockInfo);
@@ -788,12 +794,14 @@ llvm::Value *CodeGenFunction::EmitBlockL
 flags = BLOCK_HAS_SIGNATURE;
 if (blockInfo.HasCapturedVariableLayout)
   flags |= BLOCK_HAS_EXTENDED_LAYOUT;
-if (blockInfo.NeedsCopyDispose)
+if (blockInfo.needsCopyDisposeHelpers())
   flags |= BLOCK_HAS_COPY_DISPOSE;
 if (blockInfo.HasCXXObject)
   flags |= BLOCK_HAS_CXX_OBJ;
 if (blockInfo.UsesStret)
   flags |= BLOCK_USE_STRET;
+if (blockInfo.getBlockDecl()->doesNotEscape())
+  flags |= BLOCK_IS_NOESCAPE | BLOCK_IS_GLOBAL;
   }
 
   auto projectField =

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

r338041 - [CodeGen][ObjC] Make block copy/dispose helper functions exception-safe.

2018-07-26 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jul 26 09:51:21 2018
New Revision: 338041

URL: http://llvm.org/viewvc/llvm-project?rev=338041&view=rev
Log:
[CodeGen][ObjC] Make block copy/dispose helper functions exception-safe.

When an exception is thrown in a block copy helper function, captured
objects that have previously been copied should be destructed or
released. Similarly, captured objects that are yet to be released should
be released when an exception is thrown in a dispose helper function.

rdar://problem/42410255

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/test/CodeGenObjC/blocks.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=338041&r1=338040&r2=338041&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Jul 26 09:51:21 2018
@@ -1585,6 +1585,64 @@ static void findBlockCapturedManagedEnti
   }
 }
 
+namespace {
+/// Release a __block variable.
+struct CallBlockRelease final : EHScopeStack::Cleanup {
+  Address Addr;
+  BlockFieldFlags FieldFlags;
+  bool LoadBlockVarAddr;
+
+  CallBlockRelease(Address Addr, BlockFieldFlags Flags, bool LoadValue)
+  : Addr(Addr), FieldFlags(Flags), LoadBlockVarAddr(LoadValue) {}
+
+  void Emit(CodeGenFunction &CGF, Flags flags) override {
+llvm::Value *BlockVarAddr;
+if (LoadBlockVarAddr) {
+  BlockVarAddr = CGF.Builder.CreateLoad(Addr);
+  BlockVarAddr = CGF.Builder.CreateBitCast(BlockVarAddr, CGF.VoidPtrTy);
+} else {
+  BlockVarAddr = Addr.getPointer();
+}
+
+CGF.BuildBlockRelease(BlockVarAddr, FieldFlags);
+  }
+};
+} // end anonymous namespace
+
+static void pushCaptureCleanup(BlockCaptureEntityKind CaptureKind,
+   Address Field, QualType CaptureType,
+   BlockFieldFlags Flags, bool EHOnly,
+   CodeGenFunction &CGF) {
+  switch (CaptureKind) {
+  case BlockCaptureEntityKind::CXXRecord:
+  case BlockCaptureEntityKind::ARCWeak:
+  case BlockCaptureEntityKind::NonTrivialCStruct:
+  case BlockCaptureEntityKind::ARCStrong: {
+if (CaptureType.isDestructedType() &&
+(!EHOnly || CGF.needsEHCleanup(CaptureType.isDestructedType( {
+  CodeGenFunction::Destroyer *Destroyer =
+  CaptureKind == BlockCaptureEntityKind::ARCStrong
+  ? CodeGenFunction::destroyARCStrongImprecise
+  : CGF.getDestroyer(CaptureType.isDestructedType());
+  CleanupKind Kind =
+  EHOnly ? EHCleanup
+ : CGF.getCleanupKind(CaptureType.isDestructedType());
+  CGF.pushDestroy(Kind, Field, CaptureType, Destroyer, Kind & EHCleanup);
+}
+break;
+  }
+  case BlockCaptureEntityKind::BlockObject: {
+if (!EHOnly || CGF.getLangOpts().Exceptions) {
+  CleanupKind Kind = EHOnly ? EHCleanup : NormalAndEHCleanup;
+  CGF.enterByrefCleanup(Kind, Field, Flags, /*LoadBlockVarAddr*/ true);
+}
+break;
+  }
+  case BlockCaptureEntityKind::None:
+llvm_unreachable("unexpected BlockCaptureEntityKind");
+  }
+}
+
 /// Generate the copy-helper function for a block closure object:
 ///   static void block_copy_helper(block_t *dst, block_t *src);
 /// The runtime will have previously initialized 'dst' by doing a
@@ -1648,6 +1706,7 @@ CodeGenFunction::GenerateCopyHelperFunct
   for (const auto &CopiedCapture : CopiedCaptures) {
 const BlockDecl::Capture &CI = CopiedCapture.CI;
 const CGBlockInfo::Capture &capture = CopiedCapture.Capture;
+QualType captureType = CI.getVariable()->getType();
 BlockFieldFlags flags = CopiedCapture.Flags;
 
 unsigned index = capture.getIndex();
@@ -1685,9 +1744,11 @@ CodeGenFunction::GenerateCopyHelperFunct
 } else {
   EmitARCRetainNonBlock(srcValue);
 
-  // We don't need this anymore, so kill it.  It's not quite
-  // worth the annoyance to avoid creating it in the first place.
-  cast(dstField.getPointer())->eraseFromParent();
+  // Unless EH cleanup is required, we don't need this anymore, so kill
+  // it. It's not quite worth the annoyance to avoid creating it in the
+  // first place.
+  if (!needsEHCleanup(captureType.isDestructedType()))
+cast(dstField.getPointer())->eraseFromParent();
 }
   } else {
 assert(CopiedCapture.Kind == BlockCaptureEntityKind::BlockObject);
@@ -1715,6 +1776,11 @@ CodeGenFunction::GenerateCopyHelperFunct
 }
   }
 }
+
+// Ensure that we destroy the copied object if an exception is thrown later
+// in the helper function.
+pushCaptureCleanup(CopiedCapture.Kind, dstField, captureType, flags, 
/*E

r338048 - [Sema][ObjC] Do not propagate the nullability specifier on the receiver

2018-07-26 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jul 26 10:51:13 2018
New Revision: 338048

URL: http://llvm.org/viewvc/llvm-project?rev=338048&view=rev
Log:
[Sema][ObjC] Do not propagate the nullability specifier on the receiver
to the result type of a message send if the result type cannot have a
nullability specifier.

Previously, clang would print the following message when the code in
nullability.m was compiled:

"incompatible integer to pointer conversion initializing 'int *' with
an expression of type 'int _Nullable'"

This is wrong as 'int' isn't supposed to have any nullability
specifiers.

rdar://problem/40830514

Modified:
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/nullability.m

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=338048&r1=338047&r2=338048&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Jul 26 10:51:13 2018
@@ -1357,6 +1357,11 @@ QualType Sema::getMessageSendResultType(
   if (isClassMessage)
 return resultType;
 
+  // There is nothing left to do if the result type cannot have a nullability
+  // specifier.
+  if (!resultType->canHaveNullability())
+return resultType;
+
   // Map the nullability of the result into a table index.
   unsigned receiverNullabilityIdx = 0;
   if (auto nullability = ReceiverType->getNullability(Context))

Modified: cfe/trunk/test/SemaObjC/nullability.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/nullability.m?rev=338048&r1=338047&r2=338048&view=diff
==
--- cfe/trunk/test/SemaObjC/nullability.m (original)
+++ cfe/trunk/test/SemaObjC/nullability.m Thu Jul 26 10:51:13 2018
@@ -279,3 +279,14 @@ void test(ArraysInMethods *obj) {
   [obj simpleSugar:0]; // expected-warning {{null passed to a callee that 
requires a non-null argument}}
   [obj sugarWithTypedef:0]; // expected-warning {{null passed to a callee that 
requires a non-null argument}}
 }
+
+// Check that we don't propagate the nullability specifier on the receiver to
+// the result type of a message send if the result type cannot have a
+// nullability specifier.
+@interface C0
+-(int) count;
+@end
+
+void testMessageSendResultType(C0 * _Nullable c0) {
+  int *p = [c0 count]; // expected-warning {{incompatible integer to pointer 
conversion initializing 'int *' with an expression of type 'int'}}
+}


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


r338189 - [Sema][ObjC] Warn when a method declared in a protocol takes a

2018-07-27 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Jul 27 21:06:13 2018
New Revision: 338189

URL: http://llvm.org/viewvc/llvm-project?rev=338189&view=rev
Log:
[Sema][ObjC] Warn when a method declared in a protocol takes a
non-escaping parameter but the implementation's method takes an escaping
parameter.

rdar://problem/39548196

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=338189&r1=338188&r2=338189&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 27 21:06:13 
2018
@@ -1733,6 +1733,8 @@ def warn_overriding_method_missing_noesc
   "__attribute__((noescape))">, InGroup;
 def note_overridden_marked_noescape : Note<
   "parameter of overridden method is annotated with 
__attribute__((noescape))">;
+def note_cat_conform_to_noescape_prot : Note<
+  "%select{category|class extension}0 conforms to protocol %1 which defines 
method %2">;
 
 def err_covariant_return_inaccessible_base : Error<
   "invalid covariant return for virtual function: %1 is a "

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=338189&r1=338188&r2=338189&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Jul 27 21:06:13 2018
@@ -109,6 +109,30 @@ bool Sema::checkInitMethod(ObjCMethodDec
   return true;
 }
 
+/// Issue a warning if the parameter of the overridden method is non-escaping
+/// but the parameter of the overriding method is not.
+static bool diagnoseNoescape(const ParmVarDecl *NewD, const ParmVarDecl *OldD,
+ Sema &S) {
+  if (OldD->hasAttr() && !NewD->hasAttr()) {
+S.Diag(NewD->getLocation(), diag::warn_overriding_method_missing_noescape);
+S.Diag(OldD->getLocation(), diag::note_overridden_marked_noescape);
+return false;
+  }
+
+  return true;
+}
+
+/// Produce additional diagnostics if a category conforms to a protocol that
+/// defines a method taking a non-escaping parameter.
+static void diagnoseNoescape(const ParmVarDecl *NewD, const ParmVarDecl *OldD,
+ const ObjCCategoryDecl *CD,
+ const ObjCProtocolDecl *PD, Sema &S) {
+  if (!diagnoseNoescape(NewD, OldD, S))
+S.Diag(CD->getLocation(), diag::note_cat_conform_to_noescape_prot)
+<< CD->IsClassExtension() << PD
+<< cast(NewD->getDeclContext());
+}
+
 void Sema::CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 
const ObjCMethodDecl *Overridden) {
   if (Overridden->hasRelatedResultType() && 
@@ -192,13 +216,7 @@ void Sema::CheckObjCMethodOverride(ObjCM
   Diag(oldDecl->getLocation(), diag::note_previous_decl) << "parameter";
 }
 
-// A parameter of the overriding method should be annotated with noescape
-// if the corresponding parameter of the overridden method is annotated.
-if (oldDecl->hasAttr() && !newDecl->hasAttr()) 
{
-  Diag(newDecl->getLocation(),
-   diag::warn_overriding_method_missing_noescape);
-  Diag(oldDecl->getLocation(), diag::note_overridden_marked_noescape);
-}
+diagnoseNoescape(newDecl, oldDecl, *this);
   }
 }
 
@@ -4643,6 +4661,22 @@ Decl *Sema::ActOnMethodDeclaration(
 << ObjCMethod->getDeclName();
 }
   }
+
+  // Warn if a method declared in a protocol to which a category or
+  // extension conforms is non-escaping and the implementation's method is
+  // escaping.
+  for (auto *C : IDecl->visible_categories())
+for (auto &P : C->protocols())
+  if (auto *IMD = P->lookupMethod(ObjCMethod->getSelector(),
+  ObjCMethod->isInstanceMethod())) {
+assert(ObjCMethod->parameters().size() ==
+   IMD->parameters().size() &&
+   "Methods have different number of parameters");
+auto OI = IMD->param_begin(), OE = IMD->param_end();
+auto NI = ObjCMethod->param_begin();
+for (; OI != OE; ++OI, ++NI)
+  diagnoseNoescape(*NI, *OI, C, P, *this);
+  }
 }
   } else {
 cast(ClassDecl)->addDecl(ObjCMethod);

Modified: cfe/trunk/test/SemaObjCXX/noescape.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/noescape.mm?rev=338189&r1=338188&r2=338189&view=diff
==
--- cfe/trunk/test/SemaObjCXX/noescape.mm (original

r338656 - Serialize DoesNotEscape.

2018-08-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Aug  1 16:51:53 2018
New Revision: 338656

URL: http://llvm.org/viewvc/llvm-project?rev=338656&view=rev
Log:
Serialize DoesNotEscape.

I forgot to commit this in r326530.

Added:
cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp
cfe/trunk/test/PCH/no-escaping-block-tail-calls.h
Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=338656&r1=338655&r2=338656&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Wed Aug  1 16:51:53 2018
@@ -1472,6 +1472,7 @@ void ASTDeclReader::VisitBlockDecl(Block
   BD->setIsVariadic(Record.readInt());
   BD->setBlockMissingReturnType(Record.readInt());
   BD->setIsConversionFromLambda(Record.readInt());
+  BD->setDoesNotEscape(Record.readInt());
 
   bool capturesCXXThis = Record.readInt();
   unsigned numCaptures = Record.readInt();

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=338656&r1=338655&r2=338656&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Wed Aug  1 16:51:53 2018
@@ -1097,6 +1097,7 @@ void ASTDeclWriter::VisitBlockDecl(Block
   Record.push_back(D->isVariadic());
   Record.push_back(D->blockMissingReturnType());
   Record.push_back(D->isConversionFromLambda());
+  Record.push_back(D->doesNotEscape());
   Record.push_back(D->capturesCXXThis());
   Record.push_back(D->getNumCaptures());
   for (const auto &capture : D->captures()) {

Added: cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp?rev=338656&view=auto
==
--- cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp (added)
+++ cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp Wed Aug  1 16:51:53 2018
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -x c++-header -emit-pch -O1 -fblocks 
-fno-escaping-block-tail-calls -o %t %S/no-escaping-block-tail-calls.h
+// RUN: %clang_cc1 -include-pch %t -emit-llvm -O1 -fblocks 
-fno-escaping-block-tail-calls -o - %s | FileCheck %s
+
+// Check that -fno-escaping-block-tail-calls doesn't disable tail-call
+// optimization if the block is non-escaping.
+
+// CHECK-LABEL: define internal i32 @___ZN1S1mEv_block_invoke(
+// CHECK: %[[CALL:.*]] = tail call i32 @_ZN1S3fooER2S0(
+// CHECK-NEXT: ret i32 %[[CALL]]
+
+void test() {
+  S s;
+  s.m();
+}

Added: cfe/trunk/test/PCH/no-escaping-block-tail-calls.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/no-escaping-block-tail-calls.h?rev=338656&view=auto
==
--- cfe/trunk/test/PCH/no-escaping-block-tail-calls.h (added)
+++ cfe/trunk/test/PCH/no-escaping-block-tail-calls.h Wed Aug  1 16:51:53 2018
@@ -0,0 +1,16 @@
+typedef int (^BlockTy)(void);
+
+struct S0 {
+  int a;
+};
+
+struct S {
+  int i;
+  void func(BlockTy __attribute__((noescape)));
+  int foo(S0 &);
+
+  void m() {
+__block S0 x;
+func(^{ return foo(x); });
+  }
+};


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


r338664 - Pass triple to RUN line to fix failing bots.

2018-08-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Aug  1 18:52:17 2018
New Revision: 338664

URL: http://llvm.org/viewvc/llvm-project?rev=338664&view=rev
Log:
Pass triple to RUN line to fix failing bots.

This is a follow-up to r338656.

Modified:
cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp

Modified: cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp?rev=338664&r1=338663&r2=338664&view=diff
==
--- cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp (original)
+++ cfe/trunk/test/PCH/no-escaping-block-tail-calls.cpp Wed Aug  1 18:52:17 2018
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -x c++-header -emit-pch -O1 -fblocks 
-fno-escaping-block-tail-calls -o %t %S/no-escaping-block-tail-calls.h
-// RUN: %clang_cc1 -include-pch %t -emit-llvm -O1 -fblocks 
-fno-escaping-block-tail-calls -o - %s | FileCheck %s
+// RUN: %clang_cc1 -x c++-header -triple x86_64-apple-darwin11 -emit-pch -O1 
-fblocks -fno-escaping-block-tail-calls -o %t %S/no-escaping-block-tail-calls.h
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -include-pch %t -emit-llvm 
-O1 -fblocks -fno-escaping-block-tail-calls -o - %s | FileCheck %s
 
 // Check that -fno-escaping-block-tail-calls doesn't disable tail-call
 // optimization if the block is non-escaping.


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


r324269 - Add support for attribute 'trivial_abi'.

2018-02-05 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Feb  5 12:23:22 2018
New Revision: 324269

URL: http://llvm.org/viewvc/llvm-project?rev=324269&view=rev
Log:
Add support for attribute 'trivial_abi'.

The 'trivial_abi' attribute can be applied to a C++ class, struct, or
union. It makes special functions of the annotated class (the destructor
and copy/move constructors) to be trivial for the purpose of calls and,
as a result, enables the annotated class or containing classes to be
passed or returned using the C ABI for the underlying type.

When a type that is considered trivial for the purpose of calls despite
having a non-trivial destructor (which happens only when the class type
or one of its subobjects is a 'trivial_abi' class) is passed to a
function, the callee is responsible for destroying the object.

For more background, see the discussions that took place on the mailing
list:

http://lists.llvm.org/pipermail/cfe-dev/2017-November/055955.html
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180101/thread.html#214043

rdar://problem/35204524

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

Added:
cfe/trunk/test/CodeGenCXX/trivial_abi.cpp
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/Misc/pragma-attribute-supported-attributes-list.test

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=324269&r1=324268&r2=324269&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Mon Feb  5 12:23:22 2018
@@ -1179,6 +1179,10 @@ public:
const FunctionProtoType::ExceptionSpecInfo &ESI,
bool AsWritten = false);
 
+  /// Determine whether a type is a class that should be detructed in the
+  /// callee function.
+  bool isParamDestroyedInCallee(QualType T) const;
+
   /// \brief Return the uniqued reference to the type for a complex
   /// number with the specified element type.
   QualType getComplexType(QualType T) const;

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=324269&r1=324268&r2=324269&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Feb  5 12:23:22 2018
@@ -1731,6 +1731,12 @@ private:
   unsigned HasWrittenPrototype : 1;
   unsigned IsDeleted : 1;
   unsigned IsTrivial : 1; // sunk from CXXMethodDecl
+
+  /// This flag indicates whether this function is trivial for the purpose of
+  /// calls. This is meaningful only when this function is a copy/move
+  /// constructor or a destructor.
+  unsigned IsTrivialForCall : 1;
+
   unsigned IsDefaulted : 1; // sunk from CXXMethoDecl
   unsigned IsExplicitlyDefaulted : 1; //sunk from CXXMethodDecl
   unsigned HasImplicitReturnZero : 1;
@@ -1845,7 +1851,8 @@ protected:
 IsInline(isInlineSpecified), IsInlineSpecified(isInlineSpecified),
 IsExplicitSpecified(false), IsVirtualAsWritten(false), IsPure(false),
 HasInheritedPrototype(false), HasWrittenPrototype(true),
-IsDeleted(false), IsTrivial(false), IsDefaulted(false),
+IsDeleted(false), IsTrivial(false), IsTrivialForCall(false),
+IsDefaulted(false),
 IsExplicitlyDefaulted(false), HasImplicitReturnZero(false),
 IsLateTemplateParsed(false), IsConstexpr(isConstexprSpecified),
 InstantiationIsPending(false), UsesSEHTry(false), 
HasSkippedBody(false),
@@ -2010,6 +2017,9 @@ public:
   bool isTrivial() const { return IsTrivial; }
   void setTrivial(bool IT) { IsTrivial = IT; }
 
+  bool isTrivialForCall() const { return IsTrivialForCall; }
+  void setTrivialForCall(bool IT) { IsTrivialForCall = IT; }
+
   /// Whether this function is defaulted p

r324425 - [Sema][ObjC] Use SmallSetVector to fix a failing test on the reverse

2018-02-06 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Feb  6 15:44:40 2018
New Revision: 324425

URL: http://llvm.org/viewvc/llvm-project?rev=324425&view=rev
Log:
[Sema][ObjC] Use SmallSetVector to fix a failing test on the reverse
iteration bot.

This commit reverts r315639, which was causing clang to print
diagnostics that weren't printed before. Instead, it declares
OverrideSearch::Overridden as a SmallSetVector to fix the
non-deterministic behavior r315639 was trying to fix.

rdar://problem/36445528

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/arc-decls.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=324425&r1=324424&r2=324425&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb  6 15:44:40 2018
@@ -3623,6 +3623,8 @@ void Sema::mergeObjCMethodDecls(ObjCMeth
  ni = newMethod->param_begin(), ne = newMethod->param_end();
ni != ne && oi != oe; ++ni, ++oi)
 mergeParamDeclAttributes(*ni, *oi, *this);
+
+  CheckObjCMethodOverride(newMethod, oldMethod);
 }
 
 static void diagnoseVarDeclTypeMismatch(Sema &S, VarDecl *New, VarDecl* Old) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=324425&r1=324424&r2=324425&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Feb  6 15:44:40 2018
@@ -4133,7 +4133,7 @@ class OverrideSearch {
 public:
   Sema &S;
   ObjCMethodDecl *Method;
-  llvm::SmallPtrSet Overridden;
+  llvm::SmallSetVector Overridden;
   bool Recursive;
 
 public:
@@ -4170,7 +4170,7 @@ public:
 }
   }
 
-  typedef llvm::SmallPtrSetImpl::iterator iterator;
+  typedef decltype(Overridden)::iterator iterator;
   iterator begin() const { return Overridden.begin(); }
   iterator end() const { return Overridden.end(); }
 
@@ -4338,10 +4338,6 @@ void Sema::CheckObjCMethodOverrides(ObjC
 
 // Then merge the declarations.
 mergeObjCMethodDecls(ObjCMethod, overridden);
-  }
-
-  for (ObjCMethodDecl *overridden : overrides) {
-CheckObjCMethodOverride(ObjCMethod, overridden);
 
 if (ObjCMethod->isImplicit() && overridden->isImplicit())
   continue; // Conflicting properties are detected elsewhere.

Modified: cfe/trunk/test/SemaObjC/arc-decls.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-decls.m?rev=324425&r1=324424&r2=324425&view=diff
==
--- cfe/trunk/test/SemaObjC/arc-decls.m (original)
+++ cfe/trunk/test/SemaObjC/arc-decls.m Tue Feb  6 15:44:40 2018
@@ -154,3 +154,25 @@ struct __attribute__((objc_ownership(non
 
 @property (readwrite, weak) ControllerClass *weak_controller;
 @end
+
+@interface I3
+@end
+
+@interface D3 : I3
+@end
+
+@interface D3 (Cat1)
+- (id)method;
+@end
+
+@interface I3 (Cat2)
+// FIXME: clang should diagnose mismatch between methods in D3(Cat1) and
+//I3(Cat2).
+- (id)method __attribute__((ns_returns_retained));
+@end
+
+@implementation D3
+- (id)method {
+  return (id)0;
+}
+@end


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


r324765 - Remove "CHECK: entry" in test case.

2018-02-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Feb  9 11:25:31 2018
New Revision: 324765

URL: http://llvm.org/viewvc/llvm-project?rev=324765&view=rev
Log:
Remove "CHECK: entry" in test case.

rdar://problem/37397814

Modified:
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm

Modified: cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm?rev=324765&r1=324764&r2=324765&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm Fri Feb  9 11:25:31 2018
@@ -81,7 +81,6 @@ void testCallStrong(Strong *a) {
 }
 
 // CHECK: define i64 @_Z16testReturnStrongP6Strong(%[[STRUCT_STRONG]]* 
%[[A:.*]])
-// CHECK: entry:
 // CHECK: %[[RETVAL:.*]] = alloca %[[STRUCT_STRONG]], align 8
 // CHECK: %[[A_ADDR:.*]] = alloca %[[STRUCT_STRONG]]*, align 8
 // CHECK: store %[[STRUCT_STRONG]]* %[[A]], %[[STRUCT_STRONG]]** %[[A_ADDR]], 
align 8


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


r325321 - [Sema] Take into account the current context when checking the

2018-02-16 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Feb 16 00:47:37 2018
New Revision: 325321

URL: http://llvm.org/viewvc/llvm-project?rev=325321&view=rev
Log:
[Sema] Take into account the current context when checking the
accessibility of a class member.

This fixes PR32898.

rdar://problem/33737747

Differential revision: https://reviews.llvm.org/D36918

Modified:
cfe/trunk/lib/Sema/SemaAccess.cpp
cfe/trunk/test/SemaCXX/access.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=325321&r1=325320&r2=325321&view=diff
==
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Fri Feb 16 00:47:37 2018
@@ -1793,6 +1793,11 @@ Sema::AccessResult Sema::CheckAddressOfM
 
   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
   /*no instance context*/ QualType());
+
+  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) ==
+  ::AR_accessible)
+return AR_accessible;
+
   Entity.setDiag(diag::err_access)
 << Ovl->getSourceRange();
 

Modified: cfe/trunk/test/SemaCXX/access.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access.cpp?rev=325321&r1=325320&r2=325321&view=diff
==
--- cfe/trunk/test/SemaCXX/access.cpp (original)
+++ cfe/trunk/test/SemaCXX/access.cpp Fri Feb 16 00:47:37 2018
@@ -169,3 +169,38 @@ namespace ThisLambdaIsNotMyFriend {
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2(&func0);
+  func2(&func1);
+}
+  };
+
+  void friendFunc() {
+func2(&func0);
+func2(&func1);
+  }
+
+  void nonFriendFunc() {
+func2(&func0); // expected-error {{no 
matching function for call to 'func2'}}
+func2(&func1); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+}


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


Re: r325321 - [Sema] Take into account the current context when checking the

2018-02-16 Thread Akira Hatanaka via cfe-commits
Thanks for taking care of it.

It looks like I had to traverse the chain of Scopes upwards until 
Scope::getEntity() returns something that is not null.

This is a reduced test case. clang doesn’t crash if I remove “if (true)”.

$ cat test1.cpp 

struct CmapSubtable {};

struct A {
protected:
  typedef bool (*func_t)();

  template  static bool foo1() { return true; }

public:
  void init() {
if (true)
  func = foo1;
  }

  func_t func;
};

void foo1() {
  A a;
  a.init();
}

> On Feb 16, 2018, at 4:08 AM, Hans Wennborg  wrote:
> 
> Reverted in r325335 as this broke the Chromium build.
> 
> See https://bugs.chromium.org/p/chromium/issues/detail?id=813017 for
> stack trace and reproducer.
> 
> (I think Ben said it might have also broken a Clang bootstrap build,
> but I didn't see that anywhere?)
> 
> On Fri, Feb 16, 2018 at 9:47 AM, Akira Hatanaka via cfe-commits
>  wrote:
>> Author: ahatanak
>> Date: Fri Feb 16 00:47:37 2018
>> New Revision: 325321
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=325321&view=rev
>> Log:
>> [Sema] Take into account the current context when checking the
>> accessibility of a class member.
>> 
>> This fixes PR32898.
>> 
>> rdar://problem/33737747
>> 
>> Differential revision: https://reviews.llvm.org/D36918
>> 
>> Modified:
>>cfe/trunk/lib/Sema/SemaAccess.cpp
>>cfe/trunk/test/SemaCXX/access.cpp
>> 
>> Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=325321&r1=325320&r2=325321&view=diff
>> ==
>> --- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaAccess.cpp Fri Feb 16 00:47:37 2018
>> @@ -1793,6 +1793,11 @@ Sema::AccessResult Sema::CheckAddressOfM
>> 
>>   AccessTarget Entity(Context, AccessTarget::Member, NamingClass, Found,
>>   /*no instance context*/ QualType());
>> +
>> +  if (IsAccessible(*this, EffectiveContext(CurScope->getEntity()), Entity) 
>> ==
>> +  ::AR_accessible)
>> +return AR_accessible;
>> +
>>   Entity.setDiag(diag::err_access)
>> << Ovl->getSourceRange();
>> 
>> 
>> Modified: cfe/trunk/test/SemaCXX/access.cpp
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access.cpp?rev=325321&r1=325320&r2=325321&view=diff
>> ==
>> --- cfe/trunk/test/SemaCXX/access.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/access.cpp Fri Feb 16 00:47:37 2018
>> @@ -169,3 +169,38 @@ namespace ThisLambdaIsNotMyFriend {
>>   }
>>   void bar() { foo(); }
>> }
>> +
>> +namespace OverloadedMemberFunctionPointer {
>> +  template
>> +  void func0() {}
>> +
>> +  template
>> +  void func1() {}
>> +
>> +  template
>> +  void func2(void(*fn)()) {} // expected-note 2 {{candidate function not 
>> viable: no overload of 'func}}
>> +
>> +  class C {
>> +  private:
>> +friend void friendFunc();
>> +void overloadedMethod();
>> +  protected:
>> +void overloadedMethod(int);
>> +  public:
>> +void overloadedMethod(int, int);
>> +void method() {
>> +  func2(&func0);
>> +  func2(&func1);
>> +}
>> +  };
>> +
>> +  void friendFunc() {
>> +func2(&func0);
>> +func2(&func1);
>> +  }
>> +
>> +  void nonFriendFunc() {
>> +func2(&func0); // expected-error {{no 
>> matching function for call to 'func2'}}
>> +func2(&func1); // expected-error {{no 
>> matching function for call to 'func2'}}
>> +  }
>> +}
>> 
>> 
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

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


r304449 - [CodeGen][ObjC] Fix assertion failure in EmitARCStoreStrongCall.

2017-06-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jun  1 13:41:25 2017
New Revision: 304449

URL: http://llvm.org/viewvc/llvm-project?rev=304449&view=rev
Log:
[CodeGen][ObjC] Fix assertion failure in EmitARCStoreStrongCall.

The assertion fails because EmitValueForIvarAtOffset doesn't get the
correct type of the ivar when the class the ivar belongs to is
parameterized. This commit fixes the function to compute the ivar's type
based on the type argument provided to the parameterized class.

rdar://problem/32461723

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
cfe/trunk/test/CodeGenObjC/parameterized_classes.m

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp?rev=304449&r1=304448&r2=304449&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp Thu Jun  1 13:41:25 2017
@@ -90,7 +90,11 @@ LValue CGObjCRuntime::EmitValueForIvarAt
unsigned CVRQualifiers,
llvm::Value *Offset) {
   // Compute (type*) ( (char *) BaseValue + Offset)
-  QualType IvarTy = Ivar->getType().withCVRQualifiers(CVRQualifiers);
+  QualType InterfaceTy{OID->getTypeForDecl(), 0};
+  QualType ObjectPtrTy =
+  CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
+  QualType IvarTy =
+  Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
   llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
   llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
   V = CGF.Builder.CreateInBoundsGEP(V, Offset, "add.ptr");

Modified: cfe/trunk/test/CodeGenObjC/parameterized_classes.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/parameterized_classes.m?rev=304449&r1=304448&r2=304449&view=diff
==
--- cfe/trunk/test/CodeGenObjC/parameterized_classes.m (original)
+++ cfe/trunk/test/CodeGenObjC/parameterized_classes.m Thu Jun  1 13:41:25 2017
@@ -68,3 +68,31 @@ void blockTest(NSMutableArray : NSObject {
+  DestType _destination;
+}
+@end
+
+@interface Derived : Base
+- (void)setDest:(NSObject *)a;
+@end
+
+@implementation Derived
+- (void)setDest:(NSObject *)a {
+  _destination = a;
+}
+@end


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


Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-01 Thread Akira Hatanaka via cfe-commits
It crashes when there is an anonymous ivar of a bitfield type.

@interface FormatScanner {
  int : 1;
}
@end

@implementation FormatScanner
@end

I'm not sure if the code above is valid or not, but out of curiosity, why would 
you want an anonymous bitfield variable?

> On Jun 1, 2017, at 11:33 AM, Joerg Sonnenberger  wrote:
> 
> On Tue, Mar 14, 2017 at 04:00:53AM -, Akira Hatanaka via cfe-commits 
> wrote:
>> Author: ahatanak
>> Date: Mon Mar 13 23:00:52 2017
>> New Revision: 297702
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=297702&view=rev
>> Log:
>> [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded
>> correctly.
> 
> This results in asserts on the attached test case. Can you have a look,
> please?
> 
> Joerg
> 

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


r304507 - [Sema] Improve -Wstrict-prototypes diagnostic message for blocks.

2017-06-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jun  1 20:07:08 2017
New Revision: 304507

URL: http://llvm.org/viewvc/llvm-project?rev=304507&view=rev
Log:
[Sema] Improve -Wstrict-prototypes diagnostic message for blocks.

Print "this block declaration is not a prototype" for non-prototype
declarations of blocks instead of "this function declaration ...".

rdar://problem/32461723

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/Sema/warn-strict-prototypes.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=304507&r1=304506&r2=304507&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jun  1 20:07:08 
2017
@@ -4584,7 +4584,7 @@ def warn_missing_prototype : Warning<
 def note_declaration_not_a_prototype : Note<
   "this declaration is not a prototype; add 'void' to make it a prototype for 
a zero-parameter function">; 
 def warn_strict_prototypes : Warning<
-  "this %select{function declaration is not|"
+  "this %select{function declaration is not|block declaration is not|"
   "old-style function definition is not preceded by}0 a prototype">,
   InGroup>, DefaultIgnore;
 def warn_missing_variable_declarations : Warning<

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=304507&r1=304506&r2=304507&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jun  1 20:07:08 2017
@@ -12309,7 +12309,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 TypeSourceInfo *TI = FD->getTypeSourceInfo();
 TypeLoc TL = TI->getTypeLoc();
 FunctionTypeLoc FTL = TL.getAsAdjusted();
-Diag(FTL.getLParenLoc(), diag::warn_strict_prototypes) << 1;
+Diag(FTL.getLParenLoc(), diag::warn_strict_prototypes) << 2;
   }
 }
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=304507&r1=304506&r2=304507&view=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jun  1 20:07:08 2017
@@ -4347,19 +4347,6 @@ static TypeSourceInfo *GetFullTypeForDec
   if (FTI.isAmbiguous)
 warnAboutAmbiguousFunction(S, D, DeclType, T);
 
-  // GNU warning -Wstrict-prototypes
-  //   Warn if a function declaration is without a prototype.
-  //   This warning is issued for all kinds of unprototyped function
-  //   declarations (i.e. function type typedef, function pointer etc.)
-  //   C99 6.7.5.3p14:
-  //   The empty list in a function declarator that is not part of a
-  //   definition of that function specifies that no information
-  //   about the number or types of the parameters is supplied.
-  if (D.getFunctionDefinitionKind() == FDK_Declaration &&
-  FTI.NumParams == 0 && !LangOpts.CPlusPlus)
-S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
-<< 0 << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");
-
   FunctionType::ExtInfo EI(getCCForDeclaratorChunk(S, D, FTI, chunkIndex));
 
   if (!FTI.NumParams && !FTI.isVariadic && !LangOpts.CPlusPlus) {
@@ -4602,6 +4589,36 @@ static TypeSourceInfo *GetFullTypeForDec
  const_cast(DeclType.getAttrs()));
   }
 
+  // GNU warning -Wstrict-prototypes
+  //   Warn if a function declaration is without a prototype.
+  //   This warning is issued for all kinds of unprototyped function
+  //   declarations (i.e. function type typedef, function pointer etc.)
+  //   C99 6.7.5.3p14:
+  //   The empty list in a function declarator that is not part of a definition
+  //   of that function specifies that no information about the number or types
+  //   of the parameters is supplied.
+  if (!LangOpts.CPlusPlus && D.getFunctionDefinitionKind() == FDK_Declaration) 
{
+bool IsBlock = false;
+for (const DeclaratorChunk &DeclType : D.type_objects()) {
+  switch (DeclType.Kind) {
+  case DeclaratorChunk::BlockPointer:
+IsBlock = true;
+break;
+  case DeclaratorChunk::Function: {
+const DeclaratorChunk::FunctionTypeInfo &FTI = DeclType.Fun;
+if (FTI.NumParams == 0)
+  S.Diag(DeclType.Loc, diag::warn_strict_prototypes)
+  << IsBlock
+  << FixItHint::CreateInsertion(FTI.getRParenLoc(), "void");
+IsBlock = false;
+break;
+  }
+  default:
+break;
+  }
+}
+  }
+
   assert(!T.isNull(

r305772 - Add a subgroup of c++1z-compat to enable and disable the warning about

2017-06-19 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Jun 20 01:18:46 2017
New Revision: 305772

URL: http://llvm.org/viewvc/llvm-project?rev=305772&view=rev
Log:
Add a subgroup of c++1z-compat to enable and disable the warning about
c++17's non-throwing exception specification in function signature.

rdar://problem/32628743

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=305772&r1=305771&r2=305772&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Jun 20 01:18:46 2017
@@ -149,6 +149,7 @@ def GNUFlexibleArrayUnionMember : DiagGr
 def GNUFoldingConstant : DiagGroup<"gnu-folding-constant">;
 def FormatExtraArgs : DiagGroup<"format-extra-args">;
 def FormatZeroLength : DiagGroup<"format-zero-length">;
+def CXX1zCompatMangling : DiagGroup<"c++1z-compat-mangling">;
 
 // Warnings for C++1y code which is not compatible with prior C++ standards.
 def CXXPre14Compat : DiagGroup<"c++98-c++11-compat">;
@@ -211,7 +212,8 @@ def CXX14CompatPedantic : DiagGroup<"c++
 [CXXPre1zCompatPedantic]>;
 
 def CXX1zCompat : DiagGroup<"c++1z-compat", [DeprecatedRegister,
- DeprecatedIncrementBool]>;
+ DeprecatedIncrementBool,
+ CXX1zCompatMangling]>;
 
 def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
 def FlexibleArrayExtensions : DiagGroup<"flexible-array-extensions">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=305772&r1=305771&r2=305772&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 20 01:18:46 
2017
@@ -507,7 +507,7 @@ def warn_deprecated_copy_operation : War
   InGroup, DefaultIgnore;
 def warn_cxx1z_compat_exception_spec_in_signature : Warning<
   "mangled name of %0 will change in C++17 due to non-throwing exception "
-  "specification in function signature">, InGroup;
+  "specification in function signature">, InGroup;
 
 def warn_global_constructor : Warning<
   "declaration requires a global constructor">,

Modified: cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp?rev=305772&r1=305771&r2=305772&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-noexcept-function-type.cpp Tue Jun 20 01:18:46 
2017
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -std=c++14 -verify -fexceptions -fcxx-exceptions %s
 // RUN: %clang_cc1 -std=c++1z -verify -fexceptions -fcxx-exceptions %s 
-Wno-dynamic-exception-spec
+// RUN: %clang_cc1 -std=c++14 -verify -fexceptions -fcxx-exceptions 
-Wno-c++1z-compat-mangling -DNO_COMPAT_MANGLING %s
 
 #if __cplusplus > 201402L
 
@@ -81,7 +82,7 @@ namespace CompatWarning {
   auto f5() -> void (*)() throw();
   auto f6() -> void (&)() throw();
   auto f7() -> void (X::*)() throw();
-#if __cplusplus <= 201402L
+#if __cplusplus <= 201402L && !defined(NO_COMPAT_MANGLING)
   // expected-warning@-8 {{mangled name of 'f1' will change in C++17 due to 
non-throwing exception specification in function signature}}
   // expected-warning@-8 {{mangled name of 'f2' will change in C++17 due to 
non-throwing exception specification in function signature}}
   // expected-warning@-8 {{mangled name of 'f3' will change in C++17 due to 
non-throwing exception specification in function signature}}


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


Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Akira Hatanaka via cfe-commits
Do you want the same encoding for the bitfield “int : 1” you saw before 
r297792, which is just “i"?

The encoding for bitfield is normally bN where N is the number of bits, but the 
comment in function EncodeBitField says GNU runtime encodes it differently.

> On Jun 22, 2017, at 8:30 AM, Joerg Sonnenberger  wrote:
> 
> On Mon, Jun 12, 2017 at 09:03:10PM +0200, Joerg Sonnenberger wrote:
>> On Thu, Jun 01, 2017 at 05:58:41PM -0700, Akira Hatanaka wrote:
>>> It crashes when there is an anonymous ivar of a bitfield type.
>>> 
>>> @interface FormatScanner {
>>>  int : 1;
>>> }
>>> @end
>>> 
>>> @implementation FormatScanner
>>> @end
>>> 
>>> I'm not sure if the code above is valid or not, but out of curiosity,
>>> why would you want an anonymous bitfield variable?
>> 
>> It's a reduced test case. The original test case has a variable name in
>> it.
> 
> Ping?
> 
> Joerg

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


Re: r297702 - [CodeGen][ObjC] Fix a bug where the type of an ivar wasn't encoded

2017-06-22 Thread Akira Hatanaka via cfe-commits
According to the documentation, the starting position of the field has to be 
encoded too:

https://gcc.gnu.org/onlinedocs/gcc/Type-encoding.html 


I’m not sure whether we need the same information for bitfield ivars though.

> On Jun 22, 2017, at 12:03 PM, Joerg Sonnenberger  wrote:
> 
> On Thu, Jun 22, 2017 at 11:09:48AM -0700, Akira Hatanaka wrote:
>> Do you want the same encoding for the bitfield “int : 1” you saw before 
>> r297792, which is just “i"?
>> 
>> The encoding for bitfield is normally bN where N is the number of bits,
>> but the comment in function EncodeBitField says GNU runtime encodes it 
>> differently.
> 
> Sorry, can't answer that. I primarily care about a new clang crash that
> didn't exist before, cut I can't answer what the correct behavior should
> be.
> 
> Joerg

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


[libcxx] r306310 - [libcxx] Annotate c++17 aligned new/delete operators with availability

2017-06-26 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Jun 26 10:39:48 2017
New Revision: 306310

URL: http://llvm.org/viewvc/llvm-project?rev=306310&view=rev
Log:
[libcxx] Annotate c++17 aligned new/delete operators with availability
attribute.

This is needed because older versions of libc++ do not have these
operators. If users target an older deployment target and try to compile
programs in which these operators are explicitly called, the compiler
will complain.

The following is the list of minimum deployment targets for the four
OSes:

macosx: 10.13
ios: 11.0
tvos: 11.0
watchos: 4.0

rdar://problem/32664169

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

Added:

libcxx/trunk/test/std/language.support/support.dynamic/new.delete/new.delete.placement/new_deployment.fail.cpp
Modified:
libcxx/trunk/include/__config
libcxx/trunk/include/new

Modified: libcxx/trunk/include/__config
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=306310&r1=306309&r2=306310&view=diff
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Mon Jun 26 10:39:48 2017
@@ -1176,6 +1176,11 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR 
\
   __attribute__((availability(macosx,strict,introduced=10.9))) 
\
   __attribute__((availability(ios,strict,introduced=7.0)))
+#define _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION
\
+  __attribute__((availability(macosx,strict,introduced=10.13)))
\
+  __attribute__((availability(ios,strict,introduced=11.0)))
\
+  __attribute__((availability(tvos,strict,introduced=11.0)))   
\
+  __attribute__((availability(watchos,strict,introduced=4.0)))
 #else
 #define _LIBCPP_AVAILABILITY_SHARED_MUTEX
 #define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
@@ -1187,6 +1192,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
 #define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
 #define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
+#define _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION
 #endif
 
 // Define availability that depends on _LIBCPP_NO_EXCEPTIONS.

Modified: libcxx/trunk/include/new
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/new?rev=306310&r1=306309&r2=306310&view=diff
==
--- libcxx/trunk/include/new (original)
+++ libcxx/trunk/include/new Mon Jun 26 10:39:48 2017
@@ -193,20 +193,20 @@ _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVA
 #endif
 
 #ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, 
std::align_val_t) _THROW_BAD_ALLOC;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, 
std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete(void* __p, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) 
_NOEXCEPT _NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
 #ifndef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
-_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void  
operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
 #endif
 
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, 
std::align_val_t) _THROW_BAD_ALLOC;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT _NOALIAS;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, 
std::align_val_t) _NOEXCEPT;
-_LIBCPP_OVERRIDABLE_FUNC_VIS void  operator delete[](void* __p, 
std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void* 
operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) 
_NOEXCEPT _NOALIAS;
+_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_ALIGNED_ALLOCATION void  
operator delete[](void* __p, 

Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2017-12-19 Thread Akira Hatanaka via cfe-commits
On Tue, Dec 12, 2017 at 12:12 PM, John McCall  wrote:

> On Tue, Dec 12, 2017 at 1:45 PM, David Blaikie  wrote:
>
>> On Mon, Dec 11, 2017 at 5:38 PM John McCall  wrote:
>>
>>> On Mon, Dec 11, 2017 at 6:19 PM, David Blaikie 
>>> wrote:
>>>
 On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator <
 revi...@reviews.llvm.org> wrote:

> rjmccall added a comment.
>
> In https://reviews.llvm.org/D41039#951648, @ahatanak wrote:
>
> > I had a discussion with Duncan today and he pointed out that perhaps
> we shouldn't allow users to annotate a struct with "trivial_abi" if one of
> its subobjects is non-trivial and is not annotated with "trivial_abi" 
> since
> that gives users too much power.
> >
> > Should we error out or drop "trivial_abi" from struct Outer when the
> following code is compiled?
> >
> >   struct Inner1 {
> > ~Inner1(); // non-trivial
> > int x;
> >   };
> >
> >   struct __attribute__((trivial_abi)) Outer {
> > ~Outer();
> > Inner1 x;
> >   };
> >
> >
> > The current patch doesn't error out or drop the attribute, but the
> patch would probably be much simpler if we didn't allow it.
>
>
> I think it makes sense to emit an error if there is provably a
> non-trivial-ABI component.  However, for class temploids I think that
> diagnostic should only fire on the definition, not on instantiations; for
> example:
>
>   template  struct __attribute__((trivial_abi)) holder {
>  T value;
>  ~holder() {}
>   };
>   holder hs; // this instantiation should be legal
> despite the fact that holder cannot be trivial-ABI.
>
> But we should still be able to emit the diagnostic in template
> definitions, e.g.:
>
>   template  struct __attribute__((trivial_abi)) named_holder {
>  std::string name; // there are no instantiations of this template
> that could ever be trivial-ABI
>  T value;
>  ~named_holder() {}
>   };
>
> The wording should be something akin to the standard template rule
> that a template is ill-formed if it has no valid instantiations, no
> diagnostic required.
>
> I would definitely like to open the conversation about the name of the
> attribute.  I don't think we've used "abi" in an existing attribute name;
> usually it's more descriptive.  And "trivial" is a weighty word in the
> standard.  I'm not sure I have a great counter-proposal off the top of my
> head, though.
>

 Agreed on both counts (would love a better name, don't have any
 stand-out candidates off the top of my head).

 I feel like a more descriptive term about the property of the object
 would make me happier - something like "address_independent_identity"
 (s/identity/value/?) though, yeah, that's not spectacular by any stretch.

>>>
>>> Incidentally, your comments are not showing up on Phabricator for some
>>> reason.
>>>
>>
>> Yeah, Phab doesn't do a great job looking on the mailing list for
>> interesting replies - I forget, maybe it only catches bottom post or top
>> post but not infix replies or something...
>>
>
> Well, fortunately the mailing list is also archived. :)
>
>
>> The term "trivially movable" suggests itself, with two caveats:
>>>   - What we're talking about is trivial *destructive* movability, i.e.
>>> that the combination of moving the value to a new object and not destroying
>>> the old object can be done trivially, which is not quite the same as
>>> trivial movability in the normal C++ sense, which I guess could be a
>>> property that someone theoretically might care about (if the type is
>>> trivially destructed, but it isn't copyable for semantic reasons?).
>>>   - Trivial destructive movability is a really common property, and it's
>>> something that a compiler would really like to optimize based on even in
>>> cases where trivial_abi can't be adopted for binary-compatibility reasons.
>>> Stealing the term for the stronger property that the type is trivially
>>> destructively movable *and its ABI should reflect that in a specific way*
>>> would be unfortunate.
>>>
>>
>> Fair point.
>>
>>
>>> "trivially_movable" is a long attribute anyway, and
>>> "trivially_destructively_movable" is even worse.
>>>
>>> Maybe that second point is telling us that this isn't purely descriptive
>>> — it's inherently talking about the ABI, not just the semantics of the
>>> type.  I might be talking myself into accepting trivial_abi if we don't end
>>> up with a better suggestion.
>>>
>>
>> *nod* I think if you want to slice this that way (ensuring there's space
>> to support describing a similar property for use only in non-ABI-breaking
>> contexts as well) it seems like ABI is the term to use somewhere in the
>> name.
>>
>
> Yeah.  We just had a little internal conversation about it, and the idea
> of "address_

Re: trivial_abi

2018-01-02 Thread Akira Hatanaka via cfe-commits


> On Jan 2, 2018, at 4:56 PM, Richard Smith via cfe-commits 
>  wrote:
> 
> On 2 January 2018 at 15:33, John McCall via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Hey, Richard et al.  Akira and I were talking about the right ABI rule for 
> deciding can-pass-in-registers-ness for structs in the presence of 
> trivial_abi, and I think I like Akira's approach but wanted to get your input.
> 
> The current definition in Itanium is:
> 
>   non-trivial for the purposes of calls <>
>  <>
> A type is considered non-trivial for the purposes of calls if:
> 
> it has a non-trivial copy constructor, move constructor, or destructor, or
>  <>
> I'm assuming we're implicitly excluding deleted functions here. (I'd prefer 
> to make that explicit; this has been the source of a number of ABI 
> mismatches.)
> all of its copy and move constructors are deleted.
>  <>
> 
> I'd suggest modifying this to:
> 
>   A type is considered non-trivial for the purposes of calls if:
>   - if has a copy constructor, move constructor, or destructor 
> which is non-trivial for the purposes of calls, or
>   - all of its copy and move constructors are deleted and it does 
> not have the trivial_abi attribute.
> 
>   A copy/move constructor is considered trivial for the purposes of calls 
> if:
>   - it is user-provided and
>   - the class has the trivial_abi attribute and
>   - a defaulted definition of the constructor would be 
> trivial for the purposes of calls; or
> 
> We'd need to say what happens if the function in question cannot validly be 
> defaulted for any of the reasons in [dcl.fct.def.default]. Do we try to infer 
> whether it's a copy or move constructor, and use the rules for a defaulted 
> copy or move constructor? Or do we just say that's never trivial for the 
> purposes of calls? Or something else? Eg:
> 
> struct [[clang::trivial_abi]] A {
>   A(A && = make());
> };
> 
> Here, A::A(A&&) cannot validly be defaulted. Is A trivial for the purpose of 
> calls? Likewise:
> 
> struct [[clang::trivial_abi]] B {
>   B(...);
> };
> struct C {
>   volatile B b;
> };
> 
> Here, C's copy constructor calls B::B(...). Is C trivial for the purpose of 
> calls? (OK, Clang crashes on that example today. But still...)
> 
> I'd be uncomfortable making the rules in [dcl.fct.def.default] part of the 
> ABI; they seem to be changing relatively frequently. Perhaps we could say "if 
> the function is a copy constructor ([class.copy.ctor]/1), then consider what 
> an implicitly-declared defaulted copy constructor would do; if it's a move 
> constructor ([class.copy.ctor]/2), then consider what an implicitly-declared 
> defaulted move constructor would do; otherwise, it's not trivial for the 
> purpose of calls". That'd mean A is trivial for the purpose of calls and C is 
> not, which I think is probably the right answer.
> 
>   - it is not user-provided and
>   - the class has no virtual functions and no virtual 
> base classes, and
>   - the constructor used to copy/move each direct base 
> class subobject is trivial for the purposes of calls, and
>   - for each non-static data member that is of class type 
> (or array thereof), the constructor selected to copy/move that member is 
> trivial for the purposes of calls.
> 
>   A destructor is considered trivial for the purposes of calls if:
>   - it is not user-provided or the class has the trivial_abi 
> attribute, and
>   - the destructor is not virtual, and
>   - all of the direct base classes of its class have destructors 
> that are trivial for the purposes of calls, and
>   - for all of the non-static data members of its class that are 
> of class type (or array thereof), each such class is trivial for the purposes 
> of calls.
> 
>   These definitions are intended to follow [class.copy.ctor]p11 and 
> [class.dtor]p6 except for the special rules applicable to trivial_abi classes.
> 
> If I could rephrase: a *tor is considered trivial for for the purposes of 
> calls if it is either defaulted or the class has the trivial_abi attribute, 
> and the defaulted definition would satisfy the language rule for being 
> trivial but with the word "trivial" replaced by "trivial for the purposes of 
> calls". So only effect of the trivial_abi attribute is to "undo" the 
> non-triviality implied by a user-provided *tor when computing triviality for 
> the purpose of calls.
> 
> I think that's a reasonable rule, if we have a satisfactory notion of 
> "defaulted definition".
> 
> I'm not sure about the "defaulted definition" rule for copy/move constructors 
> in trivial_abi classes.  The intent is to allow class temploids with 
> trivial_abi that are instantiated to contain non-trivial classes to just 
> silently become non-trivial.  I was thinking at first that it would be nice 

Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-03 Thread Akira Hatanaka via cfe-commits

> On Jan 2, 2018, at 9:42 AM, David Blaikie via cfe-commits 
>  wrote:
> 
> 
> 
> On Tue, Dec 19, 2017 at 9:43 PM Akira Hatanaka  > wrote:
> On Tue, Dec 12, 2017 at 12:12 PM, John McCall  > wrote:
> On Tue, Dec 12, 2017 at 1:45 PM, David Blaikie  > wrote:
> On Mon, Dec 11, 2017 at 5:38 PM John McCall  > wrote:
> On Mon, Dec 11, 2017 at 6:19 PM, David Blaikie  > wrote:
> On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator 
> mailto:revi...@reviews.llvm.org>> wrote:
> rjmccall added a comment.
> 
> In https://reviews.llvm.org/D41039#951648 
> , @ahatanak wrote:
> 
> > I had a discussion with Duncan today and he pointed out that perhaps we 
> > shouldn't allow users to annotate a struct with "trivial_abi" if one of its 
> > subobjects is non-trivial and is not annotated with "trivial_abi" since 
> > that gives users too much power.
> >
> > Should we error out or drop "trivial_abi" from struct Outer when the 
> > following code is compiled?
> >
> >   struct Inner1 {
> > ~Inner1(); // non-trivial
> > int x;
> >   };
> >
> >   struct __attribute__((trivial_abi)) Outer {
> > ~Outer();
> > Inner1 x;
> >   };
> >
> >
> > The current patch doesn't error out or drop the attribute, but the patch 
> > would probably be much simpler if we didn't allow it.
> 
> 
> I think it makes sense to emit an error if there is provably a 
> non-trivial-ABI component.  However, for class temploids I think that 
> diagnostic should only fire on the definition, not on instantiations; for 
> example:
> 
>   template  struct __attribute__((trivial_abi)) holder {
>  T value;
>  ~holder() {}
>   };
>   holder hs; // this instantiation should be legal despite the 
> fact that holder cannot be trivial-ABI.
> 
> But we should still be able to emit the diagnostic in template definitions, 
> e.g.:
> 
>   template  struct __attribute__((trivial_abi)) named_holder {
>  std::string name; // there are no instantiations of this template that 
> could ever be trivial-ABI
>  T value;
>  ~named_holder() {}
>   };
> 
> The wording should be something akin to the standard template rule that a 
> template is ill-formed if it has no valid instantiations, no diagnostic 
> required.
> 
> I would definitely like to open the conversation about the name of the 
> attribute.  I don't think we've used "abi" in an existing attribute name; 
> usually it's more descriptive.  And "trivial" is a weighty word in the 
> standard.  I'm not sure I have a great counter-proposal off the top of my 
> head, though.
> 
> Agreed on both counts (would love a better name, don't have any stand-out 
> candidates off the top of my head).
> 
> I feel like a more descriptive term about the property of the object would 
> make me happier - something like "address_independent_identity" 
> (s/identity/value/?) though, yeah, that's not spectacular by any stretch.
> 
> Incidentally, your comments are not showing up on Phabricator for some reason.
> 
> Yeah, Phab doesn't do a great job looking on the mailing list for interesting 
> replies - I forget, maybe it only catches bottom post or top post but not 
> infix replies or something... 
> 
> Well, fortunately the mailing list is also archived. :)
> 
> 
> The term "trivially movable" suggests itself, with two caveats:
>   - What we're talking about is trivial *destructive* movability, i.e. that 
> the combination of moving the value to a new object and not destroying the 
> old object can be done trivially, which is not quite the same as trivial 
> movability in the normal C++ sense, which I guess could be a property that 
> someone theoretically might care about (if the type is trivially destructed, 
> but it isn't copyable for semantic reasons?).
>   - Trivial destructive movability is a really common property, and it's 
> something that a compiler would really like to optimize based on even in 
> cases where trivial_abi can't be adopted for binary-compatibility reasons.  
> Stealing the term for the stronger property that the type is trivially 
> destructively movable *and its ABI should reflect that in a specific way* 
> would be unfortunate.
> 
> Fair point.
>  
> "trivially_movable" is a long attribute anyway, and 
> "trivially_destructively_movable" is even worse.
> 
> Maybe that second point is telling us that this isn't purely descriptive — 
> it's inherently talking about the ABI, not just the semantics of the type.  I 
> might be talking myself into accepting trivial_abi if we don't end up with a 
> better suggestion.
> 
> *nod* I think if you want to slice this that way (ensuring there's space to 
> support describing a similar property for use only in non-ABI-breaking 
> contexts as well) it seems like ABI is the term to use somewhere in the name.
> 
> Yeah.  We just had a little internal conversation about it, 

Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-03 Thread Akira Hatanaka via cfe-commits


> On Jan 3, 2018, at 10:25 AM, John McCall  wrote:
> 
> On Wed, Jan 3, 2018 at 12:24 PM, Akira Hatanaka  > wrote:
>> On Jan 2, 2018, at 9:42 AM, David Blaikie via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> 
>> 
>> 
>> On Tue, Dec 19, 2017 at 9:43 PM Akira Hatanaka > > wrote:
>> On Tue, Dec 12, 2017 at 12:12 PM, John McCall > > wrote:
>> On Tue, Dec 12, 2017 at 1:45 PM, David Blaikie > > wrote:
>> On Mon, Dec 11, 2017 at 5:38 PM John McCall > > wrote:
>> On Mon, Dec 11, 2017 at 6:19 PM, David Blaikie > > wrote:
>> On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator 
>> mailto:revi...@reviews.llvm.org>> wrote:
>> rjmccall added a comment.
>> 
>> In https://reviews.llvm.org/D41039#951648 
>> , @ahatanak wrote:
>> 
>> > I had a discussion with Duncan today and he pointed out that perhaps we 
>> > shouldn't allow users to annotate a struct with "trivial_abi" if one of 
>> > its subobjects is non-trivial and is not annotated with "trivial_abi" 
>> > since that gives users too much power.
>> >
>> > Should we error out or drop "trivial_abi" from struct Outer when the 
>> > following code is compiled?
>> >
>> >   struct Inner1 {
>> > ~Inner1(); // non-trivial
>> > int x;
>> >   };
>> >
>> >   struct __attribute__((trivial_abi)) Outer {
>> > ~Outer();
>> > Inner1 x;
>> >   };
>> >
>> >
>> > The current patch doesn't error out or drop the attribute, but the patch 
>> > would probably be much simpler if we didn't allow it.
>> 
>> 
>> I think it makes sense to emit an error if there is provably a 
>> non-trivial-ABI component.  However, for class temploids I think that 
>> diagnostic should only fire on the definition, not on instantiations; for 
>> example:
>> 
>>   template  struct __attribute__((trivial_abi)) holder {
>>  T value;
>>  ~holder() {}
>>   };
>>   holder hs; // this instantiation should be legal despite the 
>> fact that holder cannot be trivial-ABI.
>> 
>> But we should still be able to emit the diagnostic in template definitions, 
>> e.g.:
>> 
>>   template  struct __attribute__((trivial_abi)) named_holder {
>>  std::string name; // there are no instantiations of this template that 
>> could ever be trivial-ABI
>>  T value;
>>  ~named_holder() {}
>>   };
>> 
>> The wording should be something akin to the standard template rule that a 
>> template is ill-formed if it has no valid instantiations, no diagnostic 
>> required.
>> 
>> I would definitely like to open the conversation about the name of the 
>> attribute.  I don't think we've used "abi" in an existing attribute name; 
>> usually it's more descriptive.  And "trivial" is a weighty word in the 
>> standard.  I'm not sure I have a great counter-proposal off the top of my 
>> head, though.
>> 
>> Agreed on both counts (would love a better name, don't have any stand-out 
>> candidates off the top of my head).
>> 
>> I feel like a more descriptive term about the property of the object would 
>> make me happier - something like "address_independent_identity" 
>> (s/identity/value/?) though, yeah, that's not spectacular by any stretch.
>> 
>> Incidentally, your comments are not showing up on Phabricator for some 
>> reason.
>> 
>> Yeah, Phab doesn't do a great job looking on the mailing list for 
>> interesting replies - I forget, maybe it only catches bottom post or top 
>> post but not infix replies or something... 
>> 
>> Well, fortunately the mailing list is also archived. :)
>> 
>> 
>> The term "trivially movable" suggests itself, with two caveats:
>>   - What we're talking about is trivial *destructive* movability, i.e. that 
>> the combination of moving the value to a new object and not destroying the 
>> old object can be done trivially, which is not quite the same as trivial 
>> movability in the normal C++ sense, which I guess could be a property that 
>> someone theoretically might care about (if the type is trivially destructed, 
>> but it isn't copyable for semantic reasons?).
>>   - Trivial destructive movability is a really common property, and it's 
>> something that a compiler would really like to optimize based on even in 
>> cases where trivial_abi can't be adopted for binary-compatibility reasons.  
>> Stealing the term for the stronger property that the type is trivially 
>> destructively movable *and its ABI should reflect that in a specific way* 
>> would be unfortunate.
>> 
>> Fair point.
>>  
>> "trivially_movable" is a long attribute anyway, and 
>> "trivially_destructively_movable" is even worse.
>> 
>> Maybe that second point is telling us that this isn't purely descriptive — 
>> it's inherently talking about the ABI, not just the semantics of the type.  
>> I might be talking myself into accepting trivial_abi if we don't end up with 
>> a better suggestion.
>> 

Re: [PATCH] D41039: Add support for attribute "trivial_abi"

2018-01-03 Thread Akira Hatanaka via cfe-commits

> On Jan 3, 2018, at 6:39 PM, John McCall  wrote:
> 
> On Wed, Jan 3, 2018 at 2:07 PM, Akira Hatanaka  > wrote:
>> On Jan 3, 2018, at 10:25 AM, John McCall > > wrote:
>> 
>> On Wed, Jan 3, 2018 at 12:24 PM, Akira Hatanaka > > wrote:
>>> On Jan 2, 2018, at 9:42 AM, David Blaikie via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> 
>>> 
>>> 
>>> On Tue, Dec 19, 2017 at 9:43 PM Akira Hatanaka >> > wrote:
>>> On Tue, Dec 12, 2017 at 12:12 PM, John McCall >> > wrote:
>>> On Tue, Dec 12, 2017 at 1:45 PM, David Blaikie >> > wrote:
>>> On Mon, Dec 11, 2017 at 5:38 PM John McCall >> > wrote:
>>> On Mon, Dec 11, 2017 at 6:19 PM, David Blaikie >> > wrote:
>>> On Mon, Dec 11, 2017 at 3:16 PM John McCall via Phabricator 
>>> mailto:revi...@reviews.llvm.org>> wrote:
>>> rjmccall added a comment.
>>> 
>>> In https://reviews.llvm.org/D41039#951648 
>>> , @ahatanak wrote:
>>> 
>>> > I had a discussion with Duncan today and he pointed out that perhaps we 
>>> > shouldn't allow users to annotate a struct with "trivial_abi" if one of 
>>> > its subobjects is non-trivial and is not annotated with "trivial_abi" 
>>> > since that gives users too much power.
>>> >
>>> > Should we error out or drop "trivial_abi" from struct Outer when the 
>>> > following code is compiled?
>>> >
>>> >   struct Inner1 {
>>> > ~Inner1(); // non-trivial
>>> > int x;
>>> >   };
>>> >
>>> >   struct __attribute__((trivial_abi)) Outer {
>>> > ~Outer();
>>> > Inner1 x;
>>> >   };
>>> >
>>> >
>>> > The current patch doesn't error out or drop the attribute, but the patch 
>>> > would probably be much simpler if we didn't allow it.
>>> 
>>> 
>>> I think it makes sense to emit an error if there is provably a 
>>> non-trivial-ABI component.  However, for class temploids I think that 
>>> diagnostic should only fire on the definition, not on instantiations; for 
>>> example:
>>> 
>>>   template  struct __attribute__((trivial_abi)) holder {
>>>  T value;
>>>  ~holder() {}
>>>   };
>>>   holder hs; // this instantiation should be legal despite the 
>>> fact that holder cannot be trivial-ABI.
>>> 
>>> But we should still be able to emit the diagnostic in template definitions, 
>>> e.g.:
>>> 
>>>   template  struct __attribute__((trivial_abi)) named_holder {
>>>  std::string name; // there are no instantiations of this template that 
>>> could ever be trivial-ABI
>>>  T value;
>>>  ~named_holder() {}
>>>   };
>>> 
>>> The wording should be something akin to the standard template rule that a 
>>> template is ill-formed if it has no valid instantiations, no diagnostic 
>>> required.
>>> 
>>> I would definitely like to open the conversation about the name of the 
>>> attribute.  I don't think we've used "abi" in an existing attribute name; 
>>> usually it's more descriptive.  And "trivial" is a weighty word in the 
>>> standard.  I'm not sure I have a great counter-proposal off the top of my 
>>> head, though.
>>> 
>>> Agreed on both counts (would love a better name, don't have any stand-out 
>>> candidates off the top of my head).
>>> 
>>> I feel like a more descriptive term about the property of the object would 
>>> make me happier - something like "address_independent_identity" 
>>> (s/identity/value/?) though, yeah, that's not spectacular by any stretch.
>>> 
>>> Incidentally, your comments are not showing up on Phabricator for some 
>>> reason.
>>> 
>>> Yeah, Phab doesn't do a great job looking on the mailing list for 
>>> interesting replies - I forget, maybe it only catches bottom post or top 
>>> post but not infix replies or something... 
>>> 
>>> Well, fortunately the mailing list is also archived. :)
>>> 
>>> 
>>> The term "trivially movable" suggests itself, with two caveats:
>>>   - What we're talking about is trivial *destructive* movability, i.e. that 
>>> the combination of moving the value to a new object and not destroying the 
>>> old object can be done trivially, which is not quite the same as trivial 
>>> movability in the normal C++ sense, which I guess could be a property that 
>>> someone theoretically might care about (if the type is trivially 
>>> destructed, but it isn't copyable for semantic reasons?).
>>>   - Trivial destructive movability is a really common property, and it's 
>>> something that a compiler would really like to optimize based on even in 
>>> cases where trivial_abi can't be adopted for binary-compatibility reasons.  
>>> Stealing the term for the stronger property that the type is trivially 
>>> destructively movable *and its ABI should reflect that in a specific way* 
>>> would be unfortunate.
>>> 
>>> Fair point.
>>>  
>>> "trivially_movable" is a long attribute anyway, and 
>>> "trivially_destructively_movable" i

r326530 - Add an option to disable tail-call optimization for escaping blocks.

2018-03-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar  1 17:53:15 2018
New Revision: 326530

URL: http://llvm.org/viewvc/llvm-project?rev=326530&view=rev
Log:
Add an option to disable tail-call optimization for escaping blocks.

This makes it easier to debug crashes and hangs in block functions since
users can easily find out where the block is called from. The option
doesn't disable tail-calls from non-escaping blocks since non-escaping
blocks are not as hard to debug as escaping blocks.

rdar://problem/35758207

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

Added:
cfe/trunk/test/CodeGenObjC/disable-tail-call-escaping-block.m
cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=326530&r1=326529&r2=326530&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Mar  1 17:53:15 2018
@@ -3802,6 +3802,10 @@ private:
   bool BlockMissingReturnType : 1;
   bool IsConversionFromLambda : 1;
 
+  /// A bit that indicates this block is passed directly to a function as a
+  /// non-escaping parameter.
+  bool DoesNotEscape : 1;
+
   /// A new[]'d array of pointers to ParmVarDecls for the formal
   /// parameters of this function.  This is null if a prototype or if there are
   /// no formals.
@@ -3821,7 +3825,7 @@ protected:
   BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
   : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false),
 CapturesCXXThis(false), BlockMissingReturnType(true),
-IsConversionFromLambda(false) {}
+IsConversionFromLambda(false), DoesNotEscape(false) {}
 
 public:
   static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L); 
@@ -3893,6 +3897,9 @@ public:
   bool isConversionFromLambda() const { return IsConversionFromLambda; }
   void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
 
+  bool doesNotEscape() const { return DoesNotEscape; }
+  void setDoesNotEscape() { DoesNotEscape = true; }
+
   bool capturesVariable(const VarDecl *var) const;
 
   void setCaptures(ASTContext &Context, ArrayRef Captures,

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=326530&r1=326529&r2=326530&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Mar  1 17:53:15 2018
@@ -1430,6 +1430,8 @@ def fopenmp_cuda_mode : Flag<["-"], "fop
 def fno_openmp_cuda_mode : Flag<["-"], "fno-openmp-cuda-mode">, 
Group, Flags<[CC1Option, NoArgumentUnused]>;
 def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, 
Group;
 def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, 
Group;
+def fno_escaping_block_tail_calls : Flag<["-"], 
"fno-escaping-block-tail-calls">, Group, Flags<[CC1Option]>;
+def fescaping_block_tail_calls : Flag<["-"], "fescaping-block-tail-calls">, 
Group;
 def force__cpusubtype__ALL : Flag<["-"], "force_cpusubtype_ALL">;
 def force__flat__namespace : Flag<["-"], "force_flat_namespace">;
 def force__load : Separate<["-"], "force_load">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=326530&r1=326529&r2=326530&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu Mar  1 17:53:15 2018
@@ -62,6 +62,8 @@ CODEGENOPT(DebugPassManager, 1, 0) ///<
///< pass manager.
 CODEGENOPT(DisableRedZone, 1, 0) ///< Set when -mno-red-zone is enabled.
 CODEGENOPT(DisableTailCalls  , 1, 0) ///< Do not emit tail calls.
+CODEGENOPT(NoEscapingBlockTailCalls, 1, 0) ///< Do not emit tail calls from
+   ///< escaping blocks.
 CODEGENOPT(EmitDeclMetadata  , 1, 0) ///< Emit special metadata indicating what
  ///< Decl* various IR entities came from.
  ///< Only useful when running CodeGen as a

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=326530&r1=326529&r2

r326531 - Remove debugging code I accidentally committed in r326530.

2018-03-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar  1 18:03:21 2018
New Revision: 326531

URL: http://llvm.org/viewvc/llvm-project?rev=326531&view=rev
Log:
Remove debugging code I accidentally committed in r326530.

Modified:
cfe/trunk/lib/Sema/SemaPseudoObject.cpp

Modified: cfe/trunk/lib/Sema/SemaPseudoObject.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaPseudoObject.cpp?rev=326531&r1=326530&r2=326531&view=diff
==
--- cfe/trunk/lib/Sema/SemaPseudoObject.cpp (original)
+++ cfe/trunk/lib/Sema/SemaPseudoObject.cpp Thu Mar  1 18:03:21 2018
@@ -993,7 +993,6 @@ ObjCSubscriptOpBuilder::buildAssignmentO
 SourceLocation opcLoc,
 BinaryOperatorKind opcode,
 Expr *LHS, Expr *RHS) {
-  assert(false);
   assert(BinaryOperator::isAssignmentOp(opcode));
   // There must be a method to do the Index'ed assignment.
   if (!findAtIndexSetter())


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


r327204 - [Driver] Pass Default=false to hasFlag.

2018-03-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Mar  9 21:55:21 2018
New Revision: 327204

URL: http://llvm.org/viewvc/llvm-project?rev=327204&view=rev
Log:
[Driver] Pass Default=false to hasFlag.

I forgot to do this in r326530.

Modified:
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=327204&r1=327203&r2=327204&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Mar  9 21:55:21 2018
@@ -3455,7 +3455,7 @@ void Clang::ConstructJob(Compilation &C,
 options::OPT_fno_optimize_sibling_calls))
 CmdArgs.push_back("-mdisable-tail-calls");
   if (Args.hasFlag(options::OPT_fno_escaping_block_tail_calls,
-   options::OPT_fescaping_block_tail_calls))
+   options::OPT_fescaping_block_tail_calls, false))
 CmdArgs.push_back("-fno-escaping-block-tail-calls");
 
   Args.AddLastArg(CmdArgs, options::OPT_ffine_grained_bitfield_accesses,

Modified: cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c?rev=327204&r1=327203&r2=327204&view=diff
==
--- cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c (original)
+++ cfe/trunk/test/Driver/fno-escaping-block-tail-calls.c Fri Mar  9 21:55:21 
2018
@@ -4,4 +4,6 @@
 
 // RUN: %clang -### %s -fno-escaping-block-tail-calls 
-fescaping-block-tail-calls 2> %t
 // RUN: FileCheck --check-prefix=CHECK-NO-DISABLE < %t %s
+// RUN: %clang -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-NO-DISABLE < %t %s
 // CHECK-NO-DISABLE-NOT: "-fno-escaping-block-tail-calls"


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


r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Mar  9 22:36:08 2018
New Revision: 327206

URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev
Log:
[ObjC] Allow declaring __weak pointer fields in C structs in ARC.

This patch uses the infrastructure added in r326307 for enabling
non-trivial fields to be declared in C structs to allow __weak fields in
C structs in ARC.

rdar://problem/33599681

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

Added:
cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
@@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
   bool NonTrivialToPrimitiveCopy : 1;
   bool NonTrivialToPrimitiveDestroy : 1;
 
+  /// True if this class can be passed in a non-address-preserving fashion
+  /// (such as in registers).
+  /// This does not imply anything about how the ABI in use will actually
+  /// pass an object of this class.
+  bool CanPassInRegisters : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3636,6 +3642,18 @@ public:
 NonTrivialToPrimitiveDestroy = true;
   }
 
+  /// Determine whether this class can be passed in registers. In C++ mode,
+  /// it must have at least one trivial, non-deleted copy or move constructor.
+  /// FIXME: This should be set as part of completeDefinition.
+  bool canPassInRegisters() const {
+return CanPassInRegisters;
+  }
+
+  /// Set that we can pass this RecordDecl in registers.
+  void setCanPassInRegisters(bool CanPass) {
+CanPassInRegisters = CanPass;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Fri Mar  9 22:36:08 2018
@@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
 /// constructor.
 unsigned HasDefaultedDefaultConstructor : 1;
 
-/// \brief True if this class can be passed in a non-address-preserving
-/// fashion (such as in registers) according to the C++ language rules.
-/// This does not imply anything about how the ABI in use will actually
-/// pass an object of this class.
-unsigned CanPassInRegisters : 1;
-
 /// \brief True if a defaulted default constructor for this class would
 /// be constexpr.
 unsigned DefaultedDefaultConstructorIsConstexpr : 1;
@@ -1474,18 +1468,6 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
-  /// \brief Determine whether this class has at least one trivial, non-deleted
-  /// copy or move constructor.
-  bool canPassInRegisters() const {
-return data().CanPassInRegisters;
-  }
-
-  /// \brief Set that we can pass this RecordDecl in registers.
-  // FIXME: This should be set as part of completeDefinition.
-  void setCanPassInRegisters(bool CanPass) {
-data().CanPassInRegisters = CanPass;
-  }
-
   /// Determine whether the triviality for the purpose of calls for this class
   /// is overridden to be trivial because this class or the type of one of its
   /// subobjects has attribute "trivial_abi".

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=327206&r1=327205&r2=327206&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Mar  9 22:36:08 2018
@@ -1097,6 +1097,10 @@ public:
 /// with the ARC __strong qualifier.
 PDIK_ARCStrong,
 
+/// The type is an Objective-C retainable pointer type that is qualified
+/// with the ARC __weak qualifier.
+PDIK

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
Do you have a reproducer?

> On Mar 12, 2018, at 9:07 AM, Eric Liu  wrote:
> 
> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
> what's the right way to fix it. I'll revert this commit for now to unblock 
> integration. Let me know if you need more information from us.
> 
> Regards,
> Eric
> 
> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu  <mailto:ioe...@google.com>> wrote:
> The tests only failed with module enabled. FWIW, I think the change in 
> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
> <https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk>) needs additional 
> changes to make imports work for RecordDecl. 
> 
> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu  <mailto:ioe...@google.com>> wrote:
> Hi Akira,
> 
> It seems that this commit also changes behavior for compiling C++ code as we 
> are seeing test failures caused by this change in our internal tests.
> 
> I'm still trying to reduce a reproducer for the failure. In the meantime, 
> could you please double check if this affects C++?
> 
> Thanks,
> Eric
> 
> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
> mailto:cfe-commits@lists.llvm.org>> wrote:
> Author: ahatanak
> Date: Fri Mar  9 22:36:08 2018
> New Revision: 327206
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
> <http://llvm.org/viewvc/llvm-project?rev=327206&view=rev>
> Log:
> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
> 
> This patch uses the infrastructure added in r326307 for enabling
> non-trivial fields to be declared in C structs to allow __weak fields in
> C structs in ARC.
> 
> rdar://problem/33599681
> 
> Differential Revision: https://reviews.llvm.org/D44095 
> <https://reviews.llvm.org/D44095>
> 
> Added:
> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/DeclCXX.h
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/Decl.cpp
> cfe/trunk/lib/AST/DeclCXX.cpp
> cfe/trunk/lib/AST/Type.cpp
> cfe/trunk/lib/CodeGen/CGBlocks.cpp
> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
> cfe/trunk/lib/CodeGen/CGObjC.cpp
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/CodeGen/TargetInfo.cpp
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
> cfe/trunk/lib/Serialization/ASTWriter.cpp
> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
> 
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>  
> <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff>
> ==
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>bool NonTrivialToPrimitiveCopy : 1;
>bool NonTrivialToPrimitiveDestroy : 1;
> 
> +  /// True if this class can be passed in a non-address-preserving fashion
> +  /// (such as in registers).
> +  /// This does not imply anything about how the ABI in use will actually
> +  /// pass an object of this class.
> +  bool CanPassInRegisters : 1;
> +
>  protected:
>RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
>   SourceLocation StartLoc, SourceLocation IdLoc,
> @@ -3636,6 +3642,18 @@ public:
>  NonTrivialToPrimitiveDestroy = true;
>}
> 
> +  /// Determine whether this class can be passed in registers. In C++ mode,
> +  /// it must have at least one trivial, non-deleted copy or move 
> constructor.
> +  /// FIXME: This should be set as part of completeDefinition.
> +  bool canPassInRegisters() const {
> +return CanPassInRegisters;
> +  }
> +
> +  /// Set that we can pass this RecordDecl in registers.
> +  void setCanPassInRegisters(bool CanPass) {
> +CanPassInRegisters = CanPass;
> +  }
> +
>/// \brief Determines whether this declaration represents the
>/// injected class name.
>///
> 
> Modified: cfe/trunk/include/clang/AST/DeclCXX.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327206&r1=327205&r2=327206&view=diff
>  
> <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
The patch I committed moved CXXRecordDecl::CanPassInRegisters to RecordDecl. It 
looks like ASTImporter::ImportDefinition no longer copies the bit for 
CanPassInRegisters after that change. I’m not sure that is what’s causing tests 
to fail.

> On Mar 12, 2018, at 9:29 AM, Eric Liu  wrote:
> 
> I have been trying to reduce a reproducer for this but haven't gotten any 
> luck yet. The error happens in conversion between different version of STL 
> containers and is a bit hard to reduce. I'll keep trying to create a 
> reproducer.
> 
> Could you please also take a quick look to see if ASTImporter/Reader/Writer 
> is actually missing something?
> 
> Thanks,
> Eric
> 
> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka  <mailto:ahatan...@apple.com>> wrote:
> Do you have a reproducer?
> 
> 
>> On Mar 12, 2018, at 9:07 AM, Eric Liu > <mailto:ioe...@google.com>> wrote:
>> 
>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
>> what's the right way to fix it. I'll revert this commit for now to unblock 
>> integration. Let me know if you need more information from us.
>> 
>> Regards,
>> Eric
>> 
>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu > <mailto:ioe...@google.com>> wrote:
>> The tests only failed with module enabled. FWIW, I think the change in 
>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
>> <https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk>) needs additional 
>> changes to make imports work for RecordDecl. 
>> 
>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu > <mailto:ioe...@google.com>> wrote:
>> Hi Akira,
>> 
>> It seems that this commit also changes behavior for compiling C++ code as we 
>> are seeing test failures caused by this change in our internal tests.
>> 
>> I'm still trying to reduce a reproducer for the failure. In the meantime, 
>> could you please double check if this affects C++?
>> 
>> Thanks,
>> Eric
>> 
>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
>> mailto:cfe-commits@lists.llvm.org>> wrote:
>> Author: ahatanak
>> Date: Fri Mar  9 22:36:08 2018
>> New Revision: 327206
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
>> <http://llvm.org/viewvc/llvm-project?rev=327206&view=rev>
>> Log:
>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>> 
>> This patch uses the infrastructure added in r326307 for enabling
>> non-trivial fields to be declared in C structs to allow __weak fields in
>> C structs in ARC.
>> 
>> rdar://problem/33599681 <>
>> 
>> Differential Revision: https://reviews.llvm.org/D44095 
>> <https://reviews.llvm.org/D44095>
>> 
>> Added:
>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>> Modified:
>> cfe/trunk/include/clang/AST/Decl.h
>> cfe/trunk/include/clang/AST/DeclCXX.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/lib/AST/ASTImporter.cpp
>> cfe/trunk/lib/AST/Decl.cpp
>> cfe/trunk/lib/AST/DeclCXX.cpp
>> cfe/trunk/lib/AST/Type.cpp
>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>> cfe/trunk/lib/Sema/SemaDecl.cpp
>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>> 
>> Modified: cfe/trunk/include/clang/AST/Decl.h
>> URL: 
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff
>>  
>> <http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327206&r1=327205&r2=327206&view=diff>
>> ==
>> --- cfe/trunk/include/clang/AST/Decl.h (original)
>> +++ cfe/trunk/include/clang/AST/Decl.h Fri Mar  9 22:36:08 2018
>> @@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
>>bool NonTrivialToPrimitiveCopy : 1;
>>bool NonTrivialToPrimitiveDestroy : 1;
>> 
>> +  /// True if this class can be passed in a non-address-preserving fashion
>> +  /// (such as in registers).
>> +  /// This does not imply anything about how the ABI in use will actually
>> +  ///

Re: r327206 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-12 Thread Akira Hatanaka via cfe-commits
I’m not sure if this a bug r327206 introduced or an existing bug in ASTImporter 
as there are other bits in RecordDecl that are not copied, but I think I should 
revert the patch for now.

> On Mar 12, 2018, at 9:57 AM, Eric Liu  wrote:
> 
> I think it's likely as our tests only fail with module enabled (without 
> module, ASTImporter isn't really used).
> 
> On Mon, Mar 12, 2018 at 5:51 PM Akira Hatanaka  <mailto:ahatan...@apple.com>> wrote:
> The patch I committed moved CXXRecordDecl::CanPassInRegisters to RecordDecl. 
> It looks like ASTImporter::ImportDefinition no longer copies the bit for 
> CanPassInRegisters after that change. I’m not sure that is what’s causing 
> tests to fail.
> 
>> On Mar 12, 2018, at 9:29 AM, Eric Liu > <mailto:ioe...@google.com>> wrote:
>> 
>> I have been trying to reduce a reproducer for this but haven't gotten any 
>> luck yet. The error happens in conversion between different version of STL 
>> containers and is a bit hard to reduce. I'll keep trying to create a 
>> reproducer.
>> 
>> Could you please also take a quick look to see if ASTImporter/Reader/Writer 
>> is actually missing something?
>> 
>> Thanks,
>> Eric
>> 
>> On Mon, Mar 12, 2018 at 5:14 PM Akira Hatanaka > <mailto:ahatan...@apple.com>> wrote:
>> Do you have a reproducer?
>> 
>> 
>>> On Mar 12, 2018, at 9:07 AM, Eric Liu >> <mailto:ioe...@google.com>> wrote:
>>> 
>>> I think there is a bug in the ASTImporter/Reader/Writer, but I'm not sure 
>>> what's the right way to fix it. I'll revert this commit for now to unblock 
>>> integration. Let me know if you need more information from us.
>>> 
>>> Regards,
>>> Eric
>>> 
>>> On Mon, Mar 12, 2018 at 4:51 PM Eric Liu >> <mailto:ioe...@google.com>> wrote:
>>> The tests only failed with module enabled. FWIW, I think the change in 
>>> ASTImporter (https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk 
>>> <https://reviews.llvm.org/rL327206#change-1q8vFFjJ6Cqk>) needs additional 
>>> changes to make imports work for RecordDecl. 
>>> 
>>> On Mon, Mar 12, 2018 at 3:56 PM Eric Liu >> <mailto:ioe...@google.com>> wrote:
>>> Hi Akira,
>>> 
>>> It seems that this commit also changes behavior for compiling C++ code as 
>>> we are seeing test failures caused by this change in our internal tests.
>>> 
>>> I'm still trying to reduce a reproducer for the failure. In the meantime, 
>>> could you please double check if this affects C++?
>>> 
>>> Thanks,
>>> Eric
>>> 
>>> On Sat, Mar 10, 2018 at 7:38 AM Akira Hatanaka via cfe-commits 
>>> mailto:cfe-commits@lists.llvm.org>> wrote:
>>> Author: ahatanak
>>> Date: Fri Mar  9 22:36:08 2018
>>> New Revision: 327206
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=327206&view=rev 
>>> <http://llvm.org/viewvc/llvm-project?rev=327206&view=rev>
>>> Log:
>>> [ObjC] Allow declaring __weak pointer fields in C structs in ARC.
>>> 
>>> This patch uses the infrastructure added in r326307 for enabling
>>> non-trivial fields to be declared in C structs to allow __weak fields in
>>> C structs in ARC.
>>> 
>>> rdar://problem/33599681 <>
>>> 
>>> Differential Revision: https://reviews.llvm.org/D44095 
>>> <https://reviews.llvm.org/D44095>
>>> 
>>> Added:
>>> cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
>>> Modified:
>>> cfe/trunk/include/clang/AST/Decl.h
>>> cfe/trunk/include/clang/AST/DeclCXX.h
>>> cfe/trunk/include/clang/AST/Type.h
>>> cfe/trunk/lib/AST/ASTImporter.cpp
>>> cfe/trunk/lib/AST/Decl.cpp
>>> cfe/trunk/lib/AST/DeclCXX.cpp
>>> cfe/trunk/lib/AST/Type.cpp
>>> cfe/trunk/lib/CodeGen/CGBlocks.cpp
>>> cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
>>> cfe/trunk/lib/CodeGen/CGObjC.cpp
>>> cfe/trunk/lib/CodeGen/CodeGenFunction.h
>>> cfe/trunk/lib/CodeGen/TargetInfo.cpp
>>> cfe/trunk/lib/Sema/SemaDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
>>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>>> cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
>>> cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
>>> 
>>> Modified: cfe/trunk/include/clang/AST/Decl.h
>>> UR

r327294 - Revert "[ObjC] Allow declaring __weak pointer fields in C structs in

2018-03-12 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Mar 12 10:05:06 2018
New Revision: 327294

URL: http://llvm.org/viewvc/llvm-project?rev=327294&view=rev
Log:
Revert "[ObjC] Allow declaring __weak pointer fields in C structs in
ARC."

This reverts commit r327206 as there were test failures caused by this
patch.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20180312/221427.html

Removed:
cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Mar 12 10:05:06 2018
@@ -3553,12 +3553,6 @@ class RecordDecl : public TagDecl {
   bool NonTrivialToPrimitiveCopy : 1;
   bool NonTrivialToPrimitiveDestroy : 1;
 
-  /// True if this class can be passed in a non-address-preserving fashion
-  /// (such as in registers).
-  /// This does not imply anything about how the ABI in use will actually
-  /// pass an object of this class.
-  bool CanPassInRegisters : 1;
-
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3642,18 +3636,6 @@ public:
 NonTrivialToPrimitiveDestroy = true;
   }
 
-  /// Determine whether this class can be passed in registers. In C++ mode,
-  /// it must have at least one trivial, non-deleted copy or move constructor.
-  /// FIXME: This should be set as part of completeDefinition.
-  bool canPassInRegisters() const {
-return CanPassInRegisters;
-  }
-
-  /// Set that we can pass this RecordDecl in registers.
-  void setCanPassInRegisters(bool CanPass) {
-CanPassInRegisters = CanPass;
-  }
-
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Mar 12 10:05:06 2018
@@ -467,6 +467,12 @@ class CXXRecordDecl : public RecordDecl
 /// constructor.
 unsigned HasDefaultedDefaultConstructor : 1;
 
+/// \brief True if this class can be passed in a non-address-preserving
+/// fashion (such as in registers) according to the C++ language rules.
+/// This does not imply anything about how the ABI in use will actually
+/// pass an object of this class.
+unsigned CanPassInRegisters : 1;
+
 /// \brief True if a defaulted default constructor for this class would
 /// be constexpr.
 unsigned DefaultedDefaultConstructorIsConstexpr : 1;
@@ -1468,6 +1474,18 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
+  /// \brief Determine whether this class has at least one trivial, non-deleted
+  /// copy or move constructor.
+  bool canPassInRegisters() const {
+return data().CanPassInRegisters;
+  }
+
+  /// \brief Set that we can pass this RecordDecl in registers.
+  // FIXME: This should be set as part of completeDefinition.
+  void setCanPassInRegisters(bool CanPass) {
+data().CanPassInRegisters = CanPass;
+  }
+
   /// Determine whether the triviality for the purpose of calls for this class
   /// is overridden to be trivial because this class or the type of one of its
   /// subobjects has attribute "trivial_abi".

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=327294&r1=327293&r2=327294&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Mar 12 10:05:06 2018
@@ -1097,10 +1097,6 @@ public:
 /// with the ARC __strong qualifier.
 PDIK_ARCStrong,
 
-/// The type is an Objective-C retainable pointer type that is qualified
-/// with the ARC __weak qualifier.
-PDIK_ARCWeak,
-
 /// The type is a struct containing a field whose typ

r327434 - Serialize the NonTrivialToPrimitive* flags I added in r326307.

2018-03-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Mar 13 11:58:25 2018
New Revision: 327434

URL: http://llvm.org/viewvc/llvm-project?rev=327434&view=rev
Log:
Serialize the NonTrivialToPrimitive* flags I added in r326307.

rdar://problem/38421774

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327434&r1=327433&r2=327434&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Tue Mar 13 11:58:25 2018
@@ -3616,24 +3616,24 @@ public:
 return NonTrivialToPrimitiveDefaultInitialize;
   }
 
-  void setNonTrivialToPrimitiveDefaultInitialize() {
-NonTrivialToPrimitiveDefaultInitialize = true;
+  void setNonTrivialToPrimitiveDefaultInitialize(bool V) {
+NonTrivialToPrimitiveDefaultInitialize = V;
   }
 
   bool isNonTrivialToPrimitiveCopy() const {
 return NonTrivialToPrimitiveCopy;
   }
 
-  void setNonTrivialToPrimitiveCopy() {
-NonTrivialToPrimitiveCopy = true;
+  void setNonTrivialToPrimitiveCopy(bool V) {
+NonTrivialToPrimitiveCopy = V;
   }
 
   bool isNonTrivialToPrimitiveDestroy() const {
 return NonTrivialToPrimitiveDestroy;
   }
 
-  void setNonTrivialToPrimitiveDestroy() {
-NonTrivialToPrimitiveDestroy = true;
+  void setNonTrivialToPrimitiveDestroy(bool V) {
+NonTrivialToPrimitiveDestroy = V;
   }
 
   /// \brief Determines whether this declaration represents the

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327434&r1=327433&r2=327434&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 13 11:58:25 2018
@@ -15445,12 +15445,12 @@ void Sema::ActOnFields(Scope *S, SourceL
 if (Record && !getLangOpts().CPlusPlus) {
   QualType FT = FD->getType();
   if (FT.isNonTrivialToPrimitiveDefaultInitialize())
-Record->setNonTrivialToPrimitiveDefaultInitialize();
+Record->setNonTrivialToPrimitiveDefaultInitialize(true);
   QualType::PrimitiveCopyKind PCK = FT.isNonTrivialToPrimitiveCopy();
   if (PCK != QualType::PCK_Trivial && PCK != QualType::PCK_VolatileTrivial)
-Record->setNonTrivialToPrimitiveCopy();
+Record->setNonTrivialToPrimitiveCopy(true);
   if (FT.isDestructedType())
-Record->setNonTrivialToPrimitiveDestroy();
+Record->setNonTrivialToPrimitiveDestroy(true);
 }
 
 if (Record && FD->getType().isVolatileQualified())

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=327434&r1=327433&r2=327434&view=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Tue Mar 13 11:58:25 2018
@@ -739,6 +739,9 @@ ASTDeclReader::VisitRecordDeclImpl(Recor
   RD->setAnonymousStructOrUnion(Record.readInt());
   RD->setHasObjectMember(Record.readInt());
   RD->setHasVolatileMember(Record.readInt());
+  RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt());
+  RD->setNonTrivialToPrimitiveCopy(Record.readInt());
+  RD->setNonTrivialToPrimitiveDestroy(Record.readInt());
   return Redecl;
 }
 

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=327434&r1=327433&r2=327434&view=diff
==
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Tue Mar 13 11:58:25 2018
@@ -465,6 +465,9 @@ void ASTDeclWriter::VisitRecordDecl(Reco
   Record.push_back(D->isAnonymousStructOrUnion());
   Record.push_back(D->hasObjectMember());
   Record.push_back(D->hasVolatileMember());
+  Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
+  Record.push_back(D->isNonTrivialToPrimitiveCopy());
+  Record.push_back(D->isNonTrivialToPrimitiveDestroy());
 
   if (D->getDeclContext() == D->getLexicalDeclContext() &&
   !D->hasAttrs() &&
@@ -1899,6 +1902,14 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
+
+  // isNonTrivialToPrimitiveDefaultInitialize
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
+  // isNonTrivialToPrimitiveCopy

r327464 - Check that a field is not annotated with attribute "unavailable" before

2018-03-13 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Mar 13 16:37:51 2018
New Revision: 327464

URL: http://llvm.org/viewvc/llvm-project?rev=327464&view=rev
Log:
Check that a field is not annotated with attribute "unavailable" before
setting the NonTrivialToPrimitive* flags of a record.

Union fields that have non-trivial Objective-C ownership qualifications
are normally not legal, but if the union is declared in a system header,
the fields are annotated with attribute "unavailable".

rdar://problem/38431072

Added:
cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=327464&r1=327463&r2=327464&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 13 16:37:51 2018
@@ -15442,7 +15442,7 @@ void Sema::ActOnFields(Scope *S, SourceL
   }
 }
 
-if (Record && !getLangOpts().CPlusPlus) {
+if (Record && !getLangOpts().CPlusPlus && !FD->hasAttr()) 
{
   QualType FT = FD->getType();
   if (FT.isNonTrivialToPrimitiveDefaultInitialize())
 Record->setNonTrivialToPrimitiveDefaultInitialize(true);

Added: cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h?rev=327464&view=auto
==
--- cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h (added)
+++ cfe/trunk/test/CodeGenObjC/Inputs/strong_in_union.h Tue Mar 13 16:37:51 2018
@@ -0,0 +1,10 @@
+#ifndef STRONG_IN_UNION_H
+#define STRONG_IN_UNION_H
+#pragma clang system_header
+
+typedef union {
+  id f0;
+  int *f1;
+} U;
+
+#endif // STRONG_IN_UNION_H

Modified: cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m?rev=327464&r1=327463&r2=327464&view=diff
==
--- cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m (original)
+++ cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m Tue Mar 13 16:37:51 2018
@@ -1,10 +1,11 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -emit-llvm -o - -DUSESTRUCT -I %S/Inputs %s | FileCheck 
%s
 
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -emit-pch -o %t %s
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT %s | 
FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -emit-pch -I %S/Inputs -o %t %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -fobjc-arc -fblocks  
-fobjc-runtime=ios-11.0 -include-pch %t -emit-llvm -o - -DUSESTRUCT -I 
%S/Inputs %s | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
+#include "strong_in_union.h"
 
 typedef void (^BlockTy)(void);
 
@@ -531,4 +532,12 @@ void test_copy_constructor_Bitfield1(Bit
   Bitfield1 t = *a;
 }
 
+// CHECK: define void @test_strong_in_union()
+// CHECK: alloca %{{.*}}
+// CHECK-NEXT: ret void
+
+void test_strong_in_union() {
+  U t;
+}
+
 #endif /* USESTRUCT */


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


r327870 - [ObjC] Allow declaring __weak pointer fields in C structs in ARC.

2018-03-19 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Mar 19 10:38:40 2018
New Revision: 327870

URL: http://llvm.org/viewvc/llvm-project?rev=327870&view=rev
Log:
[ObjC] Allow declaring __weak pointer fields in C structs in ARC.

This patch uses the infrastructure added in r326307 for enabling
non-trivial fields to be declared in C structs to allow __weak fields in
C structs in ARC.

This recommits r327206, which was reverted because it caused
module-enabled builders to fail. I discovered that the
CXXRecordDecl::CanPassInRegisters flag wasn't being set correctly in
some cases after I moved it to RecordDecl.

Thanks to Eric Liu for helping me investigate the bug.

rdar://problem/33599681

https://reviews.llvm.org/D44095

Added:
cfe/trunk/test/CodeGenObjC/weak-in-c-struct.m
cfe/trunk/test/Modules/Inputs/template-nontrivial0.h
cfe/trunk/test/Modules/Inputs/template-nontrivial1.h
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/nontrivial-c-struct-exception.m
cfe/trunk/test/Modules/Inputs/module.map
cfe/trunk/test/Modules/templates.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=327870&r1=327869&r2=327870&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Mar 19 10:38:40 2018
@@ -3553,6 +3553,12 @@ class RecordDecl : public TagDecl {
   bool NonTrivialToPrimitiveCopy : 1;
   bool NonTrivialToPrimitiveDestroy : 1;
 
+  /// True if this class can be passed in a non-address-preserving fashion
+  /// (such as in registers).
+  /// This does not imply anything about how the ABI in use will actually
+  /// pass an object of this class.
+  bool CanPassInRegisters : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3636,6 +3642,18 @@ public:
 NonTrivialToPrimitiveDestroy = V;
   }
 
+  /// Determine whether this class can be passed in registers. In C++ mode,
+  /// it must have at least one trivial, non-deleted copy or move constructor.
+  /// FIXME: This should be set as part of completeDefinition.
+  bool canPassInRegisters() const {
+return CanPassInRegisters;
+  }
+
+  /// Set that we can pass this RecordDecl in registers.
+  void setCanPassInRegisters(bool CanPass) {
+CanPassInRegisters = CanPass;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=327870&r1=327869&r2=327870&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Mon Mar 19 10:38:40 2018
@@ -467,12 +467,6 @@ class CXXRecordDecl : public RecordDecl
 /// constructor.
 unsigned HasDefaultedDefaultConstructor : 1;
 
-/// \brief True if this class can be passed in a non-address-preserving
-/// fashion (such as in registers) according to the C++ language rules.
-/// This does not imply anything about how the ABI in use will actually
-/// pass an object of this class.
-unsigned CanPassInRegisters : 1;
-
 /// \brief True if a defaulted default constructor for this class would
 /// be constexpr.
 unsigned DefaultedDefaultConstructorIsConstexpr : 1;
@@ -1474,18 +1468,6 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
-  /// \brief Determine whether this class has at least one trivial, non-deleted
-  /// copy or move constructor.
-  bool canPassInRegisters() const {
-return data().CanPassInRegisters;
-  }
-
-  /// \brief Set that we can pass this RecordDecl in registers.
-  // FIXME: This should be set as part of completeDefinition.
-  void setCanPassInRegisters(bool CanPass) {
-data().CanPassInRegisters = CanPass;
-  }
-
   /// Determine whether the triviality for the purpose of calls for this class
   /// is overridden to be trivial because this class or the type of one of its
   /// subobjects has attribute "trivial_abi".

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h

r327939 - [CodeGen] Ignore OpaqueValueExprs that are unique references to their

2018-03-19 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Mar 19 18:47:58 2018
New Revision: 327939

URL: http://llvm.org/viewvc/llvm-project?rev=327939&view=rev
Log:
[CodeGen] Ignore OpaqueValueExprs that are unique references to their
source expressions when iterating over a PseudoObjectExpr's semantic
subexpression list.

Previously the loop in emitPseudoObjectExpr would emit the IR for each
OpaqueValueExpr that was in a PseudoObjectExpr's semantic-form
expression list and use the result when the OpaqueValueExpr later
appeared in other expressions. This caused an assertion failure when
AggExprEmitter tried to copy the result of an OpaqueValueExpr and the
copied type didn't have trivial copy/move constructors or assignment
operators.

This patch adds flag IsUnique to OpaqueValueExpr which indicates it is a
unique reference to its source expression (it is not used in multiple
places). The loop in emitPseudoObjectExpr ignores OpaqueValueExprs that
are unique and CodeGen visitors simply traverse the source expressions
of such OpaqueValueExprs.

rdar://problem/34363596

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

Added:
cfe/trunk/test/CodeGenObjCXX/property-dot-copy-elision.mm
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprComplex.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp
cfe/trunk/test/CodeGenCXX/ms-property.cpp
cfe/trunk/test/CodeGenObjC/objc-container-subscripting-1.m
cfe/trunk/test/CodeGenObjCXX/property-objects.mm

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=327939&r1=327938&r2=327939&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Mar 19 18:47:58 2018
@@ -883,6 +883,7 @@ public:
(SourceExpr && SourceExpr->isInstantiationDependent()),
false),
   SourceExpr(SourceExpr), Loc(Loc) {
+setIsUnique(false);
   }
 
   /// Given an expression which invokes a copy constructor --- i.e.  a
@@ -925,6 +926,14 @@ public:
   /// place.
   Expr *getSourceExpr() const { return SourceExpr; }
 
+  void setIsUnique(bool V) {
+assert((!V || SourceExpr) &&
+   "unique OVEs are expected to have source expressions");
+OpaqueValueExprBits.IsUnique = V;
+  }
+
+  bool isUnique() const { return OpaqueValueExprBits.IsUnique; }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == OpaqueValueExprClass;
   }

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=327939&r1=327938&r2=327939&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Mon Mar 19 18:47:58 2018
@@ -237,6 +237,16 @@ protected:
 unsigned ResultIndex : 32 - 8 - NumExprBits;
   };
 
+  class OpaqueValueExprBitfields {
+friend class OpaqueValueExpr;
+
+unsigned : NumExprBits;
+
+/// The OVE is a unique semantic reference to its source expressio if this
+/// bit is set to true.
+unsigned IsUnique : 1;
+  };
+
   class ObjCIndirectCopyRestoreExprBitfields {
 friend class ObjCIndirectCopyRestoreExpr;
 
@@ -294,6 +304,7 @@ protected:
 CallExprBitfields CallExprBits;
 ExprWithCleanupsBitfields ExprWithCleanupsBits;
 PseudoObjectExprBitfields PseudoObjectExprBits;
+OpaqueValueExprBitfields OpaqueValueExprBits;
 ObjCIndirectCopyRestoreExprBitfields ObjCIndirectCopyRestoreExprBits;
 InitListExprBitfields InitListExprBits;
 TypeTraitExprBitfields TypeTraitExprBits;

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=327939&r1=327938&r2=327939&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Mar 19 18:47:58 2018
@@ -4167,7 +4167,35 @@ LValue CodeGenFunction::EmitCastLValue(c
 
 LValue CodeGenFunction::EmitOpaqueValueLValue(const OpaqueValueExpr *e) {
   assert(OpaqueValueMappingData::shouldBindAsLValue(e));
-  return getOpaqueLValueMapping(e);
+  return getOrCreateOpaqueLValueMapping(e);
+}
+
+LValue
+CodeGenFunction::getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e) {
+  assert(OpaqueValueMapping::shouldBindAsLValue(e));
+
+  llvm::DenseMap::iterator
+  it = OpaqueLValues.find(e);
+
+  if (it != OpaqueLValues.end())
+return it->second;
+
+  assert(e->isUnique() && "LValue for a nonunique OVE hasn't been e

r334569 - [Sema] When the address of a member function is used as a template

2018-06-12 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Jun 12 22:26:23 2018
New Revision: 334569

URL: http://llvm.org/viewvc/llvm-project?rev=334569&view=rev
Log:
[Sema] When the address of a member function is used as a template
argument, use the context in which it is used for checking its
accessibility.

This fixes PR32898.

rdar://problem/33737747

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

Modified:
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/test/SemaCXX/access.cpp

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=334569&r1=334568&r2=334569&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Tue Jun 12 22:26:23 2018
@@ -3803,10 +3803,16 @@ Sema::TemplateDeductionResult Sema::Dedu
   return Result;
   }
 
+  // Capture the context in which the function call is made. This is the 
context
+  // that is needed when the accessibility of template arguments is checked.
+  DeclContext *CallingCtx = CurContext;
+
   return FinishTemplateArgumentDeduction(
   FunctionTemplate, Deduced, NumExplicitlySpecified, Specialization, Info,
-  &OriginalCallArgs, PartialOverloading,
-  [&]() { return CheckNonDependent(ParamTypesForArgChecking); });
+  &OriginalCallArgs, PartialOverloading, [&, CallingCtx]() {
+ContextRAII SavedContext(*this, CallingCtx);
+return CheckNonDependent(ParamTypesForArgChecking);
+  });
 }
 
 QualType Sema::adjustCCAndNoReturn(QualType ArgFunctionType,

Modified: cfe/trunk/test/SemaCXX/access.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/access.cpp?rev=334569&r1=334568&r2=334569&view=diff
==
--- cfe/trunk/test/SemaCXX/access.cpp (original)
+++ cfe/trunk/test/SemaCXX/access.cpp Tue Jun 12 22:26:23 2018
@@ -169,3 +169,50 @@ namespace ThisLambdaIsNotMyFriend {
   }
   void bar() { foo(); }
 }
+
+namespace OverloadedMemberFunctionPointer {
+  template
+  void func0() {}
+
+  template
+  void func1() {}
+
+  template
+  void func2(void(*fn)()) {} // expected-note 2 {{candidate function template 
not viable: no overload of 'func}}
+
+  class C {
+  private:
+friend void friendFunc();
+void overloadedMethod();
+  protected:
+void overloadedMethod(int);
+  public:
+void overloadedMethod(int, int);
+void method() {
+  func2(&func0);
+  func2(&func1);
+}
+  };
+
+  void friendFunc() {
+func2(&func0);
+func2(&func1);
+  }
+
+  void nonFriendFunc() {
+func2(&func0); // expected-error {{no 
matching function for call to 'func2'}}
+func2(&func1); // expected-error {{no 
matching function for call to 'func2'}}
+  }
+
+  // r325321 caused an assertion failure when the following code was compiled.
+  class A {
+template  static bool foo1() { return true; }
+
+  public:
+void init(bool c) {
+  if (c) {
+auto f = foo1;
+  }
+}
+  };
+}


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


r335021 - [Sema] Produce diagnostics for attribute 'trivial_abi' that appears

2018-06-18 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Jun 18 22:04:44 2018
New Revision: 335021

URL: http://llvm.org/viewvc/llvm-project?rev=335021&view=rev
Log:
[Sema] Produce diagnostics for attribute 'trivial_abi' that appears
after the closing brace of a class declaration.

Merge the two call sites of checkIllFormedTrivialABIStruct and sink it
into CheckCompletedCXXClass so that it is called after the attribute has
been attached to the CXXRecordDecl.

rdar://problem/40873297

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Mon Jun 18 22:04:44 2018
@@ -6018,6 +6018,10 @@ void Sema::CheckCompletedCXXClass(CXXRec
 }
   }
 
+  // See if trivial_abi has to be dropped.
+  if (Record->hasAttr())
+checkIllFormedTrivialABIStruct(*Record);
+
   // Set HasTrivialSpecialMemberForCall if the record has attribute
   // "trivial_abi".
   bool HasTrivialABI = Record->hasAttr();
@@ -7810,17 +7814,12 @@ void Sema::ActOnFinishCXXMemberSpecifica
   l->getName();
   }
 
-  // See if trivial_abi has to be dropped.
-  auto *RD = dyn_cast(TagDecl);
-  if (RD && RD->hasAttr())
-checkIllFormedTrivialABIStruct(*RD);
-
   ActOnFields(S, RLoc, TagDecl, llvm::makeArrayRef(
   // strict aliasing violation!
   reinterpret_cast(FieldCollector->getCurFields()),
   FieldCollector->getCurNumFields()), LBrac, RBrac, AttrList);
 
-  CheckCompletedCXXClass(RD);
+  CheckCompletedCXXClass(dyn_cast_or_null(TagDecl));
 }
 
 /// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Jun 18 22:04:44 2018
@@ -2123,10 +2123,6 @@ Sema::InstantiateClass(SourceLocation Po
 }
   }
 
-  // See if trivial_abi has to be dropped.
-  if (Instantiation && Instantiation->hasAttr())
-checkIllFormedTrivialABIStruct(*Instantiation);
-
   // Finish checking fields.
   ActOnFields(nullptr, Instantiation->getLocation(), Instantiation, Fields,
   SourceLocation(), SourceLocation(), nullptr);

Modified: cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm?rev=335021&r1=335020&r2=335021&view=diff
==
--- cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm (original)
+++ cfe/trunk/test/SemaObjCXX/attr-trivial-abi.mm Mon Jun 18 22:04:44 2018
@@ -18,6 +18,10 @@ struct __attribute__((trivial_abi)) S3 {
   virtual void m();
 };
 
+struct S3_2 {
+  virtual void m();
+} __attribute__((trivial_abi)); // expected-warning {{'trivial_abi' cannot be 
applied to 'S3_2'}}
+
 struct S4 {
   int a;
 };


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


r335189 - Use cast instead of dyn_cast_or_null.

2018-06-20 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Jun 20 15:56:59 2018
New Revision: 335189

URL: http://llvm.org/viewvc/llvm-project?rev=335189&view=rev
Log:
Use cast instead of dyn_cast_or_null.

This addresses John's post-commit review feedback.

https://reviews.llvm.org/rC335021#inline-2038

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=335189&r1=335188&r2=335189&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jun 20 15:56:59 2018
@@ -7832,7 +7832,7 @@ void Sema::ActOnFinishCXXMemberSpecifica
   reinterpret_cast(FieldCollector->getCurFields()),
   FieldCollector->getCurNumFields()), LBrac, RBrac, AttrList);
 
-  CheckCompletedCXXClass(dyn_cast_or_null(TagDecl));
+  CheckCompletedCXXClass(cast(TagDecl));
 }
 
 /// AddImplicitlyDeclaredMembersToClass - Adds any implicitly-declared


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


[clang-tools-extra] r344827 - Disable unittests/clangd/JSONTransportTests.cpp on versions of macosx

2018-10-19 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct 19 19:11:45 2018
New Revision: 344827

URL: http://llvm.org/viewvc/llvm-project?rev=344827&view=rev
Log:
Disable unittests/clangd/JSONTransportTests.cpp on versions of macosx
earlier than 10.13.

rdar://problem/45310173

Modified:
clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp?rev=344827&r1=344826&r2=344827&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp Fri Oct 19 
19:11:45 2018
@@ -17,8 +17,9 @@ namespace clang {
 namespace clangd {
 namespace {
 
-// No fmemopen on windows, so we can't easily run this test.
-#ifndef WIN32
+// No fmemopen on windows or on versions of MacOS X earlier than 10.13, so we
+// can't easily run this test.
+#if !(defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
 
 // Fixture takes care of managing the input/output buffers for the transport.
 class JSONTransportTest : public ::testing::Test {


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


r344833 - [CodeGen] Use the mangle context owned by CodeGenModule to correctly

2018-10-19 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Oct 19 22:45:01 2018
New Revision: 344833

URL: http://llvm.org/viewvc/llvm-project?rev=344833&view=rev
Log:
[CodeGen] Use the mangle context owned by CodeGenModule to correctly
mangle types of lambda objects captured by a block instead of creating a
new mangle context everytime a captured field type is mangled.

This fixes a bug in IRGen's block helper merging code that was
introduced in r339438 where two blocks capturing two distinct lambdas
would end up sharing helper functions and the block descriptor. This
happened because the ID number used to distinguish lambdas defined
in the same context is reset everytime a mangled context is created.

rdar://problem/45314494

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=344833&r1=344832&r2=344833&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Fri Oct 19 22:45:01 2018
@@ -1817,8 +1817,6 @@ static std::string getBlockCaptureStr(co
   CodeGenModule &CGM) {
   std::string Str;
   ASTContext &Ctx = CGM.getContext();
-  std::unique_ptr MC(
-  ItaniumMangleContext::create(Ctx, Ctx.getDiagnostics()));
   const BlockDecl::Capture &CI = *E.CI;
   QualType CaptureTy = CI.getVariable()->getType();
 
@@ -1844,7 +1842,7 @@ static std::string getBlockCaptureStr(co
 Str += "c";
 SmallString<256> TyStr;
 llvm::raw_svector_ostream Out(TyStr);
-MC->mangleTypeName(CaptureTy, Out);
+CGM.getCXXABI().getMangleContext().mangleTypeName(CaptureTy, Out);
 Str += llvm::to_string(TyStr.size()) + TyStr.c_str();
 break;
   }

Modified: cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm?rev=344833&r1=344832&r2=344833&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/lambda-to-block.mm Fri Oct 19 22:45:01 2018
@@ -3,16 +3,74 @@
 // rdar://31385153
 // Shouldn't crash!
 
+// CHECK: %[[STRUCT_COPYABLE:.*]] = type { i8 }
+// CHECK: %[[STRUCT_BLOCK_DESCRIPTOR:.*]] = type { i64, i64 }
+// CHECK: %[[CLASS_ANON:.*]] = type { %[[STRUCT_COPYABLE]] }
+// CHECK: %[[CLASS_ANON_0:.*]] = type { %[[STRUCT_COPYABLE]] }
+// CHECK: %[[CLASS_ANON_1:.*]] = type { %[[STRUCT_COPYABLE]] }
+// CHECK: %[[CLASS_ANON_2:.*]] = type { %[[STRUCT_COPYABLE]] }
+
+// CHECK: @[[BLOCK_DESC0:.*]] = internal constant { i64, i64, i8*, i8*, i8*, 
i8* } { i64 0, i64 33, i8* bitcast (void (i8*, i8*)* 
@[[COPY_HELPER0:.*__copy_helper_block_.*]] to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block{{.*}} to i8*), {{.*}}}, align 8
+// CHECK: @[[BLOCK_DESC1:.*]] = internal constant { i64, i64, i8*, i8*, i8*, 
i8* } { i64 0, i64 33, i8* bitcast (void (i8*, i8*)* 
@[[COPY_HELPER1:.*__copy_helper_block_.*]] to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block{{.*}} to i8*), {{.*}}}, align 8
+// CHECK: @[[BLOCK_DESC2:.*]] = internal constant { i64, i64, i8*, i8*, i8*, 
i8* } { i64 0, i64 33, i8* bitcast (void (i8*, i8*)* 
@[[COPY_HELPER2:.*__copy_helper_block_.*]] to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block{{.*}} to i8*), {{.*}}}, align 8
+// CHECK: @[[BLOCK_DESC3:.*]] = internal constant { i64, i64, i8*, i8*, i8*, 
i8* } { i64 0, i64 33, i8* bitcast (void (i8*, i8*)* 
@[[COPY_HELPER3:.*__copy_helper_block_.*]] to i8*), i8* bitcast (void (i8*)* 
@__destroy_helper_block{{.*}} to i8*), {{.*}}}, align 8
+
+// CHECK: define void @_Z9hasLambda8Copyable(
+// CHECK: %[[BLOCK:.*]] = alloca <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON]] }>, align 8
+// CHECK: %[[BLOCK1:.*]] = alloca <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON_0]] }>, align 8
+// CHECK: %[[BLOCK_DESCRIPTOR:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON]] }>, <{ i8*, i32, i32, i8*, 
%[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON]] }>* %[[BLOCK]], i32 0, i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i8* }* @[[BLOCK_DESC0]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR]], align 8
+// CHECK: %[[BLOCK_DESCRIPTOR6:.*]] = getelementptr inbounds <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON_0]] }>, <{ i8*, i32, i32, 
i8*, %[[STRUCT_BLOCK_DESCRIPTOR]]*, %[[CLASS_ANON_0]] }>* %[[BLOCK1]], i32 0, 
i32 4
+// CHECK: store %[[STRUCT_BLOCK_DESCRIPTOR]]* bitcast ({ i64, i64, i8*, i8*, 
i8*, i8* }* @[[BLOCK_DESC1]] to %[[STRUCT_BLOCK_DESCRIPTOR]]*), 
%[[STRUCT_BLOCK_DESCRIPTOR]]** %[[BLOCK_DESCRIPTOR6]], align 8
+
 void takesBlock(void (^)(void));
 
 stru

[clang-tools-extra] r344856 - Check that __MAC_OS_X_VERSION_MIN_REQUIRED is defined before checking

2018-10-20 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Sat Oct 20 10:35:50 2018
New Revision: 344856

URL: http://llvm.org/viewvc/llvm-project?rev=344856&view=rev
Log:
Check that __MAC_OS_X_VERSION_MIN_REQUIRED is defined before checking
whether it is too old.

Modified:
clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp

Modified: clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp?rev=344856&r1=344855&r2=344856&view=diff
==
--- clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/JSONTransportTests.cpp Sat Oct 20 
10:35:50 2018
@@ -19,7 +19,9 @@ namespace {
 
 // No fmemopen on windows or on versions of MacOS X earlier than 10.13, so we
 // can't easily run this test.
-#if !(defined(WIN32) || __MAC_OS_X_VERSION_MIN_REQUIRED < 101300)
+#if !(defined(WIN32) || \
+  (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
+   __MAC_OS_X_VERSION_MIN_REQUIRED < 101300))
 
 // Fixture takes care of managing the input/output buffers for the transport.
 class JSONTransportTest : public ::testing::Test {


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


r350917 - [Sema] If CheckPlaceholderExpr rewrites the initializer of an auto

2019-01-10 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jan 10 20:57:34 2019
New Revision: 350917

URL: http://llvm.org/viewvc/llvm-project?rev=350917&view=rev
Log:
[Sema] If CheckPlaceholderExpr rewrites the initializer of an auto
variable during auto type deduction, use the rewritten initializer when
performing initialization of the variable.

This silences spurious -Warc-repeated-use-of-weak warnings that are
issued when the initializer uses a weak ObjC pointer.

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

Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/test/SemaObjC/arc-repeated-weak.mm

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=350917&r1=350916&r2=350917&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Jan 10 20:57:34 2019
@@ -1960,7 +1960,7 @@ public:
   bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous);
   void CheckVariableDeclarationType(VarDecl *NewVD);
   bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
- Expr *Init);
+ Expr *&Init);
   void CheckCompleteVariableDeclaration(VarDecl *VD);
   void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD);
   void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D);
@@ -7095,7 +7095,7 @@ public:
   QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name,
 QualType Type, TypeSourceInfo *TSI,
 SourceRange Range, bool DirectInit,
-Expr *Init);
+Expr *&Init);
 
   TypeLoc getReturnTypeLoc(FunctionDecl *FD) const;
 

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=350917&r1=350916&r2=350917&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 10 20:57:34 2019
@@ -10812,7 +10812,7 @@ QualType Sema::deduceVarTypeFromInitiali
 DeclarationName Name, QualType 
Type,
 TypeSourceInfo *TSI,
 SourceRange Range, bool DirectInit,
-Expr *Init) {
+Expr *&Init) {
   bool IsInitCapture = !VDecl;
   assert((!VDecl || !VDecl->isInitCapture()) &&
  "init captures are expected to be deduced prior to initialization");
@@ -10928,7 +10928,8 @@ QualType Sema::deduceVarTypeFromInitiali
   << (DeduceInit->getType().isNull() ? TSI->getType()
  : DeduceInit->getType())
   << DeduceInit->getSourceRange();
-  }
+  } else
+Init = DeduceInit;
 
   // Warn if we deduced 'id'. 'auto' usually implies type-safety, but using
   // 'id' instead of a specific object type prevents most of our usual
@@ -10945,7 +10946,7 @@ QualType Sema::deduceVarTypeFromInitiali
 }
 
 bool Sema::DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit,
- Expr *Init) {
+ Expr *&Init) {
   QualType DeducedType = deduceVarTypeFromInitializer(
   VDecl, VDecl->getDeclName(), VDecl->getType(), 
VDecl->getTypeSourceInfo(),
   VDecl->getSourceRange(), DirectInit, Init);
@@ -11451,8 +11452,9 @@ void Sema::ActOnUninitializedDecl(Decl *
   return;
 }
 
+Expr *TmpInit = nullptr;
 if (Type->isUndeducedType() &&
-DeduceVariableDeclarationType(Var, false, nullptr))
+DeduceVariableDeclarationType(Var, false, TmpInit))
   return;
 
 // C++11 [class.static.data]p3: A static data member can be declared with

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=350917&r1=350916&r2=350917&view=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jan 10 20:57:34 2019
@@ -1865,12 +1865,11 @@ Sema::BuildCXXNew(SourceRange Range, boo
 if (Braced && !getLangOpts().CPlusPlus17)
   Diag(Initializer->getBeginLoc(), diag::ext_auto_new_list_init)
   << AllocType << TypeRange;
-Expr *Deduce = Inits[0];
 QualType DeducedType;
-if (DeduceAutoType(AllocTypeInfo, Deduce, DeducedType) == DAR_Failed)
+if (DeduceAutoType(AllocTypeInfo, Inits[0], DeducedType) == DAR_Failed)
   return ExprEr

r350920 - [Sema] Make canPassInRegisters return true if the CXXRecordDecl passed

2019-01-10 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jan 10 23:06:38 2019
New Revision: 350920

URL: http://llvm.org/viewvc/llvm-project?rev=350920&view=rev
Log:
[Sema] Make canPassInRegisters return true if the CXXRecordDecl passed
to it is a trivial_abi class.

A class that has all of its copy and move constructors deleted can still
be passed or returned in registers if the class is annotated with
trivial_abi.

This fixes PR39683.

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/trivial_abi.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=350920&r1=350919&r2=350920&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 10 23:06:38 2019
@@ -5886,6 +5886,9 @@ static bool canPassInRegisters(Sema &S,
   if (D->isDependentType() || D->isInvalidDecl())
 return false;
 
+  if (D->hasAttr())
+return true;
+
   // Clang <= 4 used the pre-C++11 rule, which ignores move operations.
   // The PS4 platform ABI follows the behavior of Clang 3.2.
   if (CCK == TargetInfo::CCK_ClangABI4OrPS4)

Modified: cfe/trunk/test/CodeGenCXX/trivial_abi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/trivial_abi.cpp?rev=350920&r1=350919&r2=350920&view=diff
==
--- cfe/trunk/test/CodeGenCXX/trivial_abi.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/trivial_abi.cpp Thu Jan 10 23:06:38 2019
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions 
-fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions 
-fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
 
 // CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
 // CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
@@ -43,6 +43,13 @@ struct HasNonTrivial {
   NonTrivial m;
 };
 
+struct __attribute__((trivial_abi)) CopyMoveDeleted {
+  CopyMoveDeleted(int);
+  CopyMoveDeleted(const CopyMoveDeleted &) = delete;
+  CopyMoveDeleted(CopyMoveDeleted &&) = delete;
+  int a;
+};
+
 // CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
 // CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SMALL]], 
%[[STRUCT_SMALL]]* %[[A]], i32 0, i32 0
@@ -237,3 +244,11 @@ void calleeExceptionLarge(Large, Large);
 void testExceptionLarge() {
   calleeExceptionLarge(Large(), Large());
 }
+
+// A class with deleted copy and move constructors can still be passed or
+// returned in registers if the class is annotated with trivial_abi.
+
+// CHECK: define i64 @_Z19testCopyMoveDeletedi(i32 %
+CopyMoveDeleted testCopyMoveDeleted(int a) {
+  return a;
+}


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


Re: r350920 - [Sema] Make canPassInRegisters return true if the CXXRecordDecl passed

2019-01-15 Thread Akira Hatanaka via cfe-commits
Yes, the behavior of the compiler doesn’t match what’s explained in the documentation anymore.Please take a look at the attached patch, which updates the documentation.

trivial-abi-docs.patch
Description: Binary data
CC’ing a couple more people who commented on the original patch.On Jan 10, 2019, at 11:30 PM, Richard Smith <rich...@metafoo.co.uk> wrote:This is an ABI break (theoretically), but due to its nature I'm not too concerned.Please update the documentation for the attribute to describe these new semantics, though: the documentation currently says that we're just treating certain special members as if they were trivial when determining whether we can pass in registers, and that's not true any more, because the ABI says that classes with only deleted copy and move ctors is never passed in registers regardless of triviality.On Thu, 10 Jan 2019, 23:10 Akira Hatanaka via cfe-commits <cfe-commits@lists.llvm.org wrote:Author: ahatanak
Date: Thu Jan 10 23:06:38 2019
New Revision: 350920

URL: http://llvm.org/viewvc/llvm-project?rev=350920&view=rev
Log:
[Sema] Make canPassInRegisters return true if the CXXRecordDecl passed
to it is a trivial_abi class.

A class that has all of its copy and move constructors deleted can still
be passed or returned in registers if the class is annotated with
trivial_abi.

This fixes PR39683.

Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CodeGenCXX/trivial_abi.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=350920&r1=350919&r2=350920&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 10 23:06:38 2019
@@ -5886,6 +5886,9 @@ static bool canPassInRegisters(Sema &S,
   if (D->isDependentType() || D->isInvalidDecl())
     return false;

+  if (D->hasAttr())
+    return true;
+
   // Clang <= 4 used the pre-C++11 rule, which ignores move operations.
   // The PS4 platform ABI follows the behavior of Clang 3.2.
   if (CCK == TargetInfo::CCK_ClangABI4OrPS4)

Modified: cfe/trunk/test/CodeGenCXX/trivial_abi.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/trivial_abi.cpp?rev=350920&r1=350919&r2=350920&view=diff
==
--- cfe/trunk/test/CodeGenCXX/trivial_abi.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/trivial_abi.cpp Thu Jan 10 23:06:38 2019
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions -fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions -fexceptions -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions -fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s

 // CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
 // CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
@@ -43,6 +43,13 @@ struct HasNonTrivial {
   NonTrivial m;
 };

+struct __attribute__((trivial_abi)) CopyMoveDeleted {
+  CopyMoveDeleted(int);
+  CopyMoveDeleted(const CopyMoveDeleted &) = delete;
+  CopyMoveDeleted(CopyMoveDeleted &&) = delete;
+  int a;
+};
+
 // CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
 // CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SMALL]], %[[STRUCT_SMALL]]* %[[A]], i32 0, i32 0
@@ -237,3 +244,11 @@ void calleeExceptionLarge(Large, Large);
 void testExceptionLarge() {
   calleeExceptionLarge(Large(), Large());
 }
+
+// A class with deleted copy and move constructors can still be passed or
+// returned in registers if the class is annotated with trivial_abi.
+
+// CHECK: define i64 @_Z19testCopyMoveDeletedi(i32 %
+CopyMoveDeleted testCopyMoveDeleted(int a) {
+  return a;
+}


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

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


Re: r350920 - [Sema] Make canPassInRegisters return true if the CXXRecordDecl passed

2019-01-16 Thread Akira Hatanaka via cfe-commits


> On Jan 16, 2019, at 4:20 PM, John McCall via cfe-commits 
>  wrote:
> 
> 
> 
> On 16 Jan 2019, at 18:32, Richard Smith wrote:
> 
>> On Wed, 16 Jan 2019 at 09:10, John McCall via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>> 
>>> On 16 Jan 2019, at 9:13, Aaron Ballman wrote:
>>> 
 On Wed, Jan 16, 2019 at 1:57 AM Akira Hatanaka 
 wrote:
> 
> Yes, the behavior of the compiler doesn’t match what’s explained
> in the documentation anymore.
> 
> Please take a look at the attached patch, which updates the
> documentation.
 
 Patch mostly LGTM, but I did have one wording suggestion.
 
> diff --git a/include/clang/Basic/AttrDocs.td
> b/include/clang/Basic/AttrDocs.td
> index 5773a92c9c..ca3cfcf9b2 100644
> --- a/include/clang/Basic/AttrDocs.td
> +++ b/include/clang/Basic/AttrDocs.td
> @@ -2478,15 +2478,20 @@ def TrivialABIDocs : Documentation {
>   let Category = DocCatVariable;
>   let Content = [{
> The ``trivial_abi`` attribute can be applied to a C++ class, struct,
> or union.
> -It instructs the compiler to pass and return the type using the C
> ABI for the
> +``trivial_abi`` has the following effects:
> +
> +- It instructs the compiler to pass and return the type using the C
> ABI for the
> underlying type when the type would otherwise be considered
> non-trivial for the
> purpose of calls.
> -A class annotated with `trivial_abi` can have non-trivial
> destructors or copy/move constructors without automatically becoming
> non-trivial for the purposes of calls. For example:
> +- It makes the destructor and copy and move constructors of the
> class trivial
> +that would otherwise be considered non-trivial under the C++ ABI
> rules.
 
 How about: It makes the destructor, copy constructors, and move
 constructors of the class trivial even if they would otherwise be
 non-trivial under the C++ ABI rules.
>>> 
>>> Let's not say that it makes them trivial, because it doesn't.  It causes
>>> their immediate non-triviality to be ignored for the purposes of
>>> deciding
>>> whether the type can be passed in registers.
>>> 
>> 
>> Given the attribute now forces the type to be passed in registers, I think
>> it'd be more to the point to say that it makes the triviality of those
>> special members be ignored when deciding whether to pass a type with a
>> subobject of this type in registers.
> 
> Wait, it forces it to be passed in registers?  I thought the design
> was that it didn't override the non-trivial-abi-ness of subobjects;
> see all the discussion of trivially_relocatable.
> 

As stated in the documentation, trivial_abi on a class has no effect when one 
of its subobject is non-trivial for the purpose of calls. In the following 
example, clang (Sema::checkIllFormedTrivialABIStruct) issues a warning and 
drops the attribute on D since B is non-trivial:

struct B {
  B(const B &);
};

struct __attribute__((trivial_abi)) D {  // warning: 'trivial_abi' cannot be 
applied to ‘D' [-Wignored-attributes]
  B b;
};

If the attribute on the class survives the check by 
Sema::checkIllFormedTrivialABIStruct, the class is treated as being trivial for 
the purposes of calls.

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

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


r351911 - [Sema][ObjC] Check whether a DelayedDiagnosticPool has been pushed

2019-01-22 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Jan 22 16:55:48 2019
New Revision: 351911

URL: http://llvm.org/viewvc/llvm-project?rev=351911&view=rev
Log:
[Sema][ObjC] Check whether a DelayedDiagnosticPool has been pushed
before adding a delayed diagnostic to DelayedDiagnostics.

This fixes an assertion failure in Sema::DelayedDiagnostics::add that
was caused by the changes made in r141037.

rdar://problem/42782323

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjCXX/arc-0x.mm

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=351911&r1=351910&r2=351911&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jan 22 16:55:48 2019
@@ -12545,9 +12545,13 @@ ParmVarDecl *Sema::CheckParameter(DeclCo
 //   - otherwise, it's an error
 if (T->isArrayType()) {
   if (!T.isConstQualified()) {
-DelayedDiagnostics.add(
-sema::DelayedDiagnostic::makeForbiddenType(
-NameLoc, diag::err_arc_array_param_no_ownership, T, false));
+if (DelayedDiagnostics.shouldDelayDiagnostics())
+  DelayedDiagnostics.add(
+  sema::DelayedDiagnostic::makeForbiddenType(
+  NameLoc, diag::err_arc_array_param_no_ownership, T, false));
+else
+  Diag(NameLoc, diag::err_arc_array_param_no_ownership)
+  << TSInfo->getTypeLoc().getSourceRange();
   }
   lifetime = Qualifiers::OCL_ExplicitNone;
 } else {

Modified: cfe/trunk/test/SemaObjCXX/arc-0x.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-0x.mm?rev=351911&r1=351910&r2=351911&view=diff
==
--- cfe/trunk/test/SemaObjCXX/arc-0x.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-0x.mm Tue Jan 22 16:55:48 2019
@@ -101,3 +101,13 @@ namespace rdar12078752 {
 __autoreleasing auto o3 = o;
   }
 }
+
+namespace test_err_arc_array_param_no_ownership {
+  template 
+  void func(T a) {}
+
+  void test() {
+func([](A *a[]){}); // expected-error{{must explicitly describe intended 
ownership of an object array parameter}}
+func(^(A *a[]){}); // expected-error{{must explicitly describe intended 
ownership of an object array parameter}}
+  }
+}


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


r346209 - os_log: Minor code cleanups. NFC.

2018-11-05 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Nov  5 21:41:33 2018
New Revision: 346209

URL: http://llvm.org/viewvc/llvm-project?rev=346209&view=rev
Log:
os_log: Minor code cleanups. NFC.

Also, add a new test case and fix an incorrect comment.

Modified:
cfe/trunk/include/clang/AST/OSLog.h
cfe/trunk/lib/AST/OSLog.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/test/CodeGen/builtins.c

Modified: cfe/trunk/include/clang/AST/OSLog.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=346209&r1=346208&r2=346209&view=diff
==
--- cfe/trunk/include/clang/AST/OSLog.h (original)
+++ cfe/trunk/include/clang/AST/OSLog.h Mon Nov  5 21:41:33 2018
@@ -72,18 +72,17 @@ private:
 
 public:
   OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags)
-  : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {}
+  : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {
+assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic)) &&
+   "unexpected privacy flag");
+  }
 
   OSLogBufferItem(ASTContext &Ctx, CharUnits value, unsigned flags)
   : TheKind(CountKind), ConstValue(value),
 Size(Ctx.getTypeSizeInChars(Ctx.IntTy)), Flags(flags) {}
 
   unsigned char getDescriptorByte() const {
-unsigned char result = 0;
-if (getIsPrivate())
-  result |= IsPrivate;
-if (getIsPublic())
-  result |= IsPublic;
+unsigned char result = Flags;
 result |= ((unsigned)getKind()) << 4;
 return result;
   }
@@ -92,7 +91,6 @@ public:
 
   Kind getKind() const { return TheKind; }
   bool getIsPrivate() const { return (Flags & IsPrivate) != 0; }
-  bool getIsPublic() const { return (Flags & IsPublic) != 0; }
 
   const Expr *getExpr() const { return TheExpr; }
   CharUnits getConstValue() const { return ConstValue; }
@@ -120,11 +118,6 @@ public:
 Items, [](const OSLogBufferItem &Item) { return Item.getIsPrivate(); 
});
   }
 
-  bool hasPublicItems() const {
-return llvm::any_of(
-Items, [](const OSLogBufferItem &Item) { return Item.getIsPublic(); });
-  }
-
   bool hasNonScalar() const {
 return llvm::any_of(Items, [](const OSLogBufferItem &Item) {
   return Item.getKind() != OSLogBufferItem::ScalarKind;

Modified: cfe/trunk/lib/AST/OSLog.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OSLog.cpp?rev=346209&r1=346208&r2=346209&view=diff
==
--- cfe/trunk/lib/AST/OSLog.cpp (original)
+++ cfe/trunk/lib/AST/OSLog.cpp Mon Nov  5 21:41:33 2018
@@ -120,12 +120,11 @@ public:
   ArgsData.back().FieldWidth = Args[FS.getFieldWidth().getArgIndex()];
 }
 
-if (FS.isPrivate()) {
+if (FS.isPrivate())
   ArgsData.back().Flags |= OSLogBufferItem::IsPrivate;
-}
-if (FS.isPublic()) {
+else if (FS.isPublic())
   ArgsData.back().Flags |= OSLogBufferItem::IsPublic;
-}
+
 return true;
   }
 

Modified: cfe/trunk/lib/AST/PrintfFormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/PrintfFormatString.cpp?rev=346209&r1=346208&r2=346209&view=diff
==
--- cfe/trunk/lib/AST/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/AST/PrintfFormatString.cpp Mon Nov  5 21:41:33 2018
@@ -127,7 +127,7 @@ static PrintfSpecifierResult ParsePrintf
 
 do {
   StringRef Str(I, E - I);
-  std::string Match = "^[\t\n\v\f\r ]*(private|public)[\t\n\v\f\r ]*(,|})";
+  std::string Match = "^[[:space:]]*(private|public)[[:space:]]*(,|})";
   llvm::Regex R(Match);
   SmallVector Matches;
 

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=346209&r1=346208&r2=346209&view=diff
==
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Mon Nov  5 21:41:33 2018
@@ -440,7 +440,10 @@ void test_builtin_os_log(void *buf, int
   // CHECK: call void @__os_log_helper_1_2_1_8_34(
   __builtin_os_log_format(buf, "%{ xyz, public }s", "abc");
 
-  // The last privacy annotation in the string wins.
+  // CHECK: call void @__os_log_helper_1_3_1_8_33(
+  __builtin_os_log_format(buf, "%{ xyz, private }s", "abc");
+
+  // The strictest privacy annotation in the string wins.
 
   // CHECK: call void @__os_log_helper_1_3_1_8_33(
   __builtin_os_log_format(buf, "%{ private, public, private, public}s", "abc");


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


r346210 - os_log: Add a new privacy annotation "sensitive".

2018-11-05 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Nov  5 22:26:17 2018
New Revision: 346210

URL: http://llvm.org/viewvc/llvm-project?rev=346210&view=rev
Log:
os_log: Add a new privacy annotation "sensitive".

This is a stricter privacy annotation than "private", which will be used
for data that shouldn’t be logged to disk. For backward compatibility,
the "private" bit is set too.

rdar://problem/36755912

Modified:
cfe/trunk/include/clang/AST/FormatString.h
cfe/trunk/include/clang/AST/OSLog.h
cfe/trunk/lib/AST/OSLog.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/test/CodeGen/builtins.c

Modified: cfe/trunk/include/clang/AST/FormatString.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/FormatString.h?rev=346210&r1=346209&r2=346210&view=diff
==
--- cfe/trunk/include/clang/AST/FormatString.h (original)
+++ cfe/trunk/include/clang/AST/FormatString.h Mon Nov  5 22:26:17 2018
@@ -475,13 +475,15 @@ class PrintfSpecifier : public analyze_f
   OptionalFlag HasObjCTechnicalTerm; // '[tt]'
   OptionalFlag IsPrivate;// '{private}'
   OptionalFlag IsPublic; // '{public}'
+  OptionalFlag IsSensitive;  // '{sensitive}'
   OptionalAmount Precision;
 public:
   PrintfSpecifier()
   : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
 IsLeftJustified("-"), HasPlusPrefix("+"), HasSpacePrefix(" "),
 HasAlternativeForm("#"), HasLeadingZeroes("0"),
-HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public") {}
+HasObjCTechnicalTerm("tt"), IsPrivate("private"), IsPublic("public"),
+IsSensitive("sensitive") {}
 
   static PrintfSpecifier Parse(const char *beg, const char *end);
 
@@ -512,6 +514,9 @@ public:
   }
   void setIsPrivate(const char *position) { IsPrivate.setPosition(position); }
   void setIsPublic(const char *position) { IsPublic.setPosition(position); }
+  void setIsSensitive(const char *position) {
+IsSensitive.setPosition(position);
+  }
   void setUsesPositionalArg() { UsesPositionalArg = true; }
 
 // Methods for querying the format specifier.
@@ -551,6 +556,7 @@ public:
   const OptionalFlag &hasObjCTechnicalTerm() const { return 
HasObjCTechnicalTerm; }
   const OptionalFlag &isPrivate() const { return IsPrivate; }
   const OptionalFlag &isPublic() const { return IsPublic; }
+  const OptionalFlag &isSensitive() const { return IsSensitive; }
   bool usesPositionalArg() const { return UsesPositionalArg; }
 
   /// Changes the specifier and length according to a QualType, retaining any

Modified: cfe/trunk/include/clang/AST/OSLog.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=346210&r1=346209&r2=346210&view=diff
==
--- cfe/trunk/include/clang/AST/OSLog.h (original)
+++ cfe/trunk/include/clang/AST/OSLog.h Mon Nov  5 22:26:17 2018
@@ -60,7 +60,10 @@ public:
 IsPrivate = 0x1,
 
 // The item is marked "public" in the format string.
-IsPublic = 0x2
+IsPublic = 0x2,
+
+// The item is marked "sensitive" in the format string.
+IsSensitive = 0x4 | IsPrivate
   };
 
 private:
@@ -73,7 +76,8 @@ private:
 public:
   OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags)
   : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {
-assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic)) &&
+assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) ||
+(Flags == IsSensitive)) &&
"unexpected privacy flag");
   }
 

Modified: cfe/trunk/lib/AST/OSLog.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/OSLog.cpp?rev=346210&r1=346209&r2=346210&view=diff
==
--- cfe/trunk/lib/AST/OSLog.cpp (original)
+++ cfe/trunk/lib/AST/OSLog.cpp Mon Nov  5 22:26:17 2018
@@ -120,7 +120,9 @@ public:
   ArgsData.back().FieldWidth = Args[FS.getFieldWidth().getArgIndex()];
 }
 
-if (FS.isPrivate())
+if (FS.isSensitive())
+  ArgsData.back().Flags |= OSLogBufferItem::IsSensitive;
+else if (FS.isPrivate())
   ArgsData.back().Flags |= OSLogBufferItem::IsPrivate;
 else if (FS.isPublic())
   ArgsData.back().Flags |= OSLogBufferItem::IsPublic;

Modified: cfe/trunk/lib/AST/PrintfFormatString.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/PrintfFormatString.cpp?rev=346210&r1=346209&r2=346210&view=diff
==
--- cfe/trunk/lib/AST/PrintfFormatString.cpp (original)
+++ cfe/trunk/lib/AST/PrintfFormatString.cpp Mon Nov  5 22:26:17 2018
@@ -127,7 +127,8 @@ static PrintfSpecifierResult ParsePrintf
 
 do {
   StringRef Str(I, E - I);
-  std::string Match = "^[[:space:]]*(private|public)[[:space:]]*(,|})";
+  std::str

r346211 - os_log: Allow specifying mask type in format string.

2018-11-05 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Nov  5 23:05:14 2018
New Revision: 346211

URL: http://llvm.org/viewvc/llvm-project?rev=346211&view=rev
Log:
os_log: Allow specifying mask type in format string.

A mask type is a 1 to 8-byte string that follows the "mask." annotation
in the format string. This enables obfuscating data in the event the
provided privacy level isn't enabled.

rdar://problem/36756282

Modified:
cfe/trunk/include/clang/AST/FormatString.h
cfe/trunk/include/clang/AST/OSLog.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/OSLog.cpp
cfe/trunk/lib/AST/PrintfFormatString.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGen/builtins.c
cfe/trunk/test/SemaObjC/format-strings-oslog.m

Modified: cfe/trunk/include/clang/AST/FormatString.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/FormatString.h?rev=346211&r1=346210&r2=346211&view=diff
==
--- cfe/trunk/include/clang/AST/FormatString.h (original)
+++ cfe/trunk/include/clang/AST/FormatString.h Mon Nov  5 23:05:14 2018
@@ -477,6 +477,7 @@ class PrintfSpecifier : public analyze_f
   OptionalFlag IsPublic; // '{public}'
   OptionalFlag IsSensitive;  // '{sensitive}'
   OptionalAmount Precision;
+  StringRef MaskType;
 public:
   PrintfSpecifier()
   : FormatSpecifier(/* isPrintf = */ true), HasThousandsGrouping("'"),
@@ -559,6 +560,9 @@ public:
   const OptionalFlag &isSensitive() const { return IsSensitive; }
   bool usesPositionalArg() const { return UsesPositionalArg; }
 
+  StringRef getMaskType() const { return MaskType; }
+  void setMaskType(StringRef S) { MaskType = S; }
+
   /// Changes the specifier and length according to a QualType, retaining any
   /// flags or options. Returns true on success, or false when a conversion
   /// was not successful.
@@ -691,6 +695,9 @@ public:
 return true;
   }
 
+  /// Handle mask types whose sizes are not between one and eight bytes.
+  virtual void handleInvalidMaskType(StringRef MaskType) {}
+
 // Scanf-specific handlers.
 
   virtual bool HandleInvalidScanfConversionSpecifier(

Modified: cfe/trunk/include/clang/AST/OSLog.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OSLog.h?rev=346211&r1=346210&r2=346211&view=diff
==
--- cfe/trunk/include/clang/AST/OSLog.h (original)
+++ cfe/trunk/include/clang/AST/OSLog.h Mon Nov  5 23:05:14 2018
@@ -52,7 +52,10 @@ public:
 
 // The item is corresponding to the '%m' format specifier, no value is
 // populated in the buffer and the runtime is loading the errno value.
-ErrnoKind
+ErrnoKind,
+
+// The item is a mask type.
+MaskKind
   };
 
   enum {
@@ -72,10 +75,13 @@ private:
   CharUnits ConstValue;
   CharUnits Size; // size of the data, not including the header bytes
   unsigned Flags = 0;
+  StringRef MaskType;
 
 public:
-  OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags)
-  : TheKind(kind), TheExpr(expr), Size(size), Flags(flags) {
+  OSLogBufferItem(Kind kind, const Expr *expr, CharUnits size, unsigned flags,
+  StringRef maskType = StringRef())
+  : TheKind(kind), TheExpr(expr), Size(size), Flags(flags),
+MaskType(maskType) {
 assert(((Flags == 0) || (Flags == IsPrivate) || (Flags == IsPublic) ||
 (Flags == IsSensitive)) &&
"unexpected privacy flag");
@@ -99,6 +105,8 @@ public:
   const Expr *getExpr() const { return TheExpr; }
   CharUnits getConstValue() const { return ConstValue; }
   CharUnits size() const { return Size; }
+
+  StringRef getMaskType() const { return MaskType; }
 };
 
 class OSLogBufferLayout {
@@ -122,9 +130,10 @@ public:
 Items, [](const OSLogBufferItem &Item) { return Item.getIsPrivate(); 
});
   }
 
-  bool hasNonScalar() const {
+  bool hasNonScalarOrMask() const {
 return llvm::any_of(Items, [](const OSLogBufferItem &Item) {
-  return Item.getKind() != OSLogBufferItem::ScalarKind;
+  return Item.getKind() != OSLogBufferItem::ScalarKind ||
+ !Item.getMaskType().empty();
 });
   }
 
@@ -132,7 +141,7 @@ public:
 unsigned char result = 0;
 if (hasPrivateItems())
   result |= HasPrivateItems;
-if (hasNonScalar())
+if (hasNonScalarOrMask())
   result |= HasNonScalarItems;
 return result;
   }

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=346211&r1=346210&r2=346211&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Nov  5 23:05:14 
2018
@@ -7902,6 +7902,8 @@ def warn_for

r346212 - Cast to uint64_t instead of to unsigned.

2018-11-05 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Nov  5 23:12:28 2018
New Revision: 346212

URL: http://llvm.org/viewvc/llvm-project?rev=346212&view=rev
Log:
Cast to uint64_t instead of to unsigned.

This is a follow-up to r346211.

Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=346212&r1=346211&r2=346212&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Nov  5 23:12:28 2018
@@ -1171,7 +1171,7 @@ RValue CodeGenFunction::emitBuiltinOSLog
 if (Item.getKind() == analyze_os_log::OSLogBufferItem::MaskKind) {
   uint64_t Val = 0;
   for (unsigned I = 0, E = Item.getMaskType().size(); I < E; ++I)
-Val |= ((unsigned )Item.getMaskType()[I]) << I * 8;
+Val |= ((uint64_t)Item.getMaskType()[I]) << I * 8;
   ArgVal = llvm::Constant::getIntegerValue(Int64Ty, llvm::APInt(64, Val));
 } else if (const Expr *TheExpr = Item.getExpr()) {
   ArgVal = EmitScalarExpr(TheExpr, /*Ignore*/ false);


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


r355012 - Avoid needlessly copying a block to the heap when a block literal

2019-02-27 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Feb 27 10:17:16 2019
New Revision: 355012

URL: http://llvm.org/viewvc/llvm-project?rev=355012&view=rev
Log:
Avoid needlessly copying a block to the heap when a block literal
initializes a local auto variable or is assigned to a local auto
variable that is declared in the scope that introduced the block
literal.

rdar://problem/13289333

https://reviews.llvm.org/D58514

Added:
cfe/trunk/test/PCH/arc-blocks.mm
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenObjC/arc-block-copy-escape.m
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=355012&r1=355011&r2=355012&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Feb 27 10:17:16 2019
@@ -4008,6 +4008,13 @@ public:
   bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
   void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
 
+  bool canAvoidCopyToHeap() const {
+return BlockDeclBits.CanAvoidCopyToHeap;
+  }
+  void setCanAvoidCopyToHeap(bool B = true) {
+BlockDeclBits.CanAvoidCopyToHeap = B;
+  }
+
   bool capturesVariable(const VarDecl *var) const;
 
   void setCaptures(ASTContext &Context, ArrayRef Captures,

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=355012&r1=355011&r2=355012&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Feb 27 10:17:16 2019
@@ -1665,6 +1665,11 @@ class DeclContext {
 /// A bit that indicates this block is passed directly to a function as a
 /// non-escaping parameter.
 uint64_t DoesNotEscape : 1;
+
+/// A bit that indicates whether it's possible to avoid coying this block 
to
+/// the heap when it initializes or is assigned to a local variable with
+/// automatic storage.
+uint64_t CanAvoidCopyToHeap : 1;
   };
 
   /// Number of non-inherited bits in BlockDeclBitfields.

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=355012&r1=355011&r2=355012&view=diff
==
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Feb 27 10:17:16 2019
@@ -4265,6 +4265,7 @@ BlockDecl::BlockDecl(DeclContext *DC, So
   setBlockMissingReturnType(true);
   setIsConversionFromLambda(false);
   setDoesNotEscape(false);
+  setCanAvoidCopyToHeap(false);
 }
 
 void BlockDecl::setParams(ArrayRef NewParamInfo) {

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=355012&r1=355011&r2=355012&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Feb 27 10:17:16 2019
@@ -2871,6 +2871,7 @@ public:
   Result visit(const Expr *e);
   Result visitCastExpr(const CastExpr *e);
   Result visitPseudoObjectExpr(const PseudoObjectExpr *e);
+  Result visitBlockExpr(const BlockExpr *e);
   Result visitBinaryOperator(const BinaryOperator *e);
   Result visitBinAssign(const BinaryOperator *e);
   Result visitBinAssignUnsafeUnretained(const BinaryOperator *e);
@@ -2947,6 +2948,12 @@ ARCExprEmitter::visitPseudo
 }
 
 template 
+Result ARCExprEmitter::visitBlockExpr(const BlockExpr *e) {
+  // The default implementation just forwards the expression to visitExpr.
+  return asImpl().visitExpr(e);
+}
+
+template 
 Result ARCExprEmitter::visitCastExpr(const CastExpr *e) {
   switch (e->getCastKind()) {
 
@@ -3089,7 +3096,8 @@ Result ARCExprEmitter::visi
   // Look through pseudo-object expressions.
   } else if (const PseudoObjectExpr *pseudo = dyn_cast(e)) {
 return asImpl().visitPseudoObjectExpr(pseudo);
-  }
+  } else if (auto *be = dyn_cast(e))
+return asImpl().visitBlockExpr(be);
 
   return asImpl().visitExpr(e);
 }
@@ -3124,6 +3132,15 @@ struct ARCRetainExprEmitter :
 return TryEmitResult(result, true);
   }
 
+  TryEmitResult visitBlockExpr(const BlockExpr *e) {
+TryEmitResult result = visitExpr(e);
+// Avoid the block-retain if this is a block literal that doesn't need to 
be
+// copied to the heap.
+if (e->getBlockDecl()->canAvoidCopyToHeap())
+  result.setInt(true);
+re

r355017 - Add triples to the test I committed in r355012 to fix windows bots.

2019-02-27 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Feb 27 10:59:52 2019
New Revision: 355017

URL: http://llvm.org/viewvc/llvm-project?rev=355017&view=rev
Log:
Add triples to the test I committed in r355012 to fix windows bots.

Modified:
cfe/trunk/test/PCH/arc-blocks.mm

Modified: cfe/trunk/test/PCH/arc-blocks.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/arc-blocks.mm?rev=355017&r1=355016&r2=355017&view=diff
==
--- cfe/trunk/test/PCH/arc-blocks.mm (original)
+++ cfe/trunk/test/PCH/arc-blocks.mm Wed Feb 27 10:59:52 2019
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -fobjc-arc -fblocks -std=c++1y -emit-pch %s -o %t
-// RUN: %clang_cc1 -fobjc-arc -fblocks -std=c++1y -include-pch %t -emit-llvm 
-o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks 
-std=c++1y -emit-pch %s -o %t
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-arc -fblocks 
-std=c++1y -include-pch %t -emit-llvm -o - %s | FileCheck %s
 
 #ifndef HEADER_INCLUDED
 #define HEADER_INCLUDED


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


r355175 - [Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings by

2019-02-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Feb 28 22:43:20 2019
New Revision: 355175

URL: http://llvm.org/viewvc/llvm-project?rev=355175&view=rev
Log:
[Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings by
declaring an unavailable method in the subclass's extension that
overrides the designated initializer in the base class.

r243676 made changes to allow declaring the unavailable method in the
subclass interface to silence the warning. This commit additionally
allows declaring the unavailable method in the class extension.

rdar://problem/42731306

Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/attr-designated-init.m

Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=355175&r1=355174&r2=355175&view=diff
==
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Thu Feb 28 22:43:20 2019
@@ -2280,9 +2280,18 @@ void Sema::DiagnoseMissingDesignatedInit
  I = DesignatedInits.begin(), E = DesignatedInits.end(); I != E; ++I) {
 const ObjCMethodDecl *MD = *I;
 if (!InitSelSet.count(MD->getSelector())) {
+  // Don't emit a diagnostic if the overriding method in the subclass is
+  // marked as unavailable.
   bool Ignore = false;
   if (auto *IMD = IFD->getInstanceMethod(MD->getSelector())) {
 Ignore = IMD->isUnavailable();
+  } else {
+// Check the methods declared in the class extensions too.
+for (auto *Ext : IFD->visible_extensions())
+  if (auto *IMD = Ext->getInstanceMethod(MD->getSelector())) {
+Ignore = IMD->isUnavailable();
+break;
+  }
   }
   if (!Ignore) {
 Diag(ImplD->getLocation(),

Modified: cfe/trunk/test/SemaObjC/attr-designated-init.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/attr-designated-init.m?rev=355175&r1=355174&r2=355175&view=diff
==
--- cfe/trunk/test/SemaObjC/attr-designated-init.m (original)
+++ cfe/trunk/test/SemaObjC/attr-designated-init.m Thu Feb 28 22:43:20 2019
@@ -389,6 +389,19 @@ __attribute__((objc_root_class))
 }
 @end
 
+@interface SubTest1Ext : Test1
+-(instancetype)initWithRequiredParameter:(id)foo NS_DESIGNATED_INITIALIZER;
+@end
+// Mark 'init' as unavailable in the extension to silence warning.
+@interface SubTest1Ext()
+-(instancetype)init NS_UNAVAILABLE;
+@end
+@implementation SubTest1Ext
+-(instancetype)initWithRequiredParameter:(id)foo {
+  return [super init];
+}
+@end
+
 @interface Test2 : NSObject
 @end
 @interface SubTest2 : Test2


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


r355662 - [ObjC] Emit a boxed expression as a compile-time constant if the

2019-03-07 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar  7 20:45:37 2019
New Revision: 355662

URL: http://llvm.org/viewvc/llvm-project?rev=355662&view=rev
Log:
[ObjC] Emit a boxed expression as a compile-time constant if the
expression inside the parentheses is a valid UTF-8 string literal.

Previously clang emitted an expression like @("abc") as a message send
to stringWithUTF8String. This commit makes clang emit the boxed
expression as a compile-time constant instead.

This commit also has the effect of silencing the nullable-to-nonnull
conversion warning clang started emitting after r317727, which
originally motivated this commit (see https://oleb.net/2018/@keypath).

rdar://problem/42684601

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

Modified:
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/CodeGenObjC/boxing.m
cfe/trunk/test/SemaObjC/boxing-illegal.m
cfe/trunk/test/SemaObjC/objc-literal-sig.m
cfe/trunk/test/SemaObjC/transfer-boxed-string-nullability.m
cfe/trunk/test/SemaObjCXX/literals.mm

Modified: cfe/trunk/include/clang/AST/ExprObjC.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprObjC.h?rev=355662&r1=355661&r2=355662&view=diff
==
--- cfe/trunk/include/clang/AST/ExprObjC.h (original)
+++ cfe/trunk/include/clang/AST/ExprObjC.h Thu Mar  7 20:45:37 2019
@@ -138,6 +138,12 @@ public:
 return BoxingMethod;
   }
 
+  // Indicates whether this boxed expression can be emitted as a compile-time
+  // constant.
+  bool isExpressibleAsConstantInitializer() const {
+return !BoxingMethod && SubExpr;
+  }
+
   SourceLocation getAtLoc() const { return Range.getBegin(); }
 
   SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=355662&r1=355661&r2=355662&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Mar  7 20:45:37 2019
@@ -404,6 +404,7 @@ def ObjCPointerIntrospectPerformSelector
 def ObjCPointerIntrospect : DiagGroup<"deprecated-objc-pointer-introspection", 
[ObjCPointerIntrospectPerformSelector]>;
 def ObjCMultipleMethodNames : DiagGroup<"objc-multiple-method-names">;
 def ObjCFlexibleArray : DiagGroup<"objc-flexible-array">;
+def ObjCBoxing : DiagGroup<"objc-boxing">;
 def OpenCLUnsupportedRGBA: DiagGroup<"opencl-unsupported-rgba">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=355662&r1=355661&r2=355662&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Mar  7 20:45:37 
2019
@@ -918,6 +918,9 @@ def err_inconsistent_ivar_count : Error<
   "inconsistent number of instance variables specified">;
 def warn_undef_method_impl : Warning<"method definition for %0 not found">,
   InGroup>;
+def warn_objc_boxing_invalid_utf8_string : Warning<
+  "string is ill-formed as UTF-8 and will become a null %0 when boxed">,
+  InGroup;
 
 def warn_conflicting_overriding_ret_types : Warning<
   "conflicting return type in "

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=355662&r1=355661&r2=355662&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Mar  7 20:45:37 2019
@@ -1743,6 +1743,8 @@ static bool IsGlobalLValue(APValue::LVal
   case Expr::CXXTypeidExprClass:
   case Expr::CXXUuidofExprClass:
 return true;
+  case Expr::ObjCBoxedExprClass:
+return cast(E)->isExpressibleAsConstantInitializer();
   case Expr::CallExprClass:
 return IsStringLiteralCall(cast(E));
   // For GCC compatibility, &&label has static storage duration.
@@ -5794,6 +5796,8 @@ public:
   bool VisitObjCStringLiteral(const ObjCStringLiteral *E)
   { return Success(E); }
   bool VisitObjCBoxedExpr(const ObjCBoxedExpr *E) {
+if (E->isExpressibleAsConstantInitializer())
+  return Success(E);
 if (Info.noteFailure())
   EvaluateIgnoredValue(Info, E->getSubExpr());
 return

r355664 - Fix test case committed in r355662.

2019-03-07 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar  7 21:30:54 2019
New Revision: 355664

URL: http://llvm.org/viewvc/llvm-project?rev=355664&view=rev
Log:
Fix test case committed in r355662.

Build bots were failing because wide string literals don't have type
'int *' on some targets.

Modified:
cfe/trunk/test/SemaObjC/boxing-illegal.m

Modified: cfe/trunk/test/SemaObjC/boxing-illegal.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/boxing-illegal.m?rev=355664&r1=355663&r2=355664&view=diff
==
--- cfe/trunk/test/SemaObjC/boxing-illegal.m (original)
+++ cfe/trunk/test/SemaObjC/boxing-illegal.m Thu Mar  7 21:30:54 2019
@@ -66,7 +66,7 @@ void testStringLiteral() {
   s = @(u8"abc");
   s = @(u"abc"); // expected-error {{illegal type 'unsigned short *' used in a 
boxed expression}}
   s = @(U"abc"); // expected-error {{illegal type 'unsigned int *' used in a 
boxed expression}}
-  s = @(L"abc"); // expected-error {{illegal type 'int *' used in a boxed 
expression}}
+  s = @(L"abc"); // expected-error-re {{illegal type {{'int \*'|'unsigned 
short \*'}} used in a boxed expression}}
   s = @("\pabc"); // expected-error {{illegal type 'unsigned char *' used in a 
boxed expression}}
 }
 


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


r355700 - Use {{.*}} in test case to match the type of wide string literals.

2019-03-08 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Mar  8 07:20:12 2019
New Revision: 355700

URL: http://llvm.org/viewvc/llvm-project?rev=355700&view=rev
Log:
Use {{.*}} in test case to match the type of wide string literals.

The type of wide string literals varies depending on the target.

Modified:
cfe/trunk/test/SemaObjC/boxing-illegal.m

Modified: cfe/trunk/test/SemaObjC/boxing-illegal.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/boxing-illegal.m?rev=355700&r1=355699&r2=355700&view=diff
==
--- cfe/trunk/test/SemaObjC/boxing-illegal.m (original)
+++ cfe/trunk/test/SemaObjC/boxing-illegal.m Fri Mar  8 07:20:12 2019
@@ -66,7 +66,7 @@ void testStringLiteral() {
   s = @(u8"abc");
   s = @(u"abc"); // expected-error {{illegal type 'unsigned short *' used in a 
boxed expression}}
   s = @(U"abc"); // expected-error {{illegal type 'unsigned int *' used in a 
boxed expression}}
-  s = @(L"abc"); // expected-error-re {{illegal type {{'int \*'|'unsigned 
short \*'}} used in a boxed expression}}
+  s = @(L"abc"); // expected-error-re {{illegal type {{.*}} used in a boxed 
expression}}
   s = @("\pabc"); // expected-error {{illegal type 'unsigned char *' used in a 
boxed expression}}
 }
 


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


r356156 - [CodeGen][ObjC] Remove the leading 'l' from symbols for protocol

2019-03-14 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar 14 08:17:37 2019
New Revision: 356156

URL: http://llvm.org/viewvc/llvm-project?rev=356156&view=rev
Log:
[CodeGen][ObjC] Remove the leading 'l' from symbols for protocol
metadata and protocol list

The leading 'l' tells ld64 to remove the symbol name, which can make
debugging difficult.

rdar://problem/47256637

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
cfe/trunk/test/CodeGenObjC/hidden-visibility.m
cfe/trunk/test/CodeGenObjC/metadata-class-properties.m
cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m
cfe/trunk/test/CodeGenObjC/protocol-comdat.m
cfe/trunk/test/CodeGenObjC/protocol-in-extended-class.m
cfe/trunk/test/CodeGenObjC/protocols.m
cfe/trunk/test/CodeGenObjC/sections.m
cfe/trunk/test/CodeGenObjC/undefined-protocol2.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=356156&r1=356155&r2=356156&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu Mar 14 08:17:37 2019
@@ -6809,7 +6809,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
 // reference or not. At module finalization we add the empty
 // contents for protocols which were referenced but never defined.
 llvm::SmallString<64> Protocol;
-llvm::raw_svector_ostream(Protocol) << "\01l_OBJC_PROTOCOL_$_"
+llvm::raw_svector_ostream(Protocol) << "_OBJC_PROTOCOL_$_"
 << PD->getObjCRuntimeNameAsString();
 
 Entry = new llvm::GlobalVariable(CGM.getModule(), 
ObjCTypes.ProtocolnfABITy,
@@ -6901,7 +6901,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
   } else {
 llvm::SmallString<64> symbolName;
 llvm::raw_svector_ostream(symbolName)
-  << "\01l_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString();
+  << "_OBJC_PROTOCOL_$_" << PD->getObjCRuntimeNameAsString();
 
 Entry = values.finishAndCreateGlobal(symbolName, CGM.getPointerAlign(),
  /*constant*/ false,
@@ -6917,7 +6917,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
   // Use this protocol meta-data to build protocol list table in section
   // __DATA, __objc_protolist
   llvm::SmallString<64> ProtocolRef;
-  llvm::raw_svector_ostream(ProtocolRef) << "\01l_OBJC_LABEL_PROTOCOL_$_"
+  llvm::raw_svector_ostream(ProtocolRef) << "_OBJC_LABEL_PROTOCOL_$_"
  << PD->getObjCRuntimeNameAsString();
 
   llvm::GlobalVariable *PTGV =

Modified: cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m?rev=356156&r1=356155&r2=356156&view=diff
==
--- cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m (original)
+++ cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m Thu Mar 14 
08:17:37 2019
@@ -18,14 +18,14 @@ int main() {
   return 0;
 }
 
-// CHECK: @"\01l_OBJC_PROTOCOL_$_P0" = weak hidden global
-// CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P0" = weak hidden global
+// CHECK: @"_OBJC_PROTOCOL_$_P0" = weak hidden global
+// CHECK: @"_OBJC_LABEL_PROTOCOL_$_P0" = weak hidden global
 // CHECK: @"\01l_OBJC_CLASS_PROTOCOLS_$_A" = private global
 // CHECK: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P0" = weak hidden global
 
 // CHECK: llvm.used = appending global [3 x i8*]
-// CHECK-SAME: "\01l_OBJC_PROTOCOL_$_P0"
-// CHECK-SAME: "\01l_OBJC_LABEL_PROTOCOL_$_P0"
+// CHECK-SAME: "_OBJC_PROTOCOL_$_P0"
+// CHECK-SAME: "_OBJC_LABEL_PROTOCOL_$_P0"
 // CHECK-SAME: "\01l_OBJC_PROTOCOL_REFERENCE_$_P0"
 
 // CHECK: llvm.compiler.used = appending global [7 x i8*]

Modified: cfe/trunk/test/CodeGenObjC/hidden-visibility.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/hidden-visibility.m?rev=356156&r1=356155&r2=356156&view=diff
==
--- cfe/trunk/test/CodeGenObjC/hidden-visibility.m (original)
+++ cfe/trunk/test/CodeGenObjC/hidden-visibility.m Thu Mar 14 08:17:37 2019
@@ -2,7 +2,7 @@
 // CHECK: @"OBJC_IVAR_$_I.P" = hidden
 // CHECK: @"OBJC_CLASS_$_I" = hidden
 // CHECK: @"OBJC_METACLASS_$_I" = hidden
-// CHECK: @"\01l_OBJC_PROTOCOL_$_Prot0" = weak hidden
+// CHECK: @"_OBJC_PROTOCOL_$_Prot0" = weak hidden
 
 @interface I {
   int P;

Modified: cfe/trunk/test/CodeGenObjC/metadata-class-properties.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/metadata-class-properties.m?rev=356156&r1=356155&r2=356156&view=diff
==
--- cfe/trunk/test/CodeGenObjC/metadata-class-properties.m (original)
+++ cfe/trunk/test/Co

r356705 - [CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue

2019-03-21 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar 21 12:59:49 2019
New Revision: 356705

URL: http://llvm.org/viewvc/llvm-project?rev=356705&view=rev
Log:
[CodeGen][ObjC] Annotate calls to objc_retainAutoreleasedReturnValue
with notail on x86-64.

On x86-64, the epilogue code inserted before the tail jump blocks the
autoreleased return optimization.

rdar://problem/38675807

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

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/CodeGen/TargetInfo.h
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjC/arc-foreach.m
cfe/trunk/test/CodeGenObjC/arc-literals.m
cfe/trunk/test/CodeGenObjC/arc-precise-lifetime.m
cfe/trunk/test/CodeGenObjC/arc-property.m
cfe/trunk/test/CodeGenObjC/arc-related-result-type.m
cfe/trunk/test/CodeGenObjC/arc-ternary-op.m
cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m
cfe/trunk/test/CodeGenObjC/arc-with-atthrow.m
cfe/trunk/test/CodeGenObjC/arc.m
cfe/trunk/test/CodeGenObjC/objc-arc-container-subscripting.m
cfe/trunk/test/CodeGenObjC/os_log.m
cfe/trunk/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
cfe/trunk/test/CodeGenObjCXX/arc.mm
cfe/trunk/test/CodeGenObjCXX/inheriting-constructor-cleanup.mm
cfe/trunk/test/CodeGenObjCXX/literals.mm

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=356705&r1=356704&r2=356705&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Thu Mar 21 12:59:49 2019
@@ -1958,10 +1958,10 @@ static void setARCRuntimeFunctionLinkage
 /// Perform an operation having the signature
 ///   i8* (i8*)
 /// where a null input causes a no-op and returns null.
-static llvm::Value *
-emitARCValueOperation(CodeGenFunction &CGF, llvm::Value *value,
-  llvm::Type *returnType, llvm::Function *&fn,
-  llvm::Intrinsic::ID IntID, bool isTailCall = false) {
+static llvm::Value *emitARCValueOperation(
+CodeGenFunction &CGF, llvm::Value *value, llvm::Type *returnType,
+llvm::Function *&fn, llvm::Intrinsic::ID IntID,
+llvm::CallInst::TailCallKind tailKind = llvm::CallInst::TCK_None) {
   if (isa(value))
 return value;
 
@@ -1976,8 +1976,7 @@ emitARCValueOperation(CodeGenFunction &C
 
   // Call the function.
   llvm::CallInst *call = CGF.EmitNounwindRuntimeCall(fn, value);
-  if (isTailCall)
-call->setTailCall();
+  call->setTailCallKind(tailKind);
 
   // Cast the result back to the original type.
   return CGF.Builder.CreateBitCast(call, origType);
@@ -2187,9 +2186,15 @@ static void emitAutoreleasedReturnValueM
 llvm::Value *
 CodeGenFunction::EmitARCRetainAutoreleasedReturnValue(llvm::Value *value) {
   emitAutoreleasedReturnValueMarker(*this);
-  return emitARCValueOperation(*this, value, nullptr,
-  CGM.getObjCEntrypoints().objc_retainAutoreleasedReturnValue,
-   
llvm::Intrinsic::objc_retainAutoreleasedReturnValue);
+  llvm::CallInst::TailCallKind tailKind =
+  CGM.getTargetCodeGenInfo()
+  .shouldSuppressTailCallsOfRetainAutoreleasedReturnValue()
+  ? llvm::CallInst::TCK_NoTail
+  : llvm::CallInst::TCK_None;
+  return emitARCValueOperation(
+  *this, value, nullptr,
+  CGM.getObjCEntrypoints().objc_retainAutoreleasedReturnValue,
+  llvm::Intrinsic::objc_retainAutoreleasedReturnValue, tailKind);
 }
 
 /// Claim a possibly-autoreleased return value at +0.  This is only
@@ -2326,7 +2331,7 @@ CodeGenFunction::EmitARCAutoreleaseRetur
   return emitARCValueOperation(*this, value, nullptr,
 
CGM.getObjCEntrypoints().objc_autoreleaseReturnValue,
llvm::Intrinsic::objc_autoreleaseReturnValue,
-   /*isTailCall*/ true);
+   llvm::CallInst::TCK_Tail);
 }
 
 /// Do a fused retain/autorelease of the given object.
@@ -2336,7 +2341,7 @@ CodeGenFunction::EmitARCRetainAutoreleas
   return emitARCValueOperation(*this, value, nullptr,
  
CGM.getObjCEntrypoints().objc_retainAutoreleaseReturnValue,
  
llvm::Intrinsic::objc_retainAutoreleaseReturnValue,
-   /*isTailCall*/ true);
+   llvm::CallInst::TCK_Tail);
 }
 
 /// Do a fused retain/autorelease of the given object.

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=356705&r1=356704&r2=356705&view=diff
==
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Mar 21 12:59:49 2019
@@ -2268,6 +2268,12 @@ public:
 return static_cast(TargetCodeGenInfo::ge

r357228 - Fix typos and formatting. NFC.

2019-03-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar 28 17:23:17 2019
New Revision: 357228

URL: http://llvm.org/viewvc/llvm-project?rev=357228&view=rev
Log:
Fix typos and formatting. NFC.

Modified:
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp

Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=357228&r1=357227&r2=357228&view=diff
==
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Thu Mar 28 17:23:17 2019
@@ -83,23 +83,22 @@ struct CopyStructVisitor : StructVisitor
 
   template 
   void preVisit(QualType::PrimitiveCopyKind PCK, QualType FT,
-const FieldDecl *FD, CharUnits CurStructOffsset,
-Ts &&... Args) {
+const FieldDecl *FD, CharUnits CurStructOffset, Ts &&... Args) 
{
 if (PCK)
   asDerived().flushTrivialFields(std::forward(Args)...);
   }
 
   template 
   void visitWithKind(QualType::PrimitiveCopyKind PCK, QualType FT,
- const FieldDecl *FD, CharUnits CurStructOffsset,
+ const FieldDecl *FD, CharUnits CurStructOffset,
  Ts &&... Args) {
 if (const auto *AT = asDerived().getContext().getAsArrayType(FT)) {
   asDerived().visitArray(PCK, AT, FT.isVolatileQualified(), FD,
- CurStructOffsset, std::forward(Args)...);
+ CurStructOffset, std::forward(Args)...);
   return;
 }
 
-Super::visitWithKind(PCK, FT, FD, CurStructOffsset,
+Super::visitWithKind(PCK, FT, FD, CurStructOffset,
  std::forward(Args)...);
   }
 
@@ -253,11 +252,11 @@ struct GenBinaryFuncName : CopyStructVis
   }
 
   void visitVolatileTrivial(QualType FT, const FieldDecl *FD,
-CharUnits CurStackOffset) {
+CharUnits CurStructOffset) {
 // Because volatile fields can be bit-fields and are individually copied,
 // their offset and width are in bits.
 uint64_t OffsetInBits =
-this->Ctx.toBits(CurStackOffset) + this->getFieldOffsetInBits(FD);
+this->Ctx.toBits(CurStructOffset) + this->getFieldOffsetInBits(FD);
 this->appendStr("_tv" + llvm::to_string(OffsetInBits) + "w" +
 llvm::to_string(getFieldSize(FD, FT, this->Ctx)));
   }
@@ -286,8 +285,7 @@ struct GenDestructorFuncName : GenUnaryF
   using Super = DestructedTypeVisitor;
   GenDestructorFuncName(const char *Prefix, CharUnits DstAlignment,
 ASTContext &Ctx)
-  : GenUnaryFuncName(Prefix, DstAlignment,
-Ctx) {}
+  : GenUnaryFuncName(Prefix, DstAlignment, Ctx) {}
   void visitWithKind(QualType::DestructionKind DK, QualType FT,
  const FieldDecl *FD, CharUnits CurStructOffset) {
 if (const auto *AT = getContext().getAsArrayType(FT)) {
@@ -322,19 +320,19 @@ static const CGFunctionInfo &getFunction
 // functions.
 template  struct GenFuncBase {
   template 
-  void visitStruct(QualType FT, const FieldDecl *FD, CharUnits CurStackOffset,
+  void visitStruct(QualType FT, const FieldDecl *FD, CharUnits CurStructOffset,
std::array Addrs) {
 this->asDerived().callSpecialFunction(
-FT, CurStackOffset + asDerived().getFieldOffset(FD), Addrs);
+FT, CurStructOffset + asDerived().getFieldOffset(FD), Addrs);
   }
 
   template 
   void visitArray(FieldKind FK, const ArrayType *AT, bool IsVolatile,
-  const FieldDecl *FD, CharUnits CurStackOffset,
+  const FieldDecl *FD, CharUnits CurStructOffset,
   std::array Addrs) {
 // Non-volatile trivial fields are copied when flushTrivialFields is 
called.
 if (!FK)
-  return asDerived().visitTrivial(QualType(AT, 0), FD, CurStackOffset,
+  return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset,
   Addrs);
 
 asDerived().flushTrivialFields(Addrs);
@@ -345,7 +343,7 @@ template  struct GenFuncB
 QualType BaseEltQT;
 std::array StartAddrs = Addrs;
 for (unsigned I = 0; I < N; ++I)
-  StartAddrs[I] = getAddrWithOffset(Addrs[I], CurStackOffset, FD);
+  StartAddrs[I] = getAddrWithOffset(Addrs[I], CurStructOffset, FD);
 Address DstAddr = StartAddrs[DstIdx];
 llvm::Value *NumElts = CGF.emitArrayLength(AT, BaseEltQT, DstAddr);
 unsigned BaseEltSize = Ctx.getTypeSizeInChars(BaseEltQT).getQuantity();
@@ -585,15 +583,15 @@ struct GenDestructor : StructVisitor Addrs) {
+  CharUnits CurStructOffset, std::array Addrs) 
{
 CGF->destroyARCStrongImprecise(
-*CGF, getAddrWithOffset(Addrs[DstIdx], CurStackOffset, FD), QT);
+*CGF, getAddrWithOffset(Addrs[DstIdx], CurStructOffset, FD), QT);
   }
 
-  void visitARCWeak(QualType QT

r357229 - [CodeGen][ObjC] Adjust the addresses passed to calls to synthesized

2019-03-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Mar 28 17:23:20 2019
New Revision: 357229

URL: http://llvm.org/viewvc/llvm-project?rev=357229&view=rev
Log:
[CodeGen][ObjC] Adjust the addresses passed to calls to synthesized
copy/move constructor/assignment operator functions for non-trivial C
structs.

This commit fixes a bug where the offset of struct fields weren't being
taken into account when computing the addresses passed to calls to the
special functions.

For example, the copy constructor for S1 (__copy_constructor_8_8_s0_s8)
would pass the start addresses of the destination and source structs to
the call to S0's copy constructor (_copy_constructor_8_8_s0) without
adding the offset of field f1 to the addresses.

typedef struct {
  id f0;
  S0 f1;
} S1;

void test(S1 s1) {
  S1 t = s1;
}

rdar://problem/49400610

Modified:
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m

Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=357229&r1=357228&r2=357229&view=diff
==
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Thu Mar 28 17:23:20 2019
@@ -688,6 +688,8 @@ struct GenCopyConstructor : GenBinaryFun
 
   void callSpecialFunction(QualType FT, CharUnits Offset,
std::array Addrs) {
+Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
+Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
 CGF->callCStructCopyConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
 CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
   }
@@ -718,6 +720,8 @@ struct GenMoveConstructor : GenBinaryFun
 
   void callSpecialFunction(QualType FT, CharUnits Offset,
std::array Addrs) {
+Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
+Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
 CGF->callCStructMoveConstructor(CGF->MakeAddrLValue(Addrs[DstIdx], FT),
 CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
   }
@@ -746,6 +750,8 @@ struct GenCopyAssignment : GenBinaryFunc
 
   void callSpecialFunction(QualType FT, CharUnits Offset,
std::array Addrs) {
+Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
+Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
 CGF->callCStructCopyAssignmentOperator(
 CGF->MakeAddrLValue(Addrs[DstIdx], FT),
 CGF->MakeAddrLValue(Addrs[SrcIdx], FT));
@@ -780,6 +786,8 @@ struct GenMoveAssignment : GenBinaryFunc
 
   void callSpecialFunction(QualType FT, CharUnits Offset,
std::array Addrs) {
+Addrs[DstIdx] = getAddrWithOffset(Addrs[DstIdx], Offset);
+Addrs[SrcIdx] = getAddrWithOffset(Addrs[SrcIdx], Offset);
 CGF->callCStructMoveAssignmentOperator(
 CGF->MakeAddrLValue(Addrs[DstIdx], FT),
 CGF->MakeAddrLValue(Addrs[SrcIdx], FT));

Modified: cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m?rev=357229&r1=357228&r2=357229&view=diff
==
--- cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m (original)
+++ cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m Thu Mar 28 17:23:20 2019
@@ -30,6 +30,11 @@ typedef struct {
 } StrongOuter;
 
 typedef struct {
+  id f0;
+  Strong f1;
+} StrongOuter2;
+
+typedef struct {
   int f0;
   volatile id f1;
 } StrongVolatile;
@@ -81,6 +86,7 @@ typedef struct {
 
 StrongSmall getStrongSmall(void);
 StrongOuter getStrongOuter(void);
+StrongOuter2 getStrongOuter2(void);
 void calleeStrongSmall(StrongSmall);
 void func(Strong *);
 
@@ -289,6 +295,121 @@ void test_move_assignment_StrongOuter(St
   *p = getStrongOuter();
 }
 
+// CHECK: define linkonce_odr hidden void 
@__default_constructor_8_s0_S_s24(i8** %[[DST:.*]])
+// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
+// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
+// CHECK: %[[V1:.*]] = bitcast i8** %[[V0]] to i8*
+// CHECK: call void @llvm.memset.p0i8.i64(i8* align 8 %[[V1]], i8 0, i64 8, i1 
false)
+// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i8*
+// CHECK: %[[V3:.*]] = getelementptr inbounds i8, i8* %[[V2]], i64 8
+// CHECK: %[[V4:.*]] = bitcast i8* %[[V3]] to i8**
+// CHECK: call void @__default_constructor_8_s16(i8** %[[V4]])
+
+// CHECK: define linkonce_odr hidden void @__destructor_8_s0_S_s24(i8** 
%[[DST:.*]])
+// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
+// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
+// CHECK: call void @llvm.objc.storeStrong(i8** %[[V0]], i8* null)
+// CHECK: %[[

r358048 - [CodeGen][ObjC] Emit the retainRV marker as a module flag instead of

2019-04-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Apr  9 23:20:23 2019
New Revision: 358048

URL: http://llvm.org/viewvc/llvm-project?rev=358048&view=rev
Log:
[CodeGen][ObjC] Emit the retainRV marker as a module flag instead of
named metadata.

This fixes a bug where ARC contract wasn't inserting the retainRV
marker when LTO was enabled, which caused objects returned from a
function to be auto-released.

rdar://problem/49464214

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

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=358048&r1=358047&r2=358048&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Tue Apr  9 23:20:23 2019
@@ -2161,14 +2161,10 @@ static void emitAutoreleasedReturnValueM
 // with this marker yet, so leave a breadcrumb for the ARC
 // optimizer to pick up.
 } else {
-  llvm::NamedMDNode *metadata =
-CGF.CGM.getModule().getOrInsertNamedMetadata(
-"clang.arc.retainAutoreleasedReturnValueMarker");
-  assert(metadata->getNumOperands() <= 1);
-  if (metadata->getNumOperands() == 0) {
-auto &ctx = CGF.getLLVMContext();
-metadata->addOperand(llvm::MDNode::get(ctx,
- llvm::MDString::get(ctx, assembly)));
+  const char *markerKey = "clang.arc.retainAutoreleasedReturnValueMarker";
+  if (!CGF.CGM.getModule().getModuleFlag(markerKey)) {
+auto *str = llvm::MDString::get(CGF.getLLVMContext(), assembly);
+CGF.CGM.getModule().addModuleFlag(llvm::Module::Error, markerKey, str);
   }
 }
   }

Modified: cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m?rev=358048&r1=358047&r2=358048&view=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-unsafeclaim.m Tue Apr  9 23:20:23 2019
@@ -231,4 +231,5 @@ void test_cast_to_void() {
 
 // This is always at the end of the module.
 
-// CHECK-OPTIMIZED: !clang.arc.retainAutoreleasedReturnValueMarker = !{!0}
+// CHECK-OPTIMIZED: !llvm.module.flags = !{!0,
+// CHECK-OPTIMIZED: !0 = !{i32 1, 
!"clang.arc.retainAutoreleasedReturnValueMarker", !"mov{{.*}}marker for 
objc_retainAutoreleaseReturnValue"}


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


r358624 - [Sema][ObjC] Don't warn about an implicitly retained self if the

2019-04-17 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Apr 17 16:14:44 2019
New Revision: 358624

URL: http://llvm.org/viewvc/llvm-project?rev=358624&view=rev
Log:
[Sema][ObjC] Don't warn about an implicitly retained self if the
retaining block and all of the enclosing blocks are non-escaping.

If the block implicitly retaining self doesn't escape, there is no risk
of creating retain cycles, so clang shouldn't diagnose it and force
users to add self-> to silence the diagnostic.

Also, fix a bug where clang was failing to diagnose an implicitly
retained self inside a c++ lambda nested inside a block.

rdar://problem/25059955

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

Added:
cfe/trunk/test/SemaObjCXX/warn-implicit-self-in-block.mm
Removed:
cfe/trunk/test/SemaObjC/warn-implicit-self-in-block.m
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=358624&r1=358623&r2=358624&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Apr 17 16:14:44 2019
@@ -41,6 +41,7 @@ namespace clang {
 class ASTContext;
 class ASTMutationListener;
 class Attr;
+class BlockDecl;
 class DeclContext;
 class ExternalSourceSymbolAttr;
 class FunctionDecl;
@@ -1792,6 +1793,20 @@ public:
 
   bool isClosure() const { return getDeclKind() == Decl::Block; }
 
+  /// Return this DeclContext if it is a BlockDecl. Otherwise, return the
+  /// innermost enclosing BlockDecl or null if there are no enclosing blocks.
+  const BlockDecl *getInnermostBlockDecl() const {
+const DeclContext *Ctx = this;
+
+do {
+  if (Ctx->isClosure())
+return cast(Ctx);
+  Ctx = Ctx->getParent();
+} while (Ctx);
+
+return nullptr;
+  }
+
   bool isObjCContainer() const {
 switch (getDeclKind()) {
 case Decl::ObjCCategory:

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=358624&r1=358623&r2=358624&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Apr 17 16:14:44 2019
@@ -1213,6 +1213,11 @@ public:
   /// of -Wselector.
   llvm::MapVector ReferencedSelectors;
 
+  /// List of SourceLocations where 'self' is implicitly retained inside a
+  /// block.
+  llvm::SmallVector, 1>
+  ImplicitlyRetainedSelfLocs;
+
   /// Kinds of C++ special members.
   enum CXXSpecialMember {
 CXXDefaultConstructor,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=358624&r1=358623&r2=358624&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Apr 17 16:14:44 2019
@@ -13150,6 +13150,35 @@ private:
   bool IsLambda = false;
 };
 
+static void diagnoseImplicitlyRetainedSelf(Sema &S) {
+  llvm::DenseMap EscapeInfo;
+
+  auto IsOrNestedInEscapingBlock = [&](const BlockDecl *BD) {
+if (EscapeInfo.count(BD))
+  return EscapeInfo[BD];
+
+bool R = false;
+const BlockDecl *CurBD = BD;
+
+do {
+  R = !CurBD->doesNotEscape();
+  if (R)
+break;
+  CurBD = CurBD->getParent()->getInnermostBlockDecl();
+} while (CurBD);
+
+return EscapeInfo[BD] = R;
+  };
+
+  // If the location where 'self' is implicitly retained is inside a escaping
+  // block, emit a diagnostic.
+  for (const std::pair &P :
+   S.ImplicitlyRetainedSelfLocs)
+if (IsOrNestedInEscapingBlock(P.second))
+  S.Diag(P.first, diag::warn_implicitly_retains_self)
+  << FixItHint::CreateInsertion(P.first, "self->");
+}
+
 Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
 bool IsInstantiation) {
   FunctionDecl *FD = dcl ? dcl->getAsFunction() : nullptr;
@@ -13361,6 +13390,8 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
  diag::warn_objc_secondary_init_missing_init_call);
   getCurFunction()->ObjCWarnForNoInitDelegation = false;
 }
+
+diagnoseImplicitlyRetainedSelf(*this);
   } else {
 // Parsing the function declaration failed in some way. Pop the fake scope
 // we pushed on.

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=358624&r1=358623&r2=358624&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Apr 17 16:14:44 2019
@@ -359,6 +359,7 @@

r358627 - Move the implementation of getInnermostBlockDecl to the .cpp file to fix

2019-04-17 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Apr 17 17:00:16 2019
New Revision: 358627

URL: http://llvm.org/viewvc/llvm-project?rev=358627&view=rev
Log:
Move the implementation of getInnermostBlockDecl to the .cpp file to fix
failing bots.

Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=358627&r1=358626&r2=358627&view=diff
==
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Wed Apr 17 17:00:16 2019
@@ -1795,17 +1795,7 @@ public:
 
   /// Return this DeclContext if it is a BlockDecl. Otherwise, return the
   /// innermost enclosing BlockDecl or null if there are no enclosing blocks.
-  const BlockDecl *getInnermostBlockDecl() const {
-const DeclContext *Ctx = this;
-
-do {
-  if (Ctx->isClosure())
-return cast(Ctx);
-  Ctx = Ctx->getParent();
-} while (Ctx);
-
-return nullptr;
-  }
+  const BlockDecl *getInnermostBlockDecl() const;
 
   bool isObjCContainer() const {
 switch (getDeclKind()) {

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=358627&r1=358626&r2=358627&view=diff
==
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Wed Apr 17 17:00:16 2019
@@ -1057,6 +1057,18 @@ DeclContext *DeclContext::getLookupParen
   return getParent();
 }
 
+const BlockDecl *DeclContext::getInnermostBlockDecl() const {
+  const DeclContext *Ctx = this;
+
+  do {
+if (Ctx->isClosure())
+  return cast(Ctx);
+Ctx = Ctx->getParent();
+  } while (Ctx);
+
+  return nullptr;
+}
+
 bool DeclContext::isInlineNamespace() const {
   return isNamespace() &&
  cast(this)->isInline();


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


r359049 - Improve -Wuninitialized warning under ARC for block variables that are

2019-04-23 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Tue Apr 23 16:52:02 2019
New Revision: 359049

URL: http://llvm.org/viewvc/llvm-project?rev=359049&view=rev
Log:
Improve -Wuninitialized warning under ARC for block variables that are
recursively captured.

Under ARC, a block variable is zero-initialized when it is recursively
captured by the block literal initializer.

rdar://problem/11022762

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/FixIt/fixit-recursive-block.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=359049&r1=359048&r2=359049&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 23 16:52:02 
2019
@@ -1911,8 +1911,8 @@ def note_var_declared_here : Note<"varia
 def note_uninit_var_use : Note<
   "%select{uninitialized use occurs|variable is captured by block}0 here">;
 def warn_uninit_byref_blockvar_captured_by_block : Warning<
-  "block pointer variable %0 is uninitialized when captured by block">,
-  InGroup, DefaultIgnore;
+  "block pointer variable %0 is %select{uninitialized|null}1 when captured by "
+  "block">, InGroup, DefaultIgnore;
 def note_block_var_fixit_add_initialization : Note<
   "did you mean to use __block %0?">;
 def note_in_omitted_aggregate_initializer : Note<

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=359049&r1=359048&r2=359049&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Tue Apr 23 16:52:02 2019
@@ -998,7 +998,8 @@ static bool DiagnoseUninitializedUse(Sem
 if (VD->getType()->isBlockPointerType() && !VD->hasAttr())
   S.Diag(BE->getBeginLoc(),
  diag::warn_uninit_byref_blockvar_captured_by_block)
-  << VD->getDeclName();
+  << VD->getDeclName()
+  << VD->getType().getQualifiers().hasObjCLifetime();
 else
   DiagUninitUse(S, VD, Use, true);
   }

Modified: cfe/trunk/test/FixIt/fixit-recursive-block.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-recursive-block.c?rev=359049&r1=359048&r2=359049&view=diff
==
--- cfe/trunk/test/FixIt/fixit-recursive-block.c (original)
+++ cfe/trunk/test/FixIt/fixit-recursive-block.c Tue Apr 23 16:52:02 2019
@@ -1,12 +1,18 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10  -Wuninitialized -fblocks 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10  -Wuninitialized -fblocks 
-verify %s 
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10  -Wuninitialized -fblocks -x 
objective-c -fobjc-arc -DARC -verify %s
 
 // rdar://10817031
 
 int main() {
-void (^arc_fail)() = ^() {  // expected-warning {{block pointer variable 
'arc_fail' is uninitialized when captured by block}} \
-// expected-note {{did you mean to use __block 
'arc_fail'}}
+void (^arc_fail)() = ^() {
+#ifdef ARC
+// expected-warning@-2 {{block pointer variable 'arc_fail' is null when 
captured by block}}
+#else
+// expected-warning@-4 {{block pointer variable 'arc_fail' is uninitialized 
when captured by block}}
+#endif
+// expected-note@-6 {{did you mean to use __block 'arc_fail'}}
arc_fail(); // BOOM
 };
 }
-// CHECK: {7:12-7:12}:"__block "
+// CHECK: {8:12-8:12}:"__block "


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


r359761 - Fix typo in test case.

2019-05-02 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu May  2 00:38:07 2019
New Revision: 359761

URL: http://llvm.org/viewvc/llvm-project?rev=359761&view=rev
Log:
Fix typo in test case.

Modified:
cfe/trunk/test/CodeGenObjC/protocols.m

Modified: cfe/trunk/test/CodeGenObjC/protocols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/protocols.m?rev=359761&r1=359760&r2=359761&view=diff
==
--- cfe/trunk/test/CodeGenObjC/protocols.m (original)
+++ cfe/trunk/test/CodeGenObjC/protocols.m Thu May  2 00:38:07 2019
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | 
FileCheck %s
 
-// HECK: @[[PROTO_P1:"_OBJC_PROTOCOL_$_P1"]] = weak hidden
+// CHECK: @"\01l_OBJC_$_PROTOCOL_METHOD_TYPES_P1" = private global
 // CHECK: @[[PROTO_P1:"_OBJC_PROTOCOL_\$_P1"]] = weak hidden
 // CHECK: @[[LABEL_PROTO_P1:"_OBJC_LABEL_PROTOCOL_\$_P1"]] = weak hidden 
global %{{.*}}* @[[PROTO_P1]]
 // CHECK: @[[PROTO_P2:"_OBJC_PROTOCOL_\$_P2"]] = weak hidden


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


r359864 - [Sema][ObjC] Disable -Wunused-parameter for ObjC methods

2019-05-03 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri May  3 00:19:46 2019
New Revision: 359864

URL: http://llvm.org/viewvc/llvm-project?rev=359864&view=rev
Log:
[Sema][ObjC] Disable -Wunused-parameter for ObjC methods

The warning isn't very useful when the function is an ObjC method.

rdar://problem/41561853

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/method-unused-attribute.m
cfe/trunk/test/SemaObjC/unused.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=359864&r1=359863&r2=359864&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri May  3 00:19:46 2019
@@ -13353,8 +13353,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 assert(MD == getCurMethodDecl() && "Method parsing confused");
 MD->setBody(Body);
 if (!MD->isInvalidDecl()) {
-  if (!MD->hasSkippedBody())
-DiagnoseUnusedParameters(MD->parameters());
   DiagnoseSizeOfParametersAndReturnValue(MD->parameters(),
  MD->getReturnType(), MD);
 

Modified: cfe/trunk/test/SemaObjC/method-unused-attribute.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-unused-attribute.m?rev=359864&r1=359863&r2=359864&view=diff
==
--- cfe/trunk/test/SemaObjC/method-unused-attribute.m (original)
+++ cfe/trunk/test/SemaObjC/method-unused-attribute.m Fri May  3 00:19:46 2019
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1  -fsyntax-only -Wunused-parameter -verify 
-Wno-objc-root-class %s
 
+// -Wunused-parameter ignores ObjC method parameters that are unused.
+
+// expected-no-diagnostics
+
 @interface INTF
 - (void) correct_use_of_unused: (void *) notice : (id)another_arg;
 - (void) will_warn_unused_arg: (void *) notice : (id)warn_unused;
@@ -9,7 +13,7 @@
 @implementation INTF
 - (void) correct_use_of_unused: (void *)  __attribute__((unused)) notice : 
(id) __attribute__((unused)) newarg{
 }
-- (void) will_warn_unused_arg: (void *) __attribute__((unused))  notice : 
(id)warn_unused {}  // expected-warning {{unused parameter 'warn_unused'}}
-- (void) unused_attr_on_decl_ignored: (void *)  will_warn{}  // 
expected-warning {{unused parameter 'will_warn'}}
+- (void) will_warn_unused_arg: (void *) __attribute__((unused))  notice : 
(id)warn_unused {}
+- (void) unused_attr_on_decl_ignored: (void *)  will_warn{}
 @end
 

Modified: cfe/trunk/test/SemaObjC/unused.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/unused.m?rev=359864&r1=359863&r2=359864&view=diff
==
--- cfe/trunk/test/SemaObjC/unused.m (original)
+++ cfe/trunk/test/SemaObjC/unused.m Fri May  3 00:19:46 2019
@@ -33,7 +33,7 @@ void test2() {
   // expected-note {{introduce a parameter name to make 
'x' part of the selector}} \
   // expected-note {{or insert whitespace before ':' to 
use 'x' as parameter name and have an empty entry in the selector}}
 
-(int)y:  // expected-warning {{unused}}  expected-warning {{'y' used as the 
name of the previous parameter rather than as part of the selector}} \
+(int)y:  // expected-warning {{'y' used as the name of the previous parameter 
rather than as part of the selector}} \
  // expected-note {{introduce a parameter name to make 'y' part of the 
selector}} \
  // expected-note {{or insert whitespace before ':' to use 'y' as 
parameter name and have an empty entry in the selector}}
 (int) __attribute__((unused))z { return x; }


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


r360359 - [CodeGen][ObjC] Remove the leading `l_` from ObjC symbols and make

2019-05-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu May  9 10:43:52 2019
New Revision: 360359

URL: http://llvm.org/viewvc/llvm-project?rev=360359&view=rev
Log:
[CodeGen][ObjC] Remove the leading `l_` from ObjC symbols and make
private symbols in the __DATA segment internal.

This prevents the linker from removing the symbol names. Keeping the
symbols visible enables tools to collect various information about the
symbols, for example, tools that discover whether or not a symbol gets
dirtied.

rdar://problem/48887111

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/test/CodeGenObjC/arc.m
cfe/trunk/test/CodeGenObjC/boxing.m
cfe/trunk/test/CodeGenObjC/exceptions-asm-attribute.m
cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m
cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
cfe/trunk/test/CodeGenObjC/instance-method-metadata.m
cfe/trunk/test/CodeGenObjC/interface-layout-64.m
cfe/trunk/test/CodeGenObjC/metadata-class-properties.m
cfe/trunk/test/CodeGenObjC/metadata-symbols-32.m
cfe/trunk/test/CodeGenObjC/metadata-symbols-64.m
cfe/trunk/test/CodeGenObjC/metadata_symbols.m
cfe/trunk/test/CodeGenObjC/mrc-weak.m
cfe/trunk/test/CodeGenObjC/non-lazy-classes.m
cfe/trunk/test/CodeGenObjC/private-extern-selector-reference.m
cfe/trunk/test/CodeGenObjC/property-category-impl.m
cfe/trunk/test/CodeGenObjC/property-list-in-class.m
cfe/trunk/test/CodeGenObjC/property-list-in-extension.m
cfe/trunk/test/CodeGenObjC/protocol-comdat.m
cfe/trunk/test/CodeGenObjC/protocols.m
cfe/trunk/test/CodeGenObjC/section-name.m
cfe/trunk/test/CodeGenObjC/sections.m
cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm
cfe/trunk/test/CodeGenObjCXX/mrc-weak.mm

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=360359&r1=360358&r2=360359&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Thu May  9 10:43:52 2019
@@ -1809,6 +1809,28 @@ static bool hasObjCExceptionAttribute(AS
   return false;
 }
 
+static llvm::GlobalValue::LinkageTypes
+getLinkageTypeForObjCMetadata(CodeGenModule &CGM, StringRef Section) {
+  if (CGM.getTriple().isOSBinFormatMachO() &&
+  (Section.empty() || Section.startswith("__DATA")))
+return llvm::GlobalValue::InternalLinkage;
+  return llvm::GlobalValue::PrivateLinkage;
+}
+
+/// A helper function to create an internal or private global variable.
+static llvm::GlobalVariable *
+finishAndCreateGlobal(ConstantInitBuilder::StructBuilder &Builder,
+ const llvm::Twine &Name, CodeGenModule &CGM) {
+  std::string SectionName;
+  if (CGM.getTriple().isOSBinFormatMachO())
+SectionName = "__DATA, __objc_const";
+  auto *GV = Builder.finishAndCreateGlobal(
+  Name, CGM.getPointerAlign(), /*constant*/ false,
+  getLinkageTypeForObjCMetadata(CGM, SectionName));
+  GV->setSection(SectionName);
+  return GV;
+}
+
 /* *** CGObjCMac Public Interface *** */
 
 CGObjCMac::CGObjCMac(CodeGen::CodeGenModule &cgm) : CGObjCCommonMac(cgm),
@@ -3105,7 +3127,7 @@ CGObjCMac::EmitProtocolExtension(const O
   values.add(classProperties);
 
   // No special section, but goes in llvm.used
-  return CreateMetadataVar("\01l_OBJC_PROTOCOLEXT_" + PD->getName(), values,
+  return CreateMetadataVar("_OBJC_PROTOCOLEXT_" + PD->getName(), values,
StringRef(), CGM.getPointerAlign(), true);
 }
 
@@ -3338,9 +3360,9 @@ void CGObjCMac::GenerateCategory(const O
 
   // If there is no category @interface then there can be no properties.
   if (Category) {
-Values.add(EmitPropertyList("\01l_OBJC_$_PROP_LIST_" + ExtName.str(),
+Values.add(EmitPropertyList("_OBJC_$_PROP_LIST_" + ExtName.str(),
 OCD, Category, ObjCTypes, false));
-Values.add(EmitPropertyList("\01l_OBJC_$_CLASS_PROP_LIST_" + ExtName.str(),
+Values.add(EmitPropertyList("_OBJC_$_CLASS_PROP_LIST_" + ExtName.str(),
 OCD, Category, ObjCTypes, true));
   } else {
 Values.addNullPointer(ObjCTypes.PropertyListPtrTy);
@@ -3686,8 +3708,8 @@ CGObjCMac::EmitClassExtension(const ObjC
 
   // Properties.
   llvm::Constant *propertyList =
-EmitPropertyList((isMetaclass ? Twine("\01l_OBJC_$_CLASS_PROP_LIST_")
-  : Twine("\01l_OBJC_$_PROP_LIST_"))
+EmitPropertyList((isMetaclass ? Twine("_OBJC_$_CLASS_PROP_LIST_")
+  : Twine("_OBJC_$_PROP_LIST_"))
 + ID->getName(),
  ID, ID->getClassInterface(), ObjCTypes, isMetaclass);
 
@@ -3935,9 +3957,10 @@ llvm::GlobalVariable *CGObjCCommonMac::C
  StringRef Section,
  

r360361 - Specify ObjC runtime to fix the tests I committed in r360359 that are

2019-05-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu May  9 11:05:17 2019
New Revision: 360361

URL: http://llvm.org/viewvc/llvm-project?rev=360361&view=rev
Log:
Specify ObjC runtime to fix the tests I committed in r360359 that are
failing.

Modified:
cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m
cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm

Modified: cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m?rev=360361&r1=360360&r2=360361&view=diff
==
--- cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m (original)
+++ cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m Thu May  9 
11:05:17 2019
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | 
FileCheck -check-prefix=FRAGILE %s
-// RUN: %clang_cc1 -o - -emit-llvm %s | FileCheck -check-prefix=NONFRAGILE %s
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -o - -emit-llvm %s | FileCheck 
-check-prefix=NONFRAGILE %s
 
 // NONFRAGILE: @OBJC_SELECTOR_REFERENCES_ = internal externally_initialized 
global
 // FRAGILE: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global

Modified: cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m?rev=360361&r1=360360&r2=360361&view=diff
==
--- cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m (original)
+++ cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m Thu May  9 
11:05:17 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -x objective-c %s -o - | FileCheck %s
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -emit-llvm -x objective-c %s -o 
- | FileCheck %s
 // rdar://16203115
 
 @interface NSObject @end

Modified: cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm?rev=360361&r1=360360&r2=360361&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm Thu May  9 
11:05:17 2019
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | 
FileCheck -check-prefix=FRAGILE %s
-// RUN: %clang_cc1 -o - -emit-llvm %s | FileCheck -check-prefix=NONFRAGILE %s
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -o - -emit-llvm %s | FileCheck 
-check-prefix=NONFRAGILE %s
 
 // NONFRAGILE: @OBJC_SELECTOR_REFERENCES_ = internal externally_initialized 
global
 // FRAGILE: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global


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


r360363 - Specify target triple to fix the tests I committed in r360359 that are

2019-05-09 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu May  9 11:32:16 2019
New Revision: 360363

URL: http://llvm.org/viewvc/llvm-project?rev=360363&view=rev
Log:
Specify target triple to fix the tests I committed in r360359 that are
still failing.

Modified:
cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m
cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm

Modified: cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m?rev=360363&r1=360362&r2=360363&view=diff
==
--- cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m (original)
+++ cfe/trunk/test/CodeGenObjC/externally-initialized-selectors.m Thu May  9 
11:32:16 2019
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | 
FileCheck -check-prefix=FRAGILE %s
-// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -o - -emit-llvm %s | FileCheck 
-check-prefix=NONFRAGILE %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-10.14 
-o - -emit-llvm %s | FileCheck -check-prefix=NONFRAGILE %s
 
 // NONFRAGILE: @OBJC_SELECTOR_REFERENCES_ = internal externally_initialized 
global
 // FRAGILE: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global

Modified: cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m?rev=360363&r1=360362&r2=360363&view=diff
==
--- cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m (original)
+++ cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m Thu May  9 
11:32:16 2019
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -emit-llvm -x objective-c %s -o 
- | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-10.14 
-emit-llvm -x objective-c %s -o - | FileCheck %s
 // rdar://16203115
 
 @interface NSObject @end

Modified: cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm?rev=360363&r1=360362&r2=360363&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/externally-initialized-selectors.mm Thu May  9 
11:32:16 2019
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.5 -o - -emit-llvm %s | 
FileCheck -check-prefix=FRAGILE %s
-// RUN: %clang_cc1 -fobjc-runtime=macosx-10.14 -o - -emit-llvm %s | FileCheck 
-check-prefix=NONFRAGILE %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-10.14 
-o - -emit-llvm %s | FileCheck -check-prefix=NONFRAGILE %s
 
 // NONFRAGILE: @OBJC_SELECTOR_REFERENCES_ = internal externally_initialized 
global
 // FRAGILE: @OBJC_SELECTOR_REFERENCES_ = private externally_initialized global


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


r343518 - Distinguish `__block` variables that are captured by escaping blocks

2018-10-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Oct  1 11:50:14 2018
New Revision: 343518

URL: http://llvm.org/viewvc/llvm-project?rev=343518&view=rev
Log:
Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

This reapplies r341754, which was reverted in r341757 because it broke a
couple of bots. r341754 was calling markEscapingByrefs after the call to
PopFunctionScopeInfo, which caused the popped function scope to be
cleared out when the following code was compiled, for example:

$ cat test.m
struct A {
  id data[10];
};

void foo() {
  __block A v;
  ^{ (void)v; };
}

This commit calls markEscapingByrefs before calling PopFunctionScopeInfo
to prevent that from happening.

rdar://problem/39352313

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

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/block-byref-aggr.c
cfe/trunk/test/CodeGen/blocks-seq.c
cfe/trunk/test/CodeGen/exceptions.c
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/block-capture.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/noescape.cpp
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/arc-unoptimized-byref-var.m
cfe/trunk/test/CodeGenObjC/blocks-1.m
cfe/trunk/test/CodeGenObjC/noescape.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/SemaObjCXX/blocks.mm
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=343518&r1=343517&r2=343518&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Oct  1 11:50:14 2018
@@ -965,6 +965,8 @@ protected:
 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
 /// something else.
 unsigned ImplicitParamKind : 3;
+
+unsigned EscapingByref : 1;
   };
 
   union {
@@ -1407,6 +1409,19 @@ public:
 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
   }
 
+  /// Indicates the capture is a __block variable that is captured by a block
+  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
+  /// returns false).
+  bool isEscapingByref() const;
+
+  /// Indicates the capture is a __block variable that is never captured by an
+  /// escaping block.
+  bool isNonEscapingByref() const;
+
+  void setEscapingByref() {
+NonParmVarDeclBits.EscapingByref = true;
+  }
+
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;
@@ -3865,6 +3880,14 @@ public:
 /// variable.
 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
 
+bool isEscapingByref() const {
+  return getVariable()->isEscapingByref();
+}
+
+bool isNonEscapingByref() const {
+  return getVariable()->isNonEscapingByref();
+}
+
 /// Whether this is a nested capture, i.e. the variable captured
 /// is not from outside the immediately enclosing function/block.
 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=343518&r1=343517&r2=343518&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Mon Oct  1 11:50:14 2018
@@ -31,6 +31,7 @@
 #in

r343531 - Revert r343518.

2018-10-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Oct  1 13:29:34 2018
New Revision: 343531

URL: http://llvm.org/viewvc/llvm-project?rev=343531&view=rev
Log:
Revert r343518.

Bots are still failing.

http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/24420
http://lab.llvm.org:8011/builders/llvm-clang-x86_64-expensive-checks-win/builds/12958

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/block-byref-aggr.c
cfe/trunk/test/CodeGen/blocks-seq.c
cfe/trunk/test/CodeGen/exceptions.c
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/block-capture.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/noescape.cpp
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/arc-unoptimized-byref-var.m
cfe/trunk/test/CodeGenObjC/blocks-1.m
cfe/trunk/test/CodeGenObjC/noescape.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/SemaObjCXX/blocks.mm
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=343531&r1=343530&r2=343531&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Oct  1 13:29:34 2018
@@ -965,8 +965,6 @@ protected:
 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
 /// something else.
 unsigned ImplicitParamKind : 3;
-
-unsigned EscapingByref : 1;
   };
 
   union {
@@ -1409,19 +1407,6 @@ public:
 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
   }
 
-  /// Indicates the capture is a __block variable that is captured by a block
-  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
-  /// returns false).
-  bool isEscapingByref() const;
-
-  /// Indicates the capture is a __block variable that is never captured by an
-  /// escaping block.
-  bool isNonEscapingByref() const;
-
-  void setEscapingByref() {
-NonParmVarDeclBits.EscapingByref = true;
-  }
-
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;
@@ -3880,14 +3865,6 @@ public:
 /// variable.
 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
 
-bool isEscapingByref() const {
-  return getVariable()->isEscapingByref();
-}
-
-bool isNonEscapingByref() const {
-  return getVariable()->isNonEscapingByref();
-}
-
 /// Whether this is a nested capture, i.e. the variable captured
 /// is not from outside the immediately enclosing function/block.
 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=343531&r1=343530&r2=343531&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Mon Oct  1 13:29:34 2018
@@ -31,7 +31,6 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
@@ -203,12 +202,6 @@ public:
   /// function.
   SmallVector CompoundScopes;
 
-  /// The set of blocks that are introduced in this function.
-  llvm::SmallPtrSet Blocks;
-
-  /// The set of __block variables that are introduced in this function.
-  llvm::TinyPtrVector ByrefBlockVars;
-
   /// A list of PartialDiagnostics created but delayed within the
   /// current function scope.  These diagnostics are vetted for reachability
   /// prior to being emitted.
@@ -433,16 +426,6 @@ public:
   (HasBranchProtectedScope && HasBranchIntoScope));
   }
 
-  // Add a block introduced in this function.
-  void addBlock(const BlockDecl *BD) {
-Blocks.insert(BD);
-  }
-
-  // Add a __block variable introduced in this function.
-  void addByrefBlockVar(VarDecl *VD) {
-ByrefBlockVars.push_back(VD);
-  }
-
   bool isCoroutine() const { return !FirstCoroutineStmtLoc.

r343542 - Distinguish `__block` variables that are captured by escaping blocks

2018-10-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Oct  1 14:51:28 2018
New Revision: 343542

URL: http://llvm.org/viewvc/llvm-project?rev=343542&view=rev
Log:
Distinguish `__block` variables that are captured by escaping blocks
from those that aren't.

This patch changes the way __block variables that aren't captured by
escaping blocks are handled:

- Since non-escaping blocks on the stack never get copied to the heap
  (see https://reviews.llvm.org/D49303), Sema shouldn't error out when
  the type of a non-escaping __block variable doesn't have an accessible
  copy constructor.

- IRGen doesn't have to use the specialized byref structure (see
  https://clang.llvm.org/docs/Block-ABI-Apple.html#id8) for a
  non-escaping __block variable anymore. Instead IRGen can emit the
  variable as a normal variable and copy the reference to the block
  literal. Byref copy/dispose helpers aren't needed either.

This reapplies r343518 after fixing a use-after-free bug in function
Sema::ActOnBlockStmtExpr where the BlockScopeInfo was dereferenced after
it was popped and deleted.

rdar://problem/39352313

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

Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Sema/ScopeInfo.cpp
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGen/block-byref-aggr.c
cfe/trunk/test/CodeGen/blocks-seq.c
cfe/trunk/test/CodeGen/exceptions.c
cfe/trunk/test/CodeGen/personality.c
cfe/trunk/test/CodeGenCXX/block-capture.cpp
cfe/trunk/test/CodeGenCXX/blocks.cpp
cfe/trunk/test/CodeGenCXX/debug-info-blocks.cpp
cfe/trunk/test/CodeGenCXX/noescape.cpp
cfe/trunk/test/CodeGenObjC/arc-no-arc-exceptions.m
cfe/trunk/test/CodeGenObjC/arc-unoptimized-byref-var.m
cfe/trunk/test/CodeGenObjC/blocks-1.m
cfe/trunk/test/CodeGenObjC/noescape.m
cfe/trunk/test/CodeGenObjCXX/arc-blocks.mm
cfe/trunk/test/PCH/block-helpers.cpp
cfe/trunk/test/SemaObjCXX/blocks.mm
cfe/trunk/test/SemaObjCXX/noescape.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=343542&r1=343541&r2=343542&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Mon Oct  1 14:51:28 2018
@@ -965,6 +965,8 @@ protected:
 /// Defines kind of the ImplicitParamDecl: 'this', 'self', 'vtt', '_cmd' or
 /// something else.
 unsigned ImplicitParamKind : 3;
+
+unsigned EscapingByref : 1;
   };
 
   union {
@@ -1407,6 +1409,19 @@ public:
 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
   }
 
+  /// Indicates the capture is a __block variable that is captured by a block
+  /// that can potentially escape (a block for which BlockDecl::doesNotEscape
+  /// returns false).
+  bool isEscapingByref() const;
+
+  /// Indicates the capture is a __block variable that is never captured by an
+  /// escaping block.
+  bool isNonEscapingByref() const;
+
+  void setEscapingByref() {
+NonParmVarDeclBits.EscapingByref = true;
+  }
+
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;
@@ -3865,6 +3880,14 @@ public:
 /// variable.
 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
 
+bool isEscapingByref() const {
+  return getVariable()->isEscapingByref();
+}
+
+bool isNonEscapingByref() const {
+  return getVariable()->isNonEscapingByref();
+}
+
 /// Whether this is a nested capture, i.e. the variable captured
 /// is not from outside the immediately enclosing function/block.
 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }

Modified: cfe/trunk/include/clang/Sema/ScopeInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ScopeInfo.h?rev=343542&r1=343541&r2=343542&view=diff
==
--- cfe/trunk/include/clang/Sema/ScopeInfo.h (original)
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h Mon Oct  1 14:51:28 2018
@@ -31,6 +31,7 @@
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/TinyPtrVector.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include 
@@ -202,6 +203,12 @@ public:
   /// function.
   SmallVector CompoundScopes;
 
+

r343556 - [CodeGen] Before entering the loop that copies a non-trivial array field

2018-10-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Mon Oct  1 18:00:44 2018
New Revision: 343556

URL: http://llvm.org/viewvc/llvm-project?rev=343556&view=rev
Log:
[CodeGen] Before entering the loop that copies a non-trivial array field
of a non-trivial C struct, copy the preceding trivial fields that
haven't been copied.

This commit fixes a bug where the instructions used to copy the
preceding trivial fields were emitted inside the loop body.

rdar://problem/44185064

Modified:
cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m

Modified: cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp?rev=343556&r1=343555&r2=343556&view=diff
==
--- cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGNonTrivialStruct.cpp Mon Oct  1 18:00:44 2018
@@ -187,6 +187,7 @@ template  struct GenFuncN
 if (!FK)
   return asDerived().visitTrivial(QualType(AT, 0), FD, CurStructOffset);
 
+asDerived().flushTrivialFields();
 CharUnits FieldOffset = CurStructOffset + asDerived().getFieldOffset(FD);
 ASTContext &Ctx = asDerived().getContext();
 const ConstantArrayType *CAT = cast(AT);
@@ -336,6 +337,7 @@ template  struct GenFuncB
   return asDerived().visitTrivial(QualType(AT, 0), FD, CurStackOffset,
   Addrs);
 
+asDerived().flushTrivialFields(Addrs);
 CodeGenFunction &CGF = *this->CGF;
 ASTContext &Ctx = CGF.getContext();
 

Modified: cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m?rev=343556&r1=343555&r2=343556&view=diff
==
--- cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m (original)
+++ cfe/trunk/test/CodeGenObjC/strong-in-c-struct.m Mon Oct  1 18:00:44 2018
@@ -485,8 +485,39 @@ void test_constructor_destructor_StructA
   StructArray t;
 }
 
+// Test that StructArray's field 'd' is copied before entering the loop.
+
+// CHECK: define linkonce_odr hidden void 
@__copy_constructor_8_8_t0w8_AB8s24n4_t8w16_s24_AE(i8** %[[DST:.*]], i8** 
%[[SRC:.*]])
+// CHECK: entry:
+// CHECK: %[[DST_ADDR:.*]] = alloca i8**, align 8
+// CHECK: %[[SRC_ADDR:.*]] = alloca i8**, align 8
+// CHECK: store i8** %[[DST]], i8*** %[[DST_ADDR]], align 8
+// CHECK: store i8** %[[SRC]], i8*** %[[SRC_ADDR]], align 8
+// CHECK: %[[V0:.*]] = load i8**, i8*** %[[DST_ADDR]], align 8
+// CHECK: %[[V1:.*]] = load i8**, i8*** %[[SRC_ADDR]], align 8
+// CHECK: %[[V2:.*]] = bitcast i8** %[[V0]] to i64*
+// CHECK: %[[V3:.*]] = bitcast i8** %[[V1]] to i64*
+// CHECK: %[[V4:.*]] = load i64, i64* %[[V3]], align 8
+// CHECK: store i64 %[[V4]], i64* %[[V2]], align 8
+
+// CHECK: phi i8**
+// CHECK: phi i8**
+
+// CHECK: phi i8**
+// CHECK: phi i8**
+
+// CHECK-NOT: load i64, i64* %
+// CHECK-NOT: store i64 %
+// CHECK: call void @__copy_constructor_8_8_t0w16_s16(
+
+void test_copy_constructor_StructArray(StructArray a) {
+  StructArray t = a;
+}
+
 // Check that IRGen copies the 9-bit bitfield emitting i16 load and store.
 
+// CHECK: define void @test_copy_constructor_Bitfield0(
+
 // CHECK: define linkonce_odr hidden void @__copy_constructor_8_8_s0_t8w2(
 // CHECK: %[[V4:.*]] = bitcast i8** %{{.*}} to i8*
 // CHECK: %[[V5:.*]] = getelementptr inbounds i8, i8* %[[V4]], i64 8


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


Re: r350920 - [Sema] Make canPassInRegisters return true if the CXXRecordDecl passed

2019-01-31 Thread Akira Hatanaka via cfe-commits
Would it be better if we disallowed trivial_abi if the class’ copy and move 
destructors were all deleted (and revert r350920)? I think that would make it 
easier to reason about when you are allowed to use trivial_abi and what effect 
the attribute has (which is to override the trivialness for the purpose of 
calls).

Sorry for my late reply. It took a while to understand that the patch I 
committed might not be the right way to fix the problem.

> On Jan 16, 2019, at 8:37 PM, John McCall via cfe-commits 
>  wrote:
> 
> On 16 Jan 2019, at 20:03, Richard Smith wrote:
> 
>> On Wed, 16 Jan 2019 at 16:20, John McCall via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>> 
>>> On 16 Jan 2019, at 18:32, Richard Smith wrote:
>>> 
 On Wed, 16 Jan 2019 at 09:10, John McCall via cfe-commits <
 cfe-commits@lists.llvm.org> wrote:
 
> On 16 Jan 2019, at 9:13, Aaron Ballman wrote:
> 
>> On Wed, Jan 16, 2019 at 1:57 AM Akira Hatanaka 
>> wrote:
>>> 
>>> Yes, the behavior of the compiler doesn’t match what’s explained
>>> in the documentation anymore.
>>> 
>>> Please take a look at the attached patch, which updates the
>>> documentation.
>> 
>> Patch mostly LGTM, but I did have one wording suggestion.
>> 
>>> diff --git a/include/clang/Basic/AttrDocs.td
>>> b/include/clang/Basic/AttrDocs.td
>>> index 5773a92c9c..ca3cfcf9b2 100644
>>> --- a/include/clang/Basic/AttrDocs.td
>>> +++ b/include/clang/Basic/AttrDocs.td
>>> @@ -2478,15 +2478,20 @@ def TrivialABIDocs : Documentation {
>>>   let Category = DocCatVariable;
>>>   let Content = [{
>>> The ``trivial_abi`` attribute can be applied to a C++ class, struct,
>>> or union.
>>> -It instructs the compiler to pass and return the type using the C
>>> ABI for the
>>> +``trivial_abi`` has the following effects:
>>> +
>>> +- It instructs the compiler to pass and return the type using the C
>>> ABI for the
>>> underlying type when the type would otherwise be considered
>>> non-trivial for the
>>> purpose of calls.
>>> -A class annotated with `trivial_abi` can have non-trivial
>>> destructors or copy/move constructors without automatically becoming
>>> non-trivial for the purposes of calls. For example:
>>> +- It makes the destructor and copy and move constructors of the
>>> class trivial
>>> +that would otherwise be considered non-trivial under the C++ ABI
>>> rules.
>> 
>> How about: It makes the destructor, copy constructors, and move
>> constructors of the class trivial even if they would otherwise be
>> non-trivial under the C++ ABI rules.
> 
> Let's not say that it makes them trivial, because it doesn't.  It causes
> their immediate non-triviality to be ignored for the purposes of
> deciding
> whether the type can be passed in registers.
> 
 
 Given the attribute now forces the type to be passed in registers, I
>>> think
 it'd be more to the point to say that it makes the triviality of those
 special members be ignored when deciding whether to pass a type with a
 subobject of this type in registers.
>>> 
>>> Wait, it forces it to be passed in registers?  I thought the design
>>> was that it didn't override the non-trivial-abi-ness of subobjects;
>>> see all the discussion of trivially_relocatable.
>>> 
>> 
>> The attribute is ill-formed if applied to a class that has a subobject that
>> can't be passed in registers (or that has a vptr). And then as a weird
>> special case we don't instantiate the attribute when instantiating a class
>> if it would be ill-formed (well, we instantiate it and then remove it
>> again, but the effect is the same).
>> 
>> The commit at the start of this email chain switches us from the "just
>> override the trivialness for the purposes of the ABI" model to /also/
>> forcing the type to be passed in registers (the type would otherwise not be
>> passed in registers in some corner cases, such as if all its copy/move
>> special members are deleted).
> 
> I see.  Alright, I accept your wording, then.
> 
> John.
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 

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


r352822 - Revert "[Sema] Make canPassInRegisters return true if the CXXRecordDecl passed"

2019-01-31 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Thu Jan 31 16:12:06 2019
New Revision: 352822

URL: http://llvm.org/viewvc/llvm-project?rev=352822&view=rev
Log:
Revert "[Sema] Make canPassInRegisters return true if the CXXRecordDecl passed"

This reverts commit r350920 as it is not clear whether we should force a
class to be returned in registers when copy and move constructors are
both deleted.

For more background, see the following discussion:
http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190128/259907.html

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/trivial_abi.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=352822&r1=352821&r2=352822&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Jan 31 16:12:06 2019
@@ -5889,9 +5889,6 @@ static bool canPassInRegisters(Sema &S,
   if (D->isDependentType() || D->isInvalidDecl())
 return false;
 
-  if (D->hasAttr())
-return true;
-
   // Clang <= 4 used the pre-C++11 rule, which ignores move operations.
   // The PS4 platform ABI follows the behavior of Clang 3.2.
   if (CCK == TargetInfo::CCK_ClangABI4OrPS4)

Modified: cfe/trunk/test/CodeGenCXX/trivial_abi.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/trivial_abi.cpp?rev=352822&r1=352821&r2=352822&view=diff
==
--- cfe/trunk/test/CodeGenCXX/trivial_abi.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/trivial_abi.cpp Thu Jan 31 16:12:06 2019
@@ -1,5 +1,5 @@
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++17 -fcxx-exceptions 
-fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions 
-fexceptions -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple arm64-apple-ios11 -std=c++11 -fcxx-exceptions 
-fexceptions -fclang-abi-compat=4.0 -emit-llvm -o - %s | FileCheck %s
 
 // CHECK: %[[STRUCT_SMALL:.*]] = type { i32* }
 // CHECK: %[[STRUCT_LARGE:.*]] = type { i32*, [128 x i32] }
@@ -43,13 +43,6 @@ struct HasNonTrivial {
   NonTrivial m;
 };
 
-struct __attribute__((trivial_abi)) CopyMoveDeleted {
-  CopyMoveDeleted(int);
-  CopyMoveDeleted(const CopyMoveDeleted &) = delete;
-  CopyMoveDeleted(CopyMoveDeleted &&) = delete;
-  int a;
-};
-
 // CHECK: define void @_Z14testParamSmall5Small(i64 %[[A_COERCE:.*]])
 // CHECK: %[[A:.*]] = alloca %[[STRUCT_SMALL]], align 8
 // CHECK: %[[COERCE_DIVE:.*]] = getelementptr inbounds %[[STRUCT_SMALL]], 
%[[STRUCT_SMALL]]* %[[A]], i32 0, i32 0
@@ -244,11 +237,3 @@ void calleeExceptionLarge(Large, Large);
 void testExceptionLarge() {
   calleeExceptionLarge(Large(), Large());
 }
-
-// A class with deleted copy and move constructors can still be passed or
-// returned in registers if the class is annotated with trivial_abi.
-
-// CHECK: define i64 @_Z19testCopyMoveDeletedi(i32 %
-CopyMoveDeleted testCopyMoveDeleted(int a) {
-  return a;
-}


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


Re: r350920 - [Sema] Make canPassInRegisters return true if the CXXRecordDecl passed

2019-01-31 Thread Akira Hatanaka via cfe-commits
Reverted patch in r352822. I’ll send a new patch later that disallows 
trivial_abi on classes without non-deleted copy or move constructors.

> On Jan 31, 2019, at 3:52 PM, Richard Smith  wrote:
> 
> Given that there's uncertainty as to how to proceed and this patch
> affects the ABI, I would prefer that we revert it for trunk and 8.0.
> 
> The suggested alternative of disallowing trivial_abi in the case where
> all copy/move constructors are deleted seems reasonable to me.
> 
> On Thu, 31 Jan 2019 at 14:31, Shoaib Meenai via cfe-commits
>  wrote:
>> 
>> Just wanted to point out that r350920 is on the 8.0 release branch as well. 
>> I don't know if there are any additional considerations there.
>> 
>> On 1/31/19, 2:20 PM, "cfe-commits on behalf of John McCall via cfe-commits" 
>>  
>> wrote:
>> 
>> 
>> 
>>On 31 Jan 2019, at 16:57, Akira Hatanaka wrote:
>> 
>>> Would it be better if we disallowed trivial_abi if the class’ copy
>>> and move destructors were all deleted (and revert r350920)? I think
>>> that would make it easier to reason about when you are allowed to use
>>> trivial_abi and what effect the attribute has (which is to override
>>> the trivialness for the purpose of calls).
>>> 
>>> Sorry for my late reply. It took a while to understand that the patch
>>> I committed might not be the right way to fix the problem.
>> 
>>I'd be fine with that.  If nothing else, we can generalize it later if
>>we decide that's an important use-case.
>> 
>>John.
>> 
>>> 
 On Jan 16, 2019, at 8:37 PM, John McCall via cfe-commits
  wrote:
 
 On 16 Jan 2019, at 20:03, Richard Smith wrote:
 
> On Wed, 16 Jan 2019 at 16:20, John McCall via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> 
>> On 16 Jan 2019, at 18:32, Richard Smith wrote:
>> 
>>> On Wed, 16 Jan 2019 at 09:10, John McCall via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>> 
 On 16 Jan 2019, at 9:13, Aaron Ballman wrote:
 
> On Wed, Jan 16, 2019 at 1:57 AM Akira Hatanaka
> 
> wrote:
>> 
>> Yes, the behavior of the compiler doesn’t match what’s
>> explained
>> in the documentation anymore.
>> 
>> Please take a look at the attached patch, which updates the
>> documentation.
> 
> Patch mostly LGTM, but I did have one wording suggestion.
> 
>> diff --git a/include/clang/Basic/AttrDocs.td
>> b/include/clang/Basic/AttrDocs.td
>> index 5773a92c9c..ca3cfcf9b2 100644
>> --- a/include/clang/Basic/AttrDocs.td
>> +++ b/include/clang/Basic/AttrDocs.td
>> @@ -2478,15 +2478,20 @@ def TrivialABIDocs : Documentation {
>>  let Category = DocCatVariable;
>>  let Content = [{
>> The ``trivial_abi`` attribute can be applied to a C++ class,
>> struct,
>> or union.
>> -It instructs the compiler to pass and return the type using
>> the C
>> ABI for the
>> +``trivial_abi`` has the following effects:
>> +
>> +- It instructs the compiler to pass and return the type using
>> the C
>> ABI for the
>> underlying type when the type would otherwise be considered
>> non-trivial for the
>> purpose of calls.
>> -A class annotated with `trivial_abi` can have non-trivial
>> destructors or copy/move constructors without automatically
>> becoming
>> non-trivial for the purposes of calls. For example:
>> +- It makes the destructor and copy and move constructors of
>> the
>> class trivial
>> +that would otherwise be considered non-trivial under the C++
>> ABI
>> rules.
> 
> How about: It makes the destructor, copy constructors, and move
> constructors of the class trivial even if they would otherwise
> be
> non-trivial under the C++ ABI rules.
 
 Let's not say that it makes them trivial, because it doesn't.  It
 causes
 their immediate non-triviality to be ignored for the purposes of
 deciding
 whether the type can be passed in registers.
 
>>> 
>>> Given the attribute now forces the type to be passed in registers,
>>> I
>> think
>>> it'd be more to the point to say that it makes the triviality of
>>> those
>>> special members be ignored when deciding whether to pass a type
>>> with a
>>> subobject of this type in registers.
>> 
>> Wait, it forces it to be passed in registers?  I thought the design
>> was that it didn't override the non-trivial-abi-ness of subobjects;
>> see all the discussion of trivially_relocatable.
>> 
> 
> The attribute is ill-formed if applied to a class that has a
> subobject that
> can't be passed in registers (or that has a vptr). And then as a
> weird
>

r352949 - [Sema][ObjC] Allow declaring ObjC pointer members with non-trivial

2019-02-01 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Fri Feb  1 18:23:40 2019
New Revision: 352949

URL: http://llvm.org/viewvc/llvm-project?rev=352949&view=rev
Log:
[Sema][ObjC] Allow declaring ObjC pointer members with non-trivial
ownership qualifications in C++ unions under ARC.

An ObjC pointer member with non-trivial ownership qualifications causes
all of the defaulted special functions of the enclosing union to be
defined as deleted, except when the member has an in-class initializer,
the default constructor isn't defined as deleted.

rdar://problem/34213306

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaObjCXX/arc-0x.mm
cfe/trunk/test/SemaObjCXX/objc-weak.mm

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=352949&r1=352948&r2=352949&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Feb  1 18:23:40 
2019
@@ -4649,13 +4649,15 @@ def note_deleted_special_member_class_su
   "copy assignment operator of|move assignment operator of|destructor of|"
   "constructor inherited by}0 "
   "%1 is implicitly deleted because "
-  "%select{base class %3|%select{variant }4field %3}2 has "
+  "%select{base class %3|%select{variant }4field %3}2 "
+  "%select{has "
   "%select{no|a deleted|multiple|an inaccessible|a non-trivial}4 "
   "%select{%select{default constructor|copy constructor|move constructor|copy "
   "assignment operator|move assignment operator|destructor|"
   "%select{default|corresponding|default|default|default}4 constructor}0|"
   "destructor}5"
-  "%select{||s||}4">;
+  "%select{||s||}4"
+  "|is an ObjC pointer}6">;
 def note_deleted_default_ctor_uninit_field : Note<
   "%select{default constructor of|constructor inherited by}0 "
   "%1 is implicitly deleted because field %2 of "

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=352949&r1=352948&r2=352949&view=diff
==
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Fri Feb  1 18:23:40 2019
@@ -991,6 +991,17 @@ void CXXRecordDecl::addedMember(Decl *D)
   setArgPassingRestrictions(RecordDecl::APK_CanNeverPassInRegs);
 
 Data.HasIrrelevantDestructor = false;
+
+if (isUnion()) {
+  data().DefaultedCopyConstructorIsDeleted = true;
+  data().DefaultedMoveConstructorIsDeleted = true;
+  data().DefaultedMoveAssignmentIsDeleted = true;
+  data().DefaultedDestructorIsDeleted = true;
+  data().NeedOverloadResolutionForCopyConstructor = true;
+  data().NeedOverloadResolutionForMoveConstructor = true;
+  data().NeedOverloadResolutionForMoveAssignment = true;
+  data().NeedOverloadResolutionForDestructor = true;
+}
   } else if (!Context.getLangOpts().ObjCAutoRefCount) {
 setHasObjectMember(true);
   }

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=352949&r1=352948&r2=352949&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Feb  1 18:23:40 2019
@@ -15923,7 +15923,8 @@ void Sema::ActOnFields(Scope *S, SourceL
   QualType T = Context.getObjCObjectPointerType(FD->getType());
   FD->setType(T);
 } else if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() &&
-   Record && !ObjCFieldLifetimeErrReported && Record->isUnion()) {
+   Record && !ObjCFieldLifetimeErrReported && Record->isUnion() &&
+   !getLangOpts().CPlusPlus) {
   // It's an error in ARC or Weak if a field has lifetime.
   // We don't want to report this in a system header, though,
   // so we just make the field unavailable.

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=352949&r1=352948&r2=352949&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Feb  1 18:23:40 2019
@@ -6891,6 +6891,8 @@ struct SpecialMemberDeletionInfo
 return ICI ? Sema::CXXInvalid : CSM;
   }
 
+  bool shouldDeleteForVariantObjCPtrMember(FieldDecl *FD, QualType FieldType);
+
   bool visitBase(CXXBaseSpecifier *Base) { return shouldDeleteForBase(Base); }
   bool visitField(FieldDecl *Field) { return shouldDeleteForFiel

  1   2   3   4   5   6   7   8   9   10   >