[clang] Set dllimport on Objective C ivar offsets (PR #107604)

2024-09-11 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/107604
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllimport on Objective C ivar offsets (PR #107604)

2024-09-11 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/107604

>From 5fa137ce295b369b3d652e9538a4f3c13e592ad3 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Fri, 6 Sep 2024 11:54:59 +
Subject: [PATCH 1/2] Set dllimport on Objective C ivar offsets

This commit ensures that offsets for instance variables are marked with 
`dllimport` if the interface to which they belong have this attribute.
---
 clang/lib/CodeGen/CGObjCGNU.cpp | 11 +--
 clang/test/CodeGenObjC/dllstorage.m |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index adc7cdbfded880..6280e9465ecba6 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -1699,11 +1699,18 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   llvm::Value *EmitIvarOffset(CodeGenFunction &CGF,
   const ObjCInterfaceDecl *Interface,
   const ObjCIvarDecl *Ivar) override {
-const std::string Name = 
GetIVarOffsetVariableName(Ivar->getContainingInterface(), Ivar);
+const ObjCInterfaceDecl *ContainingInterface =
+Ivar->getContainingInterface();
+const std::string Name =
+GetIVarOffsetVariableName(ContainingInterface, Ivar);
 llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
-if (!IvarOffsetPointer)
+if (!IvarOffsetPointer) {
   IvarOffsetPointer = new llvm::GlobalVariable(TheModule, IntTy, false,
   llvm::GlobalValue::ExternalLinkage, nullptr, Name);
+  if (Ivar->getAccessControl() != ObjCIvarDecl::Private &&
+  Ivar->getAccessControl() != ObjCIvarDecl::Package)
+CGM.setGVProperties(IvarOffsetPointer, ContainingInterface);
+}
 CharUnits Align = CGM.getIntAlign();
 llvm::Value *Offset =
 CGF.Builder.CreateAlignedLoad(IntTy, IvarOffsetPointer, Align);
diff --git a/clang/test/CodeGenObjC/dllstorage.m 
b/clang/test/CodeGenObjC/dllstorage.m
index c94f4c9b5804d0..a6c591b2d79302 100644
--- a/clang/test/CodeGenObjC/dllstorage.m
+++ b/clang/test/CodeGenObjC/dllstorage.m
@@ -112,7 +112,7 @@ @interface M : I {
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
 // CHECK-NF-DAG: @"$_OBJC_REF_CLASS_M" = external dllimport global ptr
-// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external dllimport global 
i32
 
 __declspec(dllexport)
 __attribute__((__objc_exception__))
@@ -151,7 +151,7 @@ id f(Q *q) {
 
 // CHECK-IR-DAG: @"OBJC_IVAR_$_M._ivar" = external dllimport global i32
 
-// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external global i32
+// CHECK-NF-DAG: @"__objc_ivar_offset_M._ivar.@" = external dllimport global 
i32
 
 int g(void) {
   @autoreleasepool {

>From 93abb9bbc785d9ed6e86c0f1cfb22bc7982da252 Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Sat, 7 Sep 2024 03:00:46 -0700
Subject: [PATCH 2/2] Add tests to ensure unmarked instance variables are
 considered protected

---
 clang/test/SemaObjC/ivar-access-tests.m | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/clang/test/SemaObjC/ivar-access-tests.m 
b/clang/test/SemaObjC/ivar-access-tests.m
index cd7e09d406adaa..6060dea5ab0f0e 100644
--- a/clang/test/SemaObjC/ivar-access-tests.m
+++ b/clang/test/SemaObjC/ivar-access-tests.m
@@ -2,6 +2,8 @@
 
 @interface MySuperClass
 {
+  int unmarked;
+
 @private
   int private;
 
@@ -17,6 +19,7 @@ @implementation MySuperClass
 - (void) test {
 int access;
 MySuperClass *s = 0;
+access = s->unmarked;
 access = s->private;   
 access = s->protected;
 }
@@ -30,9 +33,11 @@ @implementation MyClass
 - (void) test {
 int access;
 MySuperClass *s = 0;
+access = s->unmarked;
 access = s->private; // expected-error {{instance variable 'private' is 
private}}
 access = s->protected;
 MyClass *m=0;
+access = m->unmarked;
 access = m->private; // expected-error {{instance variable 'private' is 
private}}
 access = m->protected;
 }
@@ -46,9 +51,11 @@ @implementation Deeper
 - (void) test {
 int access;
 MySuperClass *s = 0;
+access = s->unmarked;
 access = s->private; // expected-error {{instance variable 'private' is 
private}}
 access = s->protected;
 MyClass *m=0;
+access = m->unmarked;
 access = m->private; // expected-error {{instance variable 'private' is 
private}}
 access = m->protected;
 }
@@ -61,9 +68,11 @@ @implementation Unrelated
 - (void) test {
 int access;
 MySuperClass *s = 0;
+access = s->unmarked; // expected-error {{instance variable 'unmarked' is 
protected}}
 access = s->private; // expected-error {{instance variable 'private' is 
private}}
 access = s->protected; // expected-error {{instance variable 'protected' 
is protected}}
 MyClass *m=0;
+access = m->unmarked; // expected-error {{instanc

[clang] Set dllimport on Objective C ivar offsets (PR #107604)

2024-09-11 Thread David Chisnall via cfe-commits

davidchisnall wrote:

LGTM, do you need someone else to commit it for you?

https://github.com/llvm/llvm-project/pull/107604
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllimport on Objective C ivar offsets (PR #107604)

2024-09-07 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall approved this pull request.

Looks good to me. It might be worth updating the test to make sure that one 
ivar is implicitly `@protected` if it isn’t already.

https://github.com/llvm/llvm-project/pull/107604
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][CodeGen] Fix bad codegen when building Clang with latest MSVC (PR #102681)

2024-08-10 Thread David Chisnall via cfe-commits

davidchisnall wrote:

The new version is probably slightly more readable than mine, but I don’t 
really understand how it would affect codegen with UT C. No objections.

https://github.com/llvm/llvm-project/pull/102681
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)

2024-07-11 Thread David Chisnall via cfe-commits

davidchisnall wrote:

Those CI failures look unrelated.  

https://github.com/llvm/llvm-project/pull/94885
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)

2024-07-11 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/94885
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)

2024-07-11 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/94885

>From e818620af0a9732d7c0e96b85d7ec1f5a8afc297 Mon Sep 17 00:00:00 2001
From: Rose 
Date: Sat, 8 Jun 2024 22:30:53 -0400
Subject: [PATCH] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot
 overflow

When accessing data in the buffer, we know we won't overrun the buffer, so we 
know it is inbounds. In addition, we know that the addition to increase the 
index is also NUW because the buffer's end has to be unsigned-greater-than 0, 
which becomes untrue if the bounds ever has an unsigned wrap.
---
 clang/lib/CodeGen/CGObjC.cpp | 4 ++--
 clang/test/CodeGenObjC/arc-foreach.m | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 281b2d9795f6c..80a64d8e4cdd9 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -1952,7 +1952,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const 
ObjCForCollectionStmt &S){
 Builder.CreateLoad(StateItemsPtr, "stateitems");
 
   // Fetch the value at the current index from the buffer.
-  llvm::Value *CurrentItemPtr = Builder.CreateGEP(
+  llvm::Value *CurrentItemPtr = Builder.CreateInBoundsGEP(
   ObjCIdType, EnumStateItems, index, "currentitem.ptr");
   llvm::Value *CurrentItem =
 Builder.CreateAlignedLoad(ObjCIdType, CurrentItemPtr, getPointerAlign());
@@ -2028,7 +2028,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const 
ObjCForCollectionStmt &S){
 
   // First we check in the local buffer.
   llvm::Value *indexPlusOne =
-  Builder.CreateAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1));
+  Builder.CreateNUWAdd(index, llvm::ConstantInt::get(NSUIntegerTy, 1));
 
   // If we haven't overrun the buffer yet, we can continue.
   // Set the branch weights based on the simplifying assumption that this is
diff --git a/clang/test/CodeGenObjC/arc-foreach.m 
b/clang/test/CodeGenObjC/arc-foreach.m
index 71edc5161303c..9f7b60aef7a1b 100644
--- a/clang/test/CodeGenObjC/arc-foreach.m
+++ b/clang/test/CodeGenObjC/arc-foreach.m
@@ -53,7 +53,7 @@ void test0(NSArray *array) {
 
 // CHECK-LP64:  [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr 
[[STATE]], i32 0, i32 1
 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]]
-// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64
+// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64
 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]]
 // CHECK-LP64-NEXT: store ptr [[T3]], ptr [[X]]
 
@@ -100,7 +100,7 @@ void test1(NSArray *array) {
 
 // CHECK-LP64:  [[T0:%.*]] = getelementptr inbounds [[STATE_T]], ptr 
[[STATE]], i32 0, i32 1
 // CHECK-LP64-NEXT: [[T1:%.*]] = load ptr, ptr [[T0]]
-// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr ptr, ptr [[T1]], i64
+// CHECK-LP64-NEXT: [[T2:%.*]] = getelementptr inbounds ptr, ptr [[T1]], i64
 // CHECK-LP64-NEXT: [[T3:%.*]] = load ptr, ptr [[T2]]
 // CHECK-LP64-NEXT: call ptr @llvm.objc.initWeak(ptr [[X]], ptr [[T3]])
 

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


[clang] [ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (PR #94885)

2024-06-10 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall approved this pull request.


https://github.com/llvm/llvm-project/pull/94885
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix objc_sel_{name,types} missing an underscore (PR #88713)

2024-04-22 Thread David Chisnall via cfe-commits

davidchisnall wrote:

Yup, it’s just an optimisation. The runtime does a slightly more complex 
deduplication pass during loading, this just does a best effort merge so that 
we don’t end up with hundreds of copies of common selectors as we did with the 
GCC ABI. If we don’t do it, it isn’t an ABI break, it’s only an ABI break if we 
merge two strings that are not the same.

Some of this code accreted and so deduplicating the code, as well as the 
selectors, is a good idea.

https://github.com/llvm/llvm-project/pull/88713
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-22 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/78030
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/78030

>From 008814b0aeee4b1a853fa4544c0dba89252425ce Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 214 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 +++
 3 files changed, 239 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea5121..1ccf60f0b7bee70 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 9cc7f32815f7e9e..a36b0cdddaf0afd 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -597,6 +599,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -917,6 +923,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 ClassAliasSection,
 ConstantStringSection
   };
+  /// The subset of `objc_class_flags` used at compile time.
+  enum ClassFlags {
+/// This is a metaclass
+ClassFlagMeta = (1 << 0),
+/// This class has been initialised by the runtime (+initialize has been
+/// sent if necessary).
+ClassFlagInitialized = (1 << 8),
+  };
   static const char *const SectionsBaseNames[8];
   static const char *const PECOFFSectionsBaseNames[8];
   template
@@ -932,6 +946,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1719,7 +1735,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 metaclassFields.addInt(LongTy, 0);
 // unsigned long info;
 // objc_class_flag_meta
-metaclassFields.addInt(LongTy, 1);
+metaclassFi

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

davidchisnall wrote:

Thanks, all review comments should now be resolved.

https://github.com/llvm/llvm-project/pull/78030
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-21 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/78030

>From 02123c6557c7deea3f04f96bce7230f9d45e4ddb Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 214 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 +++
 3 files changed, 239 insertions(+), 27 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..71e7a580ffe091 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -911,6 +917,14 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 ClassAliasSection,
 ConstantStringSection
   };
+  /// The subset of `objc_class_flags` used at compile time.
+  enum ClassFlags {
+/// This is a metaclass
+ClassFlagMeta = (1 << 0),
+/// This class has been initialised by the runtime (+initialize has been
+/// sent if necessary).
+ClassFlagInitialized = (1 << 8),
+  };
   static const char *const SectionsBaseNames[8];
   static const char *const PECOFFSectionsBaseNames[8];
   template
@@ -926,6 +940,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1709,7 +1725,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 metaclassFields.addInt(LongTy, 0);
 // unsigned long info;
 // objc_class_flag_meta
-metaclassFields.addInt(LongTy, 1);
+metaclassFields

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-14 Thread David Chisnall via cfe-commits

davidchisnall wrote:

Formatting issues were introduced by running clang-format15, should now be 
fixed.

https://github.com/llvm/llvm-project/pull/78030
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-14 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/78030

>From c8d733479ee8d0fd7c75c4a623f8c1bc2f132c61 Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 204 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 
 3 files changed, 230 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..44fdef5ac57c86 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -926,6 +932,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1981,6 +1989,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 CGObjCGNUstep2(CodeGenModule &Mod) : CGObjCGNUstep(Mod, 10, 4, 2) {
   MsgLookupSuperFn.init(&CGM, "objc_msg_lookup_super", IMPTy,
 PtrToObjCSuperTy, SelectorTy);
+  SentInitializeFn.init(&CGM, "objc_send_initialize",
+llvm::Type::getVoidTy(VMContext), IdTy);
   // struct objc_property
   // {
   //   const char *name;
@@ -1994,6 +2004,106 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 { PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty, PtrToInt8Ty 
});
 }
 
+void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
+  const O

[clang] Enable direct methods and fast alloc calls for libobjc2. (PR #78030)

2024-01-13 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall created 
https://github.com/llvm/llvm-project/pull/78030

These will be supported in the upcoming 2.2 release and so are gated on that 
version.

Direct methods call `objc_send_initialize` if they are class methods that may 
not have called initialize.  This is guarded by checking for the class flag bit 
that is set on initialisation in the class.  This bit now forms part of the 
ABI, but it's been stable for 30+ years so that's fine as a contract going 
forwards.

>From b286b9b07d60a7b3243ad5e8e6959a4d7d7fda49 Mon Sep 17 00:00:00 2001
From: David Chisnall 
Date: Sun, 7 Jan 2024 14:53:48 +
Subject: [PATCH] Enable direct methods and fast alloc calls for libobjc2.

These will be supported in the upcoming 2.2 release and so are gated on
that version.

Direct methods call `objc_send_initialize` if they are class methods
that may not have called initialize.  This is guarded by checking for
the class flag bit that is set on initialisation in the class.  This bit
now forms part of the ABI, but it's been stable for 30+ years so that's
fine as a contract going forwards.
---
 clang/include/clang/Basic/ObjCRuntime.h   |  15 +-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 204 --
 .../test/CodeGenObjC/gnustep2-direct-method.m |  37 
 3 files changed, 230 insertions(+), 26 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/gnustep2-direct-method.m

diff --git a/clang/include/clang/Basic/ObjCRuntime.h 
b/clang/include/clang/Basic/ObjCRuntime.h
index f05debe6fea512..1ccf60f0b7bee7 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -211,7 +211,13 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  // This could be enabled for all versions, except for the fact that the
+  // implementation of `objc_retain` and friends prior to 2.2 call [object
+  // retain] in their fall-back paths, which leads to infinite recursion if
+  // the runtime is built with this enabled.  Since distributions typically
+  // build all Objective-C things with the same compiler version and flags,
+  // it's better to be conservative here.
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW:
   return false;
 }
@@ -248,7 +254,7 @@ class ObjCRuntime {
 case GCC:
   return false;
 case GNUstep:
-  return false;
+  return getVersion() >= VersionTuple(2, 2);
 case ObjFW:
   return false;
 }
@@ -266,6 +272,8 @@ class ObjCRuntime {
   return getVersion() >= VersionTuple(12, 2);
 case WatchOS:
   return getVersion() >= VersionTuple(5, 2);
+case GNUstep:
+  return getVersion() >= VersionTuple(2, 2);
 default:
   return false;
 }
@@ -463,7 +471,8 @@ class ObjCRuntime {
 case iOS: return true;
 case WatchOS: return true;
 case GCC: return false;
-case GNUstep: return false;
+case GNUstep:
+  return (getVersion() >= VersionTuple(2, 2));
 case ObjFW: return false;
 }
 llvm_unreachable("bad kind");
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..a71f42169fc3e6 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -18,6 +18,8 @@
 #include "CGObjCRuntime.h"
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CodeGenTypes.h"
+#include "SanitizerMetadata.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/Decl.h"
@@ -595,6 +597,10 @@ class CGObjCGNU : public CGObjCRuntime {
 
   llvm::Function *GenerateMethod(const ObjCMethodDecl *OMD,
  const ObjCContainerDecl *CD) override;
+
+  // Map to unify direct method definitions.
+  llvm::DenseMap
+  DirectMethodDefinitions;
   void GenerateDirectMethodPrologue(CodeGenFunction &CGF, llvm::Function *Fn,
 const ObjCMethodDecl *OMD,
 const ObjCContainerDecl *CD) override;
@@ -926,6 +932,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
   /// structure describing the receiver and the class, and a selector as
   /// arguments.  Returns the IMP for the corresponding method.
   LazyRuntimeFunction MsgLookupSuperFn;
+  /// Function to ensure that +initialize is sent to a class.
+  LazyRuntimeFunction SentInitializeFn;
   /// A flag indicating if we've emitted at least one protocol.
   /// If we haven't, then we need to emit an empty protocol, to ensure that the
   /// __start__objc_protocols and __stop__objc_protocols sections exist.
@@ -1981,6 +1989,8 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
 CGObjCGNUstep2(CodeGenModule &Mod) : CGObjCGNUstep(Mod, 10, 4, 2) {
   MsgLookupSuperFn.init(&CGM, "objc_msg_lookup_super", IMPTy,
 PtrToObjCSuperTy, SelectorTy);
+  SentInitializeFn.init(&CGM, "objc_send_initialize",
+

[clang] [ObjC]: Make type encoding safe in symbol names (PR #77797)

2024-01-12 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/77797
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC]: Make type encoding safe in symbol names (PR #77797)

2024-01-12 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall approved this pull request.


https://github.com/llvm/llvm-project/pull/77797
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ObjC]: Make type encoding safe in symbol names (PR #77797)

2024-01-11 Thread David Chisnall via cfe-commits


@@ -1,5 +1,14 @@
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o %t %s
-// RUN: FileCheck < %t %s
+// RUN: FileCheck -check-prefix CHECK-DWARF < %t %s
+
+// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o %t %s
+// RUN: FileCheck -check-prefix CHECK-MINGW < %t %s
+
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o %t %s
+// RUN: FileCheck -check-prefix CHECK-MSVC < %t %s
+
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o %t %s
+// RUN: FileCheck -check-prefix CHECK-ELF < %t %s

davidchisnall wrote:

Do these need to use a temporary file?

https://github.com/llvm/llvm-project/pull/77797
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-10 Thread David Chisnall via cfe-commits

davidchisnall wrote:

It looks as if three tests are failing in CI:

  Clang :: CodeGenObjC/2007-04-03-ObjcEH.m
  Clang :: CodeGenObjC/exceptions-personality.m
  Clang :: Coverage/codegen-gnu.m


https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-09 Thread David Chisnall via cfe-commits

davidchisnall wrote:

I'd like CI to be green.  Hopefully the failure is transient, but I don't seem 
to be able to kick off a rerun.  Maybe once others start passing, you can 
squash the two commits and force push to restart it?

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/77385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread David Chisnall via cfe-commits

davidchisnall wrote:

I didn’t intentional hit close, not sure what happened there.

https://github.com/llvm/llvm-project/pull/77385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall reopened 
https://github.com/llvm/llvm-project/pull/77385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall closed 
https://github.com/llvm/llvm-project/pull/77385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Set dllstorage on ObjectiveC ivar offsets (PR #77385)

2024-01-09 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall approved this pull request.


https://github.com/llvm/llvm-project/pull/77385
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits


@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {

davidchisnall wrote:

Ah, sorry, I didn't see the `re` bit.

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits

davidchisnall wrote:

The failing format CI isn’t in this PR, rebasing to (hopefully) fix it

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits

https://github.com/davidchisnall updated 
https://github.com/llvm/llvm-project/pull/77255

>From 6195e6c57b5b461dda2bffec0e5497ceb659f82c Mon Sep 17 00:00:00 2001
From: Frederik Carlier 
Date: Thu, 4 Jan 2024 11:10:05 -0800
Subject: [PATCH] Objective C: use C++ exceptions on MinGW+GNUstep

The GNUstep Objective C runtime (libobjc2) is adding support for
MinGW.  This runtime uses C++ exceptions in that configuration.
---
 clang/lib/CodeGen/CGException.cpp |  9 +++-
 clang/lib/CodeGen/CGObjCGNU.cpp   | 35 
 .../test/CodeGenObjC/exceptions-personality.m | 53 +++
 clang/test/CodeGenObjC/personality.m  |  5 +-
 clang/test/CodeGenObjCXX/personality.mm   |  5 +-
 5 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 clang/test/CodeGenObjC/exceptions-personality.m

diff --git a/clang/lib/CodeGen/CGException.cpp 
b/clang/lib/CodeGen/CGException.cpp
index 0d507da5c1ba92..cadd6f6ad75daa 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -156,7 +156,9 @@ static const EHPersonality &getObjCPersonality(const 
TargetInfo &Target,
   case ObjCRuntime::WatchOS:
 return EHPersonality::NeXT_ObjC;
   case ObjCRuntime::GNUstep:
-if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
+if (T.isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else if (L.ObjCRuntime.getVersion() >= VersionTuple(1, 7))
   return EHPersonality::GNUstep_ObjC;
 [[fallthrough]];
   case ObjCRuntime::GCC:
@@ -210,7 +212,10 @@ static const EHPersonality &getObjCXXPersonality(const 
TargetInfo &Target,
 return getObjCPersonality(Target, L);
 
   case ObjCRuntime::GNUstep:
-return EHPersonality::GNU_ObjCXX;
+if (Target.getTriple().isOSCygMing())
+  return EHPersonality::GNU_CPlusPlus_SEH;
+else
+  return EHPersonality::GNU_ObjCXX;
 
   // The GCC runtime's personality function inherently doesn't support
   // mixed EH.  Use the ObjC personality just to avoid returning null.
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 4ca1a8cce64d89..2b3a5da87fb778 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -819,10 +819,19 @@ class CGObjCGNUstep : public CGObjCGNU {
   SlotLookupSuperFn.init(&CGM, "objc_slot_lookup_super", SlotTy,
  PtrToObjCSuperTy, SelectorTy);
   // If we're in ObjC++ mode, then we want to make
-  if (usesSEHExceptions) {
-  llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
-  // void objc_exception_rethrow(void)
-  ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy);
+  if (CGM.getTarget().getTriple().isOSCygMing() &&
+  isRuntime(ObjCRuntime::GNUstep, 2)) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void *__cxa_begin_catch(void *e)
+EnterCatchFn.init(&CGM, "__cxa_begin_catch", PtrTy, PtrTy);
+// void __cxa_end_catch(void)
+ExitCatchFn.init(&CGM, "__cxa_end_catch", VoidTy);
+// void objc_exception_rethrow(void*)
+ExceptionReThrowFn.init(&CGM, "__cxa_rethrow", PtrTy);
+  } else if (usesSEHExceptions) {
+llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
+// void objc_exception_rethrow(void)
+ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy);
   } else if (CGM.getLangOpts().CPlusPlus) {
 llvm::Type *VoidTy = llvm::Type::getVoidTy(VMContext);
 // void *__cxa_begin_catch(void *e)
@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {
+ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
+  }
   // int objc_sync_enter(id);
   SyncEnterFn.init(&CGM, "objc_sync_enter", IntTy, IdTy);
   // int objc_sync_exit(id);
@@ -2387,7 +2401,9 @@ llvm::Constant *CGObjCGNUstep::GetEHType(QualType T) {
   if (usesSEHExceptions)
 return CGM.getCXXABI().getAddrOfRTTIDescriptor(T);
 
-  if (!CGM.getLangOpts().CPlusPlus)
+  if (!CGM.getLangOpts().CPlusPlus &&
+  !(CGM.getTarget().getTriple().isOSCygMing() &&
+isRuntime(ObjCRuntime::GNUstep, 2)))
 return CGObjCGNU::GetEHType(T);
 
   // For Objective-C++, we want to provide the ability to catch both C++ and
@@ -3993,7 +4009,9 @@ void CGObjCGNU::EmitThrowStmt(CodeGenFunction &CGF,
 ExceptionAsObject = CGF.ObjCEHValueStack.back();
 isRethrow = true;
   }
-  if (isRethrow && usesSEHExceptions) {
+  if (isRethrow &&
+  (usesSEHExceptions || (CGM.getTarget().getTriple().isOSCygMing() &&
+ 

[clang] Objective C: use C++ exceptions on MinGW+GNUstep (PR #77255)

2024-01-08 Thread David Chisnall via cfe-commits


@@ -2210,7 +2219,12 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned 
runtimeABIVersion,
 
   // void objc_exception_throw(id);
   ExceptionThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
-  ExceptionReThrowFn.init(&CGM, "objc_exception_throw", VoidTy, IdTy);
+  if ((CGM.getTarget().getTriple().isOSCygMing() &&
+   isRuntime(ObjCRuntime::GNUstep, 2))) {
+ExceptionReThrowFn.init(&CGM, "objc_exception_rethrow", VoidTy, IdTy);
+  } else {

davidchisnall wrote:

It looks as if both branches of the if and else here do the same thing?

https://github.com/llvm/llvm-project/pull/77255
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 94c3b16 - Fix crash in ObjC codegen introduced with 5ab6ee75994d645725264e757d67bbb1c96fb2b6

2022-07-24 Thread David Chisnall via cfe-commits

Author: David Chisnall
Date: 2022-07-24T13:59:45+01:00
New Revision: 94c3b169785c0a0ae650c724dcf2c22ff65f5e24

URL: 
https://github.com/llvm/llvm-project/commit/94c3b169785c0a0ae650c724dcf2c22ff65f5e24
DIFF: 
https://github.com/llvm/llvm-project/commit/94c3b169785c0a0ae650c724dcf2c22ff65f5e24.diff

LOG: Fix crash in ObjC codegen introduced with 
5ab6ee75994d645725264e757d67bbb1c96fb2b6

5ab6ee75994d645725264e757d67bbb1c96fb2b6 assumed that if `RValue::isScalar()` 
returns true then `RValue::getScalarVal` will return a valid value.  This is 
not the case when the return value is `void` and so void message returns would 
crash if they hit this path.  This is triggered only for cases where the 
nil-handling path needs to do something non-trivial (destroy arguments that 
should be consumed by the callee).

Reviewed By: triplef

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

Added: 
clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm

Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index ec459f07f307d..7bbe9af7ed593 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -2837,11 +2837,13 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF,
 // Enter the continuation block and emit a phi if required.
 CGF.EmitBlock(continueBB);
 if (msgRet.isScalar()) {
-  llvm::Value *v = msgRet.getScalarVal();
-  llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
-  phi->addIncoming(v, nonNilPathBB);
-  phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
-  msgRet = RValue::get(phi);
+  // If the return type is void, do nothing
+  if (llvm::Value *v = msgRet.getScalarVal()) {
+llvm::PHINode *phi = Builder.CreatePHI(v->getType(), 2);
+phi->addIncoming(v, nonNilPathBB);
+phi->addIncoming(CGM.EmitNullConstant(ResultType), nilPathBB);
+msgRet = RValue::get(phi);
+  }
 } else if (msgRet.isAggregate()) {
   // Aggregate zeroing is handled in nilCleanupBB when it's required.
 } else /* isComplex() */ {

diff  --git a/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm 
b/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm
new file mode 100644
index 0..a7de79bf79940
--- /dev/null
+++ b/clang/test/CodeGenObjC/gnustep2-nontrivial-destructor-argument.mm
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple x86_64-unknow-windows-msvc -S -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o - %s 
+
+// Regression test.  Ensure that C++ arguments with non-trivial destructors
+// don't crash the compiler.
+
+struct X
+{
+  int a;
+  ~X();
+};
+
+@protocol Y
+- (void)foo: (X)bar;
+@end
+
+
+void test(id obj)
+{
+  X a{12};
+  [obj foo: a];
+}
+



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


[clang] d1ed670 - [GNU ObjC] Fix a regression listing methods twice.

2020-12-01 Thread David Chisnall via cfe-commits

Author: David Chisnall
Date: 2020-12-01T09:50:18Z
New Revision: d1ed67037de6f3f44dc446784f74f0e02adec9b5

URL: 
https://github.com/llvm/llvm-project/commit/d1ed67037de6f3f44dc446784f74f0e02adec9b5
DIFF: 
https://github.com/llvm/llvm-project/commit/d1ed67037de6f3f44dc446784f74f0e02adec9b5.diff

LOG: [GNU ObjC] Fix a regression listing methods twice.

Methods synthesized from declared properties were being added to the
method lists twice.  This came from the change to list them in the
class's method list, which missed removing the place in CGObjCGNU that
added them again.

Reviewed By: lanza

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

Added: 
clang/test/CodeGenObjC/gnu-method-only-once.m

Modified: 
clang/lib/CodeGen/CGObjCGNU.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index c6500c0230c4..9825d7bca18c 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3512,19 +3512,6 @@ void CGObjCGNU::GenerateClass(const 
ObjCImplementationDecl *OID) {
   ClassMethods.insert(ClassMethods.begin(), OID->classmeth_begin(),
   OID->classmeth_end());
 
-  // Collect the same information about synthesized properties, which don't
-  // show up in the instance method lists.
-  for (auto *propertyImpl : OID->property_impls())
-if (propertyImpl->getPropertyImplementation() ==
-ObjCPropertyImplDecl::Synthesize) {
-  auto addPropertyMethod = [&](const ObjCMethodDecl *accessor) {
-if (accessor)
-  InstanceMethods.push_back(accessor);
-  };
-  addPropertyMethod(propertyImpl->getGetterMethodDecl());
-  addPropertyMethod(propertyImpl->getSetterMethodDecl());
-}
-
   llvm::Constant *Properties = GeneratePropertyList(OID, ClassDecl);
 
   // Collect the names of referenced protocols

diff  --git a/clang/test/CodeGenObjC/gnu-method-only-once.m 
b/clang/test/CodeGenObjC/gnu-method-only-once.m
new file mode 100644
index ..67d873ccc0aa
--- /dev/null
+++ b/clang/test/CodeGenObjC/gnu-method-only-once.m
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-NEW
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm 
-fobjc-runtime=gnustep-1.8 -o - %s | FileCheck %s -check-prefix=CHECK-OLD
+
+// Clang 9 or 10 changed the handling of method lists so that methods provided
+// from synthesised properties showed up in the method list, where previously
+// CGObjCGNU had to collect them and merge them.  One of the places where this
+// merging happened was missed in the move and so we ended up emitting two
+// copies of method metadata for declared properties.
+
+// This class has only instance properties and only one pair of synthesized
+// methods from the property and so we should synthesize only one method list,
+// with precisely two methods on it.
+@interface X
+@property (retain) id iProp;
+@end
+
+@implementation X
+@synthesize iProp;
+@end
+
+// Check that the method list has precisely 2 methods.
+// CHECK-NEW: @.objc_method_list = internal global { i8*, i32, i64, [2 x
+// CHECK-OLD: @.objc_method_list = internal global { i8*, i32, [2 x



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


[clang] bdd88b7 - Add support for __declspec(guard(nocf))

2020-01-10 Thread David Chisnall via cfe-commits

Author: Andrew Paverd
Date: 2020-01-10T16:04:12Z
New Revision: bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7

URL: 
https://github.com/llvm/llvm-project/commit/bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7
DIFF: 
https://github.com/llvm/llvm-project/commit/bdd88b7ed3956534a0a71b1ea2bc88c69d48f9b7.diff

LOG: Add support for __declspec(guard(nocf))

Summary:
Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a
new `"guard_nocf"` function attribute to indicate that checks should not be
added on indirect calls within that function. Add support for
`__declspec(guard(nocf))` following the same syntax as MSVC.

Reviewers: rnk, dmajor, pcc, hans, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

Added: 
clang/test/CodeGen/guard_nocf.c
clang/test/CodeGenCXX/guard_nocf.cpp
clang/test/Sema/attr-guard_nocf.c

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CGCall.cpp
clang/lib/Sema/SemaDeclAttr.cpp
llvm/lib/Transforms/CFGuard/CFGuard.cpp
llvm/test/CodeGen/AArch64/cfguard-checks.ll
llvm/test/CodeGen/ARM/cfguard-checks.ll
llvm/test/CodeGen/X86/cfguard-checks.ll

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c992d6459f0c..d1c42e8af4d1 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2907,6 +2907,15 @@ def MSAllocator : InheritableAttr {
   let Documentation = [MSAllocatorDocs];
 }
 
+def CFGuard : InheritableAttr {
+  // Currently only the __declspec(guard(nocf)) modifier is supported. In 
future
+  // we might also want to support __declspec(guard(suppress)).
+  let Spellings = [Declspec<"guard">];
+  let Subjects = SubjectList<[Function]>;
+  let Args = [EnumArgument<"Guard", "GuardArg", ["nocf"], ["nocf"]>];
+  let Documentation = [CFGuardDocs];
+}
+
 def MSStruct : InheritableAttr {
   let Spellings = [GCC<"ms_struct">];
   let Subjects = SubjectList<[Record]>;

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 70bf2517cdcb..6692c3825ec6 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4558,6 +4558,26 @@ This attribute does not affect optimizations in any way, 
unlike GCC's
 }];
 }
 
+def CFGuardDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Code can indicate CFG checks are not wanted with the 
``__declspec(guard(nocf))``
+attribute. This directs the compiler to not insert any CFG checks for the 
entire
+function. This approach is typically used only sparingly in specific 
situations 
+where the programmer has manually inserted "CFG-equivalent" protection. The 
+programmer knows that they are calling through some read-only function table 
+whose address is obtained through read-only memory references and for which 
the 
+index is masked to the function table limit. This approach may also be applied 
+to small wrapper functions that are not inlined and that do nothing more than 
+make a call through a function pointer. Since incorrect usage of this 
directive 
+can compromise the security of CFG, the programmer must be very careful using 
+the directive. Typically, this usage is limited to very small functions that 
+only call one function.
+
+`Control Flow Guard documentation 
`
+}];
+}
+
 def HIPPinnedShadowDocs : Documentation {
   let Category = DocCatType;
   let Content = [{

diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index b49b194d6112..e4803fde230f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4415,6 +4415,17 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   if (callOrInvoke)
 *callOrInvoke = CI;
 
+  // If this is within a function that has the guard(nocf) attribute and is an
+  // indirect call, add the "guard_nocf" attribute to this call to indicate 
that
+  // Control Flow Guard checks should not be added, even if the call is 
inlined.
+  if (const auto *FD = dyn_cast_or_null(CurFuncDecl)) {
+if (const auto *A = FD->getAttr()) {
+  if (A->getGuard() == CFGuardAttr::GuardArg::nocf && 
!CI->getCalledFunction())
+Attrs = Attrs.addAttribute(
+getLLVMContext(), llvm::AttributeList::FunctionIndex, 
"guard_nocf");
+}
+  }
+
   // Apply the attributes and calling convention.
   CI->setAttributes(Attrs);
   CI->setCallingConv(static_cast(CallingConv));

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 7f1da406757d..142c6f156506 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6626,6 +6626

Re: [PATCH] D55802: Change CGObjC to use objc intrinsics instead of runtime methods

2019-11-01 Thread David Chisnall via cfe-commits

Hi,

I think the assumption that intrinsics can't read any global is, indeed, 
the problem here.  `@llvm.objc.autoreleasePoolPop` may call any number 
of `-dealloc` methods with arbitrary side effects (though if they cause 
resurrection then that's undefined behaviour), so there should be no 
assumptions about the memory that it will read and write.


This check looks wrong, the documentation in Intrinsics.td states:

> By default, intrinsics are assumed to have side
> effects, so this property is only necessary if you have defined one of
> the memory properties listed above.

Looking at the other intrinsics, the ones that don't touch memory 
(mostly?) seem to have the IntrNoMem attribute set.  I think that should 
GlobalsAA should probably check that intrinsics either have that 
attribute set or one of the others that restricts the memory it can 
touch (e.g. IntrArgMemOnly).


David

On 31/10/2019 23:55, Alina Sbirlea wrote:

Following up on this, AFAICT this is working as intended on the LLVM side.

The different decision is made in GlobalsAA + MemoryDependencyAnalysis.
IIUC, the logic there is along the lines of: if I have a global G that's 
"internal" ("static" in C), and an intrinsic method M, then M cannot 
read from or write to G. In the LLVM IR for the test, @deallocCalled is 
an internal global, @llvm.objc.autoreleasePoolPop is an intrinsic, hence 
@llvm.objc.autoreleasePoolPop cannot read or write @deallocCalled.


Please note however that there are a couple of things that I found and 
intend to fix in GlobalsAA, but they do not seem to affect this case.


The one problem in particular that I thought was relevant here is that 
the "MayReadAnyGlobal" is not set on a path in 
GlobalsAAResult::AnalyzeCallGraph, but should apply when the function is 
not an intrinsic (judging by the other code paths). If 
@llvm.objc.autoreleasePoolPop was not an intrinsic, then with the fix in 
D69690  would resolve this miscompile.
Perhaps we should not rely on the assumption that intrinsics are 
restricted to this behavior in GlobalsAA?


Best,
Alina


On Thu, Oct 17, 2019 at 3:00 PM Alina Sbirlea > wrote:


I only got a chance to look more into this now. I can reproduce it
with re-inserting the "static".

The miscompile is not related to MemorySSA, i.e. disabling all uses
of MemorySSA doesn't help.
It appears to be a GVN bug, but I haven't tracked it further than this.

To repro, see attached .ll files. The only difference is the global
variable being static or not, which in IR translates to internal or
dso_local.
A simple `opt -O3 AssociatedObject_O0_*.ll` shows the difference you
mention.

Reducing the pipeline, I believe the result after the following
command is incorrect.
`opt -globals-aa -gvn AssociatedObject_O0_*.ll`
I'll need to dig deeper to confirm and track down the bug inside the
pass.


Thanks,
Alina


On Mon, Sep 30, 2019 at 4:30 AM David Chisnall
mailto:david.chisn...@cl.cam.ac.uk>>
wrote:

Hi,

Yes, I believe it does still reproduce (at least, with the most
recent
build that I tried).  We worked around the clang bug to make the
test pass:


https://github.com/gnustep/libobjc2/commit/eab35fce379eb6ab1423dbb6d7908cb782f13458#diff-7f1eea7fdb5c7c3bf21f08d1cfe98a19

Reintroducing the 'static' on deallocCalled reduces the test
case to
unconditionally failing the assert immediately after the pop,
and DCEs
the rest of the code.

David

On 11/09/2019 01:17, Alina Sbirlea wrote:
 > Hi David,
 >
 > Does this still reproduce?
 > I'm seeing the load after the call to autoreleasePoolPop at
ToT, but
 > perhaps I'm not using the proper flags?
 > I only checked out the github repo and did "clang
 > -fobjc-runtime=gnustep-2.0 -O3 -emit-llvm -S
 > libobjc2/Test/AssociatedObject.m" with a ToT clang.
 >
 > Thanks,
 > Alina
 >
 >
 > On Sun, Feb 24, 2019 at 9:56 AM Pete Cooper via llvm-commits
 > mailto:llvm-comm...@lists.llvm.org>
>> wrote:
 >
 >     Hey David
 >
 >     Thanks for letting me know, and analysing it this far!
 >
 >     I also can't see anything wrong with the intrinsic.  Its just
 >     defined as:
 >
 >         def int_objc_autoreleasePoolPop             :
Intrinsic<[],
 >         [llvm_ptr_ty]>;
 >
 >
 >     which (I believe) means it has unmodelled side effects so
it should
 >     have been fine for your example.
 >
 >     I'll try build the same file you did and see if I can
reproduce.
 >

Re: [PATCH] D55802: Change CGObjC to use objc intrinsics instead of runtime methods

2019-09-30 Thread David Chisnall via cfe-commits

Hi,

Yes, I believe it does still reproduce (at least, with the most recent 
build that I tried).  We worked around the clang bug to make the test pass:


https://github.com/gnustep/libobjc2/commit/eab35fce379eb6ab1423dbb6d7908cb782f13458#diff-7f1eea7fdb5c7c3bf21f08d1cfe98a19

Reintroducing the 'static' on deallocCalled reduces the test case to 
unconditionally failing the assert immediately after the pop, and DCEs 
the rest of the code.


David

On 11/09/2019 01:17, Alina Sbirlea wrote:

Hi David,

Does this still reproduce?
I'm seeing the load after the call to autoreleasePoolPop at ToT, but 
perhaps I'm not using the proper flags?
I only checked out the github repo and did "clang 
-fobjc-runtime=gnustep-2.0 -O3 -emit-llvm -S 
libobjc2/Test/AssociatedObject.m" with a ToT clang.


Thanks,
Alina


On Sun, Feb 24, 2019 at 9:56 AM Pete Cooper via llvm-commits 
mailto:llvm-comm...@lists.llvm.org>> wrote:


Hey David

Thanks for letting me know, and analysing it this far!

I also can't see anything wrong with the intrinsic.  Its just
defined as:

def int_objc_autoreleasePoolPop             : Intrinsic<[],
[llvm_ptr_ty]>;


which (I believe) means it has unmodelled side effects so it should
have been fine for your example.

I'll try build the same file you did and see if I can reproduce.

Cheers,
Pete


On Feb 24, 2019, at 7:48 AM, David Chisnall via Phabricator
mailto:revi...@reviews.llvm.org>> wrote:

theraven added a comment.
Herald added a project: LLVM.

After some bisection, it appears that this is the revision that
introduced the regression in the GNUstep Objective-C runtime test
suite that I reported on the list a few weeks ago.  In this is the
test (compiled with `-fobjc-runtime=gnustep-2.0 -O3` and an ELF
triple):

https://github.com/gnustep/libobjc2/blob/master/Test/AssociatedObject.m

After this change, Early CSE w/ MemorySSA is determining that the
second load of `deallocCalled` is redundant.  The code goes from:

   %7 = load i1, i1* @deallocCalled, align 1
   br i1 %7, label %8, label %9

 ; :8:  ; preds = %0
   call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x
i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds
([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 26, i8*
getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64
0)) #5
   unreachable

 ; :9:  ; preds = %0
   call void @llvm.objc.autoreleasePoolPop(i8* %1)
   %10 = load i1, i1* @deallocCalled, align 1
   br i1 %10, label %12, label %11

 ; :11: ; preds = %9
   call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x
i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds
([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 29, i8*
getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64
0)) #5
   unreachable

to:

   %7 = load i1, i1* @deallocCalled, align 1
   br i1 %7, label %8, label %9

 ; :8:  ; preds = %0
   call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x
i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds
([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 26, i8*
getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64
0)) #5
   unreachable

 ; :9:  ; preds = %0
   call void @llvm.objc.autoreleasePoolPop(i8* %1)
   br i1 %7, label %11, label %10

 ; :10: ; preds = %9
   call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x
i8]* @__func__.main, i64 0, i64 0), i8* getelementptr inbounds
([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 29, i8*
getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64
0)) #5
   unreachable

Later optimisations then determine that, because the assert does
not return, the only possible value for %7 is false and cause the
second assert to fire unconditionally.

It appears that we are not correctly modelling the side effects of
the `llvm.objc.autoreleasePoolPop` intrinsic, but it's not
entirely clear why not.  The same test compiled for the macos
runtime does not appear to exhibit the same behaviour.  The
previous revision, where we emitted a call to
`objc_autoreleasePoolPop` and not the intrinsic worked correctly,
but with this change the optimisers are assuming that no globals
can be modified across an autorelease pool pop operation (at
least, in some situations).

Looking at the definition of the intrinsic, I don't see anything
wrong, so I still suspect that there is a MemorySSA bug that this
has uncovered, rather than anything wrong in this series of
commits.  Any sugge

r357363 - COMDAT-fold block descriptors.

2019-03-31 Thread David Chisnall via cfe-commits
Author: theraven
Date: Sun Mar 31 04:22:26 2019
New Revision: 357363

URL: http://llvm.org/viewvc/llvm-project?rev=357363&view=rev
Log:
COMDAT-fold block descriptors.

Without this change, linking multiple objects containing block
descriptors together on Windows will generate duplicate symbol errors.

Patch by Dustin Howett!

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

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGenObjC/block-desc-str.m

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=357363&r1=357362&r2=357363&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Sun Mar 31 04:22:26 2019
@@ -274,6 +274,8 @@ static llvm::Constant *buildBlockDescrip
  /*constant*/ true, linkage, AddrSpace);
 
   if (linkage == llvm::GlobalValue::LinkOnceODRLinkage) {
+if (CGM.supportsCOMDAT())
+  global->setComdat(CGM.getModule().getOrInsertComdat(descName));
 global->setVisibility(llvm::GlobalValue::HiddenVisibility);
 global->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
   }

Modified: cfe/trunk/test/CodeGenObjC/block-desc-str.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/block-desc-str.m?rev=357363&r1=357362&r2=357363&view=diff
==
--- cfe/trunk/test/CodeGenObjC/block-desc-str.m (original)
+++ cfe/trunk/test/CodeGenObjC/block-desc-str.m Sun Mar 31 04:22:26 2019
@@ -1,9 +1,13 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm 
-fobjc-runtime=gnustep-1.7 -fblocks -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc 
-fblocks -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -emit-llvm 
-fobjc-runtime=gnustep-1.7 -fblocks -o - %s | FileCheck 
--check-prefix=CHECK-COMDAT %s
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -fobjc-runtime=gcc 
-fblocks -o - %s | FileCheck --check-prefix=CHECK-COMDAT %s
 // RUN: %clang_cc1 -triple=x86_64-apple-darwin10 -emit-llvm -fblocks -o - %s | 
FileCheck %s
 
 // Test that descriptor symbol names don't include '@'.
 
+// CHECK-COMDAT: $"__block_descriptor_40_8_32o_e5_v8\01?0l" = comdat any
+// CHECK-COMDAT: @[[STR:.*]] = private unnamed_addr constant [6 x i8] 
c"v8@?0\00"
+// CHECK-COMDAT: @"__block_descriptor_40_8_32o_e5_v8\01?0l" = linkonce_odr 
hidden unnamed_addr constant { i64, i64, i8*, i8*, i8*, {{.*}} } { i64 0, i64 
40, i8* bitcast ({{.*}} to i8*), i8* bitcast ({{.*}} to i8*), i8* getelementptr 
inbounds ([6 x i8], [6 x i8]* @[[STR]], i32 0, i32 0), {{.*}} }, comdat, align 8
+
 // CHECK: @[[STR:.*]] = private unnamed_addr constant [6 x i8] c"v8@?0\00"
 // CHECK: @"__block_descriptor_40_8_32o_e5_v8\01?0l" = linkonce_odr hidden 
unnamed_addr constant { i64, i64, i8*, i8*, i8*, {{.*}} } { i64 0, i64 40, i8* 
bitcast ({{.*}} to i8*), i8* bitcast ({{.*}} to i8*), i8* getelementptr 
inbounds ([6 x i8], [6 x i8]* @[[STR]], i32 0, i32 0), {{.*}} }, align 8
 


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


r357364 - [gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs.

2019-03-31 Thread David Chisnall via cfe-commits
Author: theraven
Date: Sun Mar 31 04:22:33 2019
New Revision: 357364

URL: http://llvm.org/viewvc/llvm-project?rev=357364&view=rev
Log:
[gnustep-objc] Make the GNUstep v2 ABI work for Windows DLLs.

Summary:
Based on a patch by Dustin Howett, modified to not change the ABI for
ELF platforms.

Use more Windows-like section names.

This also makes things more readable by PE/COFF debug tools that assume
sections fit in the first header.

With these changes in, it is now possible to build a working WinObjC
with clang and the WinObjC version of GNUstep libobjc (upstream GNUstep
libobjc + a work around for incremental linking, which can be removed
once LINK.EXE gains a feature to opt sections out of receiving extra
padding during an incremental link).

Patch by Dustin Howett!

Reviewers: DHowett-MSFT

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/test/CodeGenObjC/gnu-init.m

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=357364&r1=357363&r2=357364&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Mar 31 04:22:33 2019
@@ -185,12 +185,16 @@ protected:
   (R.getVersion() >= VersionTuple(major, minor));
   }
 
-  std::string SymbolForProtocol(StringRef Name) {
-return (StringRef("._OBJC_PROTOCOL_") + Name).str();
+  std::string ManglePublicSymbol(StringRef Name) {
+return (StringRef(CGM.getTriple().isOSBinFormatCOFF() ? "$_" : "._") + 
Name).str();
+  }
+
+  std::string SymbolForProtocol(Twine Name) {
+return (ManglePublicSymbol("OBJC_PROTOCOL_") + Name).str();
   }
 
   std::string SymbolForProtocolRef(StringRef Name) {
-return (StringRef("._OBJC_REF_PROTOCOL_") + Name).str();
+return (ManglePublicSymbol("OBJC_REF_PROTOCOL_") + Name).str();
   }
 
 
@@ -906,12 +910,15 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 ConstantStringSection
   };
   static const char *const SectionsBaseNames[8];
+  static const char *const PECOFFSectionsBaseNames[8];
   template
   std::string sectionName() {
-std::string name(SectionsBaseNames[K]);
-if (CGM.getTriple().isOSBinFormatCOFF())
+if (CGM.getTriple().isOSBinFormatCOFF()) {
+  std::string name(PECOFFSectionsBaseNames[K]);
   name += "$m";
-return name;
+  return name;
+}
+return SectionsBaseNames[K];
   }
   /// The GCC ABI superclass message lookup function.  Takes a pointer to a
   /// structure describing the receiver and the class, and a selector as
@@ -932,15 +939,19 @@ class CGObjCGNUstep2 : public CGObjCGNUs
   bool EmittedClass = false;
   /// Generate the name of a symbol for a reference to a class.  Accesses to
   /// classes should be indirected via this.
+
+  typedef std::pair> 
EarlyInitPair;
+  std::vector EarlyInitList;
+
   std::string SymbolForClassRef(StringRef Name, bool isWeak) {
 if (isWeak)
-  return (StringRef("._OBJC_WEAK_REF_CLASS_") + Name).str();
+  return (ManglePublicSymbol("OBJC_WEAK_REF_CLASS_") + Name).str();
 else
-  return (StringRef("._OBJC_REF_CLASS_") + Name).str();
+  return (ManglePublicSymbol("OBJC_REF_CLASS_") + Name).str();
   }
   /// Generate the name of a class symbol.
   std::string SymbolForClass(StringRef Name) {
-return (StringRef("._OBJC_CLASS_") + Name).str();
+return (ManglePublicSymbol("OBJC_CLASS_") + Name).str();
   }
   void CallRuntimeFunction(CGBuilderTy &B, StringRef FunctionName,
   ArrayRef Args) {
@@ -994,10 +1005,13 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 
 llvm::Constant *isa = TheModule.getNamedGlobal(Sym);
 
-if (!isa)
+if (!isa) {
   isa = new llvm::GlobalVariable(TheModule, IdTy, /* isConstant */false,
   llvm::GlobalValue::ExternalLinkage, nullptr, Sym);
-else if (isa->getType() != PtrToIdTy)
+  if (CGM.getTriple().isOSBinFormatCOFF()) {
+
cast(isa)->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  }
+} else if (isa->getType() != PtrToIdTy)
   isa = llvm::ConstantExpr::getBitCast(isa, PtrToIdTy);
 
 //  struct
@@ -1012,7 +1026,11 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 
 ConstantInitBuilder Builder(CGM);
 auto Fields = Builder.beginStruct();
-Fields.add(isa);
+if (!CGM.getTriple().isOSBinFormatCOFF()) {
+  Fields.add(isa);
+} else {
+  Fields.addNullPointer(PtrTy);
+}
 // For now, all non-ASCII strings are represented as UTF-16.  As such, the
 // number of bytes is simply double the number of UTF-16 codepoints.  In
 // ASCII strings, the number of bytes is equal to the number of non-ASCII
@@ -1083,6 +1101,10 @@ class CGObjCGNUstep2 : public CGObjCGNUs
   ObjCStrGV->setComdat(TheModule.getOrInsertComdat(StringName));
   ObjCStrGV->setVisibility(llvm::Globa

r357362 - [objc-gnustep] Use .init_array not .ctors when requested.

2019-03-31 Thread David Chisnall via cfe-commits
Author: theraven
Date: Sun Mar 31 04:22:19 2019
New Revision: 357362

URL: http://llvm.org/viewvc/llvm-project?rev=357362&view=rev
Log:
[objc-gnustep] Use .init_array not .ctors when requested.

This doesn't make a difference most of the time but FreeBSD/ARM doesn't
run anything in the .ctors array.

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/test/CodeGenObjC/gnu-init.m

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=357362&r1=357361&r2=357362&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Mar 31 04:22:19 2019
@@ -1514,7 +1514,12 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 if (CGM.getTriple().isOSBinFormatCOFF())
 InitVar->setSection(".CRT$XCLz");
 else
-  InitVar->setSection(".ctors");
+{
+  if (CGM.getCodeGenOpts().UseInitArray)
+InitVar->setSection(".init_array");
+  else
+InitVar->setSection(".ctors");
+}
 InitVar->setVisibility(llvm::GlobalValue::HiddenVisibility);
 InitVar->setComdat(TheModule.getOrInsertComdat(".objc_ctor"));
 CGM.addUsedGlobal(InitVar);

Modified: cfe/trunk/test/CodeGenObjC/gnu-init.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-init.m?rev=357362&r1=357361&r2=357362&view=diff
==
--- cfe/trunk/test/CodeGenObjC/gnu-init.m (original)
+++ cfe/trunk/test/CodeGenObjC/gnu-init.m Sun Mar 31 04:22:19 2019
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-NEW
 // RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -S -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s -check-prefix=CHECK-WIN
 // RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm 
-fobjc-runtime=gnustep-1.8 -o - %s | FileCheck %s -check-prefix=CHECK-OLD
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -fuse-init-array -S 
-emit-llvm -fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s 
-check-prefix=CHECK-INIT_ARRAY
 
 // Almost minimal Objective-C file, check that it emits calls to the correct
 // runtime entry points.
@@ -39,6 +40,7 @@
 
 // Check that the load function is manually inserted into .ctors.
 // CHECK-NEW: @.objc_ctor = linkonce hidden constant void ()* 
@.objcv2_load_function, section ".ctors", comdat
+// CHECK-INIT_ARRAY: @.objc_ctor = linkonce hidden constant void ()* 
@.objcv2_load_function, section ".init_array", comdat
 
 
 // Make sure that we provide null versions of everything so the __start /


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


r352995 - [objc-gnustep] Fix encoding of ivar size for _Bool.

2019-02-03 Thread David Chisnall via cfe-commits
Author: theraven
Date: Sun Feb  3 07:05:52 2019
New Revision: 352995

URL: http://llvm.org/viewvc/llvm-project?rev=352995&view=rev
Log:
[objc-gnustep] Fix encoding of ivar size for _Bool.

Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=352995&r1=352994&r2=352995&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sun Feb  3 07:05:52 2019
@@ -1728,7 +1728,6 @@ class CGObjCGNUstep2 : public CGObjCGNUs
   CGM.getContext().getCharWidth());
   // struct objc_ivar ivars[]
   auto ivarArrayBuilder = ivarListBuilder.beginArray();
-  CodeGenTypes &Types = CGM.getTypes();
   for (const ObjCIvarDecl *IVD = classDecl->all_declared_ivar_begin(); IVD;
IVD = IVD->getNextIvar()) {
 auto ivarTy = IVD->getType();
@@ -1762,8 +1761,7 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 ivarBuilder.add(OffsetVar);
 // Ivar size
 ivarBuilder.addInt(Int32Ty,
-td.getTypeSizeInBits(Types.ConvertType(ivarTy)) /
-  CGM.getContext().getCharWidth());
+CGM.getContext().getTypeSizeInChars(ivarTy).getQuantity());
 // Alignment will be stored as a base-2 log of the alignment.
 int align = 
llvm::Log2_32(Context.getTypeAlignInChars(ivarTy).getQuantity());
 // Objects that require more than 2^64-byte alignment should be 
impossible!

Modified: cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m?rev=352995&r1=352994&r2=352995&view=diff
==
--- cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m (original)
+++ cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m Sun Feb  3 07:05:52 2019
@@ -19,10 +19,12 @@
 @package
 // CHECK: @__objc_ivar_offset_ANObject._intIvar.i = hidden global i32 16
   int _intIvar;
+  _Bool   boolIvar;
 }
 @end
 @implementation ANObject @end
 
 // Check that the ivar metadata contains 3 entries of the correct form and 
correctly sets the size.
-// CHECK: @.objc_ivar_list = private global { i32, i64, [3 x { i8*, i8*, i32*, 
i32, i32 }] } { i32 3, i64 32,
-// Check that we're emitting the extended type encoding for the string ivar.
+// CHECK: @.objc_ivar_list = private global { i32, i64, [4 x { i8*, i8*, i32*, 
i32, i32 }] } { i32 4, i64 32,
+// Check that we emit 1 as the size of _Bool, not 0.
+// CHECK-SAME:  @__objc_ivar_offset_ANObject.boolIvar.B, i32 1, i32 4


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


r350130 - [objc-gnustep2] Fix a bug in category generation.

2018-12-28 Thread David Chisnall via cfe-commits
Author: theraven
Date: Fri Dec 28 09:44:54 2018
New Revision: 350130

URL: http://llvm.org/viewvc/llvm-project?rev=350130&view=rev
Log:
[objc-gnustep2] Fix a bug in category generation.

We were not emitting a protocol definition while generating the category
method list.  This was fine in most cases, because something else in the
library typically referenced any given protocol, but it caused linker
failures if the category was the only reference to a given protocol.

Added:
cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=350130&r1=350129&r2=350130&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Fri Dec 28 09:44:54 2018
@@ -277,6 +277,8 @@ protected:
 Fields.addInt(Int8Ty, 0);
   }
 
+  virtual llvm::Constant *GenerateCategoryProtocolList(const
+  ObjCCategoryDecl *OCD);
   virtual ConstantArrayBuilder PushPropertyListHeader(ConstantStructBuilder 
&Fields,
   int count) {
   // int count;
@@ -1164,6 +1166,15 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 return MethodList.finishAndCreateGlobal(".objc_protocol_method_list",
 CGM.getPointerAlign());
   }
+  llvm::Constant *GenerateCategoryProtocolList(const ObjCCategoryDecl *OCD)
+override {
+SmallVector Protocols;
+for (const auto *PI : OCD->getReferencedProtocols())
+  Protocols.push_back(
+  llvm::ConstantExpr::getBitCast(GenerateProtocolRef(PI),
+ProtocolPtrTy));
+return GenerateProtocolList(Protocols);
+  }
 
   llvm::Value *LookupIMPSuper(CodeGenFunction &CGF, Address ObjCSuper,
   llvm::Value *cmd, MessageSendInfo &MSI) override 
{
@@ -3099,18 +3110,21 @@ llvm::Constant *CGObjCGNU::MakeBitField(
   return ptr;
 }
 
+llvm::Constant *CGObjCGNU::GenerateCategoryProtocolList(const
+ObjCCategoryDecl *OCD) {
+  SmallVector Protocols;
+  for (const auto *PD : OCD->getReferencedProtocols())
+Protocols.push_back(PD->getNameAsString());
+  return GenerateProtocolList(Protocols);
+}
+
 void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) {
   const ObjCInterfaceDecl *Class = OCD->getClassInterface();
   std::string ClassName = Class->getNameAsString();
   std::string CategoryName = OCD->getNameAsString();
 
   // Collect the names of referenced protocols
-  SmallVector Protocols;
   const ObjCCategoryDecl *CatDecl = OCD->getCategoryDecl();
-  const ObjCList &Protos = CatDecl->getReferencedProtocols();
-  for (ObjCList::iterator I = Protos.begin(),
-   E = Protos.end(); I != E; ++I)
-Protocols.push_back((*I)->getNameAsString());
 
   ConstantInitBuilder Builder(CGM);
   auto Elements = Builder.beginStruct();
@@ -3132,7 +3146,7 @@ void CGObjCGNU::GenerateCategory(const O
   GenerateMethodList(ClassName, CategoryName, ClassMethods, true),
   PtrTy);
   // Protocol list
-  Elements.addBitCast(GenerateProtocolList(Protocols), PtrTy);
+  Elements.addBitCast(GenerateCategoryProtocolList(CatDecl), PtrTy);
   if (isRuntime(ObjCRuntime::GNUstep, 2)) {
 const ObjCCategoryDecl *Category =
   Class->FindCategoryDeclaration(OCD->getIdentifier());

Added: cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m?rev=350130&view=auto
==
--- cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m (added)
+++ cfe/trunk/test/CodeGenObjC/gnustep2-category-protocol.m Fri Dec 28 09:44:54 
2018
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -S -emit-llvm 
-fobjc-runtime=gnustep-2.0 -o - %s | FileCheck %s
+
+// Regression test.  We weren't emitting definitions for protocols used in
+// categories, causing linker errors when the category was the only reference
+// to a protocol in a binary.
+
+// CHECK: @._OBJC_PROTOCOL_Y = global 
+// CHEKC-SAME: section "__objc_protocols", comdat, align 8
+
+
+@interface X
+{
+id isa;
+}
+@end
+@implementation X
+@end
+
+@protocol Y @end
+
+@interface X (y) 
+@end
+@implementation X (y) @end
+
+


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


r350092 - [objc-gnustep] Fix a copy-and-paste error.

2018-12-27 Thread David Chisnall via cfe-commits
Author: theraven
Date: Thu Dec 27 06:44:36 2018
New Revision: 350092

URL: http://llvm.org/viewvc/llvm-project?rev=350092&view=rev
Log:
[objc-gnustep] Fix a copy-and-paste error.

We were emitting the null class symbol in the wrong section, which meant
that programs that contained no Objective-C classes would fail to link.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=350092&r1=350091&r2=350092&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Thu Dec 27 06:44:36 2018
@@ -1547,7 +1547,7 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 sectionName());
   if (!EmittedClass) {
 createNullGlobal(".objc_null_cls_init_ref", NULLPtr,
-sectionName());
+sectionName());
 createNullGlobal(".objc_null_class_ref", { NULLPtr, NULLPtr },
 sectionName());
   }


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


r341352 - Revert "Disable the GNUstep v2 ABI on Windows."

2018-09-04 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue Sep  4 03:07:27 2018
New Revision: 341352

URL: http://llvm.org/viewvc/llvm-project?rev=341352&view=rev
Log:
Revert "Disable the GNUstep v2 ABI on Windows."

This reverts commit b4547c9cadd2f8adfe3f3182e4c56e466c5256cb.

Apparently git llvm push from the monorepo does not respect branches and
pushes the current branch to master.

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341352&r1=341351&r2=341352&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Sep  4 03:07:27 2018
@@ -4949,7 +4949,8 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(co
 }
 if ((runtime.getKind() == ObjCRuntime::GNUstep) &&
 (runtime.getVersion() >= VersionTuple(2, 0)))
-  if (!getToolChain().getTriple().isOSBinFormatELF()) {
+  if (!getToolChain().getTriple().isOSBinFormatELF() &&
+  !getToolChain().getTriple().isOSBinFormatCOFF()) {
 getToolChain().getDriver().Diag(
 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
   << runtime.getVersion().getMajor();


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


r341350 - Disable the GNUstep v2 ABI on Windows.

2018-09-04 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue Sep  4 02:23:18 2018
New Revision: 341350

URL: http://llvm.org/viewvc/llvm-project?rev=341350&view=rev
Log:
Disable the GNUstep v2 ABI on Windows.

The code remains so that we can potentially reenable it in a point
release, but the driver will reject it.  Several issues were raised
during testing that made it clear that this was not quite ready for
general consumption.

Approved by: Hans Wennborg

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

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=341350&r1=341349&r2=341350&view=diff
==
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Sep  4 02:23:18 2018
@@ -4949,8 +4949,7 @@ ObjCRuntime Clang::AddObjCRuntimeArgs(co
 }
 if ((runtime.getKind() == ObjCRuntime::GNUstep) &&
 (runtime.getVersion() >= VersionTuple(2, 0)))
-  if (!getToolChain().getTriple().isOSBinFormatELF() &&
-  !getToolChain().getTriple().isOSBinFormatCOFF()) {
+  if (!getToolChain().getTriple().isOSBinFormatELF()) {
 getToolChain().getDriver().Diag(
 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
   << runtime.getVersion().getMajor();


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


r339668 - [gnu-objc] Make selector order deterministic.

2018-08-14 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue Aug 14 03:05:25 2018
New Revision: 339668

URL: http://llvm.org/viewvc/llvm-project?rev=339668&view=rev
Log:
[gnu-objc] Make selector order deterministic.

Summary:
This probably fixes PR35277, though there may be other sources of
nondeterminism (this was the only case of iterating over a DenseMap).

It's difficult to provide a test case for this, because it shows up only
on systems with ASLR enabled.

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: bmwiedemann, mgrang, cfe-commits

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

Added:
cfe/trunk/test/CodeGenObjC/gnu-deterministic-selectors.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=339668&r1=339667&r2=339668&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Aug 14 03:05:25 2018
@@ -3541,12 +3541,16 @@ llvm::Function *CGObjCGNU::ModuleInitFun
 ConstantInitBuilder builder(CGM);
 auto selectors = builder.beginArray(selStructTy);
 auto &table = SelectorTable; // MSVC workaround
-for (auto &entry : table) {
+std::vector allSelectors;
+for (auto &entry : table)
+  allSelectors.push_back(entry.first);
+llvm::sort(allSelectors.begin(), allSelectors.end());
 
-  std::string selNameStr = entry.first.getAsString();
+for (auto &untypedSel : allSelectors) {
+  std::string selNameStr = untypedSel.getAsString();
   llvm::Constant *selName = ExportUniqueString(selNameStr, 
".objc_sel_name");
 
-  for (TypedSelector &sel : entry.second) {
+  for (TypedSelector &sel : table[untypedSel]) {
 llvm::Constant *selectorTypeEncoding = NULLPtr;
 if (!sel.first.empty())
   selectorTypeEncoding =

Added: cfe/trunk/test/CodeGenObjC/gnu-deterministic-selectors.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-deterministic-selectors.m?rev=339668&view=auto
==
--- cfe/trunk/test/CodeGenObjC/gnu-deterministic-selectors.m (added)
+++ cfe/trunk/test/CodeGenObjC/gnu-deterministic-selectors.m Tue Aug 14 
03:05:25 2018
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -fobjc-runtime=gnustep-1.5 
%s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -fobjc-runtime=gcc %s 
-emit-llvm -o - | FileCheck %s
+
+// Check that these selectors are emitted in alphabetical order.
+// The order doesn't actually matter, only that it doesn't vary across runs.
+// Clang sorts them when targeting a GCC-like ABI to guarantee determinism.
+// CHECK: @.objc_selector_list = internal global [6 x { i8*, i8* }] [{ i8*, 
i8* } { i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.objc_sel_namea, i64 
0, i64 0), i8* null }, { i8*, i8* } { i8* getelementptr inbounds ([2 x i8], [2 
x i8]* @.objc_sel_nameg, i64 0, i64 0), i8* null }, { i8*, i8* } { i8* 
getelementptr inbounds ([2 x i8], [2 x i8]* @.objc_sel_namej, i64 0, i64 0), 
i8* null }, { i8*, i8* } { i8* getelementptr inbounds ([2 x i8], [2 x i8]* 
@.objc_sel_namel, i64 0, i64 0), i8* null }, { i8*, i8* } { i8* getelementptr 
inbounds ([2 x i8], [2 x i8]* @.objc_sel_namez, i64 0, i64 0), i8* null }, { 
i8*, i8* } zeroinitializer], align 8
+
+
+void f() {
+   SEL a = @selector(z);
+   SEL b = @selector(a);
+   SEL c = @selector(g);
+   SEL d = @selector(l);
+   SEL e = @selector(j);
+}


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


r339667 - Add a stub mangling for ObjC selectors in the Microsoft ABI.

2018-08-14 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue Aug 14 03:04:36 2018
New Revision: 339667

URL: http://llvm.org/viewvc/llvm-project?rev=339667&view=rev
Log:
Add a stub mangling for ObjC selectors in the Microsoft ABI.

This mangling is used only for outlined SEH finally blocks, which have
internal linkage.

This fixes the failure of CodeGenObjC/2007-04-03-ObjcEH.m on builds with
expensive checks enabled, on Windows.  This test should probably be
specifying a triple: it currently picks up whatever the host environment
is using.  Unfortunately, I have no idea what it is trying to test,
because it contains no comments and predates Clang having working
Objective-C IR generation.

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=339667&r1=339666&r2=339667&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Tue Aug 14 03:04:36 2018
@@ -905,8 +905,14 @@ void MicrosoftCXXNameMangler::mangleUnqu
 
 case DeclarationName::ObjCZeroArgSelector:
 case DeclarationName::ObjCOneArgSelector:
-case DeclarationName::ObjCMultiArgSelector:
-  llvm_unreachable("Can't mangle Objective-C selector names here!");
+case DeclarationName::ObjCMultiArgSelector: {
+  // This is reachable only when constructing an outlined SEH finally
+  // block.  Nothing depends on this mangling and it's used only with
+  // functinos with internal linkage.
+  llvm::SmallString<64> Name;
+  mangleSourceName(Name.str());
+  break;
+}
 
 case DeclarationName::CXXConstructorName:
   if (isStructorDecl(ND)) {


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


Re: r339428 - Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-11 Thread David Chisnall via cfe-commits
Thanks,

That fix looks exactly what is needed - and is something I didn’t realise 
FileCheck could do!  The order of those matters in the linked binary, but not 
in the IR - the linker will arrange them sensibly based on the subsection name.

Thanks again,

David

> On 11 Aug 2018, at 04:12,   
> wrote:
> 
> Hi David,
>  
> I made an attempt to fix the Windows bot test failures in r339494 by making 
> the checks for the section boundaries not depend on the order they were 
> emitted.
>  
> It seems that when using Visual Studio to build clang, the compiler that is 
> generated emits the __stop_ section boundaries before the __start_ ones, thus 
> causing your checks to fail. For example, you were checking for the following:
>  
> @__start___objc_selectors = linkonce_odr hidden global 
> %.objc_section_sentinel zeroinitializer, section "__objc_selectors$a", 
> comdat, align 1
> @__stop__objc_selectors = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_selectors$z", comdat, align 1
> @__start___objc_classes = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_classes$a", comdat, align 1
> @__stop__objc_classes = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_classes$z", comdat, align 1
>  
> However the Visual Studio built clang was producing the following output:
>  
> @__stop__objc_selectors = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_selectors$z", comdat, align 1
> @__start___objc_selectors = linkonce_odr hidden global 
> %.objc_section_sentinel zeroinitializer, section "__objc_selectors$a", 
> comdat, align 1
> @__stop__objc_classes = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_classes$z", comdat, align 1
> @__start___objc_classes = linkonce_odr hidden global %.objc_section_sentinel 
> zeroinitializer, section "__objc_classes$a", comdat, align 1
>  
> I don’t think that the order matters, only that they are actually emitted, 
> but if I am wrong, I apologize, and please revert my change and look into the 
> problem.
>  
> Douglas Yung
>  
> From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf Of 
> Tom Weaver via cfe-commits
> Sent: Friday, August 10, 2018 10:01
> To: David Chisnall
> Cc: cfe-commits@lists.llvm.org
> Subject: Re: r339428 - Add Windows support for the GNUstep Objective-C ABI V2.
>  
> Hi David,
>  
> revision 339428 seems to have caused failing tests on a couple of windows 
> build bots, any chance you can take a look please?
>  
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/18985
>  
> ****
> Failing Tests (1):
> Clang :: CodeGenObjC/gnu-init.m
>  
>   Expected Passes: 30627
>   Expected Failures  : 65
>   Unsupported Tests  : 12223
>   Unexpected Failures: 1
>  
> Thanks
>  
> Tom Weaver
>  
> On 10 August 2018 at 13:53, David Chisnall via cfe-commits 
>  wrote:
> Author: theraven
> Date: Fri Aug 10 05:53:13 2018
> New Revision: 339428
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=339428&view=rev
> Log:
> Add Windows support for the GNUstep Objective-C ABI V2.
> 
> Summary:
> Introduces funclet-based unwinding for Objective-C and fixes an issue
> where global blocks can't have their isa pointers initialised on
> Windows.
> 
> After discussion with Dustin, this changes the name mangling of
> Objective-C types to prevent a C++ catch statement of type struct X*
> from catching an Objective-C object of type X*.
> 
> Reviewers: rjmccall, DHowett-MSFT
> 
> Reviewed By: rjmccall, DHowett-MSFT
> 
> Subscribers: mgrang, mstorsjo, smeenai, cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D50144
> 
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/lib/CodeGen/CGException.cpp
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.h
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/test/CodeGenObjC/gnu-init.m
> cfe/trunk/test/CodeGenObjC/gnustep2-proto.m
> cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
> cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm
> 
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> ht

Re: r339428 - Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-10 Thread David Chisnall via cfe-commits
Hi Tom,

I’ll take a look over the weekend and see if I can reproduce locally.  It’s odd 
that a test for a Windows triple would be behaving differently on a Windows 
host.

David

> On 10 Aug 2018, at 18:01, Tom Weaver  wrote:
> 
> Hi David,
> 
> revision 339428 seems to have caused failing tests on a couple of windows 
> build bots, any chance you can take a look please?
> 
> http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/18985
> 
> 
> Failing Tests (1):
> Clang :: CodeGenObjC/gnu-init.m
> 
>   Expected Passes: 30627
>   Expected Failures  : 65
>   Unsupported Tests  : 12223
>   Unexpected Failures: 1
> 
> 
> Thanks
> 
> Tom Weaver
> 
> On 10 August 2018 at 13:53, David Chisnall via cfe-commits 
>  wrote:
> Author: theraven
> Date: Fri Aug 10 05:53:13 2018
> New Revision: 339428
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=339428&view=rev
> Log:
> Add Windows support for the GNUstep Objective-C ABI V2.
> 
> Summary:
> Introduces funclet-based unwinding for Objective-C and fixes an issue
> where global blocks can't have their isa pointers initialised on
> Windows.
> 
> After discussion with Dustin, this changes the name mangling of
> Objective-C types to prevent a C++ catch statement of type struct X*
> from catching an Objective-C object of type X*.
> 
> Reviewers: rjmccall, DHowett-MSFT
> 
> Reviewed By: rjmccall, DHowett-MSFT
> 
> Subscribers: mgrang, mstorsjo, smeenai, cfe-commits
> 
> Differential Revision: https://reviews.llvm.org/D50144
> 
> Modified:
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/lib/AST/MicrosoftMangle.cpp
> cfe/trunk/lib/CodeGen/CGException.cpp
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
> cfe/trunk/lib/CodeGen/CGObjCRuntime.h
> cfe/trunk/lib/CodeGen/CodeGenFunction.h
> cfe/trunk/lib/Driver/ToolChains/Clang.cpp
> cfe/trunk/test/CodeGenObjC/gnu-init.m
> cfe/trunk/test/CodeGenObjC/gnustep2-proto.m
> cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
> cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
> cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm
> 
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=339428&r1=339427&r2=339428&view=diff
> ==
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 10 05:53:13 2018
> @@ -1488,7 +1488,7 @@ def fobjc_weak : Flag<["-"], "fobjc-weak
>HelpText<"Enable ARC-style weak references in Objective-C">;
> 
>  // Objective-C ABI options.
> -def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group, 
> Flags<[CC1Option]>,
> +def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group, 
> Flags<[CC1Option, CoreOption]>,
>HelpText<"Specify the target Objective-C runtime kind and version">;
>  def fobjc_abi_version_EQ : Joined<["-"], "fobjc-abi-version=">, 
> Group;
>  def fobjc_nonfragile_abi_version_EQ : Joined<["-"], 
> "fobjc-nonfragile-abi-version=">, Group;
> 
> Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=339428&r1=339427&r2=339428&view=diff
> ==
> --- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
> +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Aug 10 05:53:13 2018
> @@ -445,7 +445,7 @@ void MicrosoftCXXNameMangler::mangle(con
>  mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
>else if (const VarDecl *VD = dyn_cast(D))
>  mangleVariableEncoding(VD);
> -  else
> +  else if (!isa(D))
>  llvm_unreachable("Tried to mangle unexpected NamedDecl!");
>  }
> 
> @@ -1884,13 +1884,13 @@ void MicrosoftCXXNameMangler::mangleType
>  llvm_unreachable("placeholder types shouldn't get to name mangling");
> 
>case BuiltinType::ObjCId:
> -mangleArtificalTagType(TTK_Struct, "objc_object");
> +mangleArtificalTagType(TTK_Struct, ".objc_object");
>  break;
>case BuiltinType::ObjCClass:
> -mangleArtificalTagType(TTK_Struct, "objc_class");
> +mangleArtificalTagType(TTK_Struct,

r339429 - Fix a deprecated warning in the last commit.

2018-08-10 Thread David Chisnall via cfe-commits
Author: theraven
Date: Fri Aug 10 05:53:18 2018
New Revision: 339429

URL: http://llvm.org/viewvc/llvm-project?rev=339429&view=rev
Log:
Fix a deprecated warning in the last commit.

Done as a separate commit to make it easier to cherry pick the changes
to the release branch.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp?rev=339429&r1=339428&r2=339429&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp Fri Aug 10 05:53:18 2018
@@ -205,7 +205,7 @@ void CGObjCRuntime::EmitTryCatchStmt(Cod
 // Emit the original filter expression, convert to i32, and return.
 HelperCGF.EmitStmt(FinallyBlock);
 
-HelperCGF.FinishFunction(FinallyBlock->getLocEnd());
+HelperCGF.FinishFunction(FinallyBlock->getEndLoc());
 
 llvm::Function *FinallyFunc = HelperCGF.CurFn;
 


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


r339428 - Add Windows support for the GNUstep Objective-C ABI V2.

2018-08-10 Thread David Chisnall via cfe-commits
Author: theraven
Date: Fri Aug 10 05:53:13 2018
New Revision: 339428

URL: http://llvm.org/viewvc/llvm-project?rev=339428&view=rev
Log:
Add Windows support for the GNUstep Objective-C ABI V2.

Summary:
Introduces funclet-based unwinding for Objective-C and fixes an issue
where global blocks can't have their isa pointers initialised on
Windows.

After discussion with Dustin, this changes the name mangling of
Objective-C types to prevent a C++ catch statement of type struct X*
from catching an Objective-C object of type X*.

Reviewers: rjmccall, DHowett-MSFT

Reviewed By: rjmccall, DHowett-MSFT

Subscribers: mgrang, mstorsjo, smeenai, cfe-commits

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/lib/CodeGen/CGException.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/test/CodeGenObjC/gnu-init.m
cfe/trunk/test/CodeGenObjC/gnustep2-proto.m
cfe/trunk/test/CodeGenObjCXX/arc-marker-funclet.mm
cfe/trunk/test/CodeGenObjCXX/microsoft-abi-arc-param-order.mm
cfe/trunk/test/CodeGenObjCXX/msabi-objc-extensions.mm
cfe/trunk/test/CodeGenObjCXX/msabi-objc-types.mm

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=339428&r1=339427&r2=339428&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Aug 10 05:53:13 2018
@@ -1488,7 +1488,7 @@ def fobjc_weak : Flag<["-"], "fobjc-weak
   HelpText<"Enable ARC-style weak references in Objective-C">;
 
 // Objective-C ABI options.
-def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group, 
Flags<[CC1Option]>,
+def fobjc_runtime_EQ : Joined<["-"], "fobjc-runtime=">, Group, 
Flags<[CC1Option, CoreOption]>,
   HelpText<"Specify the target Objective-C runtime kind and version">;
 def fobjc_abi_version_EQ : Joined<["-"], "fobjc-abi-version=">, Group;
 def fobjc_nonfragile_abi_version_EQ : Joined<["-"], 
"fobjc-nonfragile-abi-version=">, Group;

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=339428&r1=339427&r2=339428&view=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Aug 10 05:53:13 2018
@@ -445,7 +445,7 @@ void MicrosoftCXXNameMangler::mangle(con
 mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
   else if (const VarDecl *VD = dyn_cast(D))
 mangleVariableEncoding(VD);
-  else
+  else if (!isa(D))
 llvm_unreachable("Tried to mangle unexpected NamedDecl!");
 }
 
@@ -1884,13 +1884,13 @@ void MicrosoftCXXNameMangler::mangleType
 llvm_unreachable("placeholder types shouldn't get to name mangling");
 
   case BuiltinType::ObjCId:
-mangleArtificalTagType(TTK_Struct, "objc_object");
+mangleArtificalTagType(TTK_Struct, ".objc_object");
 break;
   case BuiltinType::ObjCClass:
-mangleArtificalTagType(TTK_Struct, "objc_class");
+mangleArtificalTagType(TTK_Struct, ".objc_class");
 break;
   case BuiltinType::ObjCSel:
-mangleArtificalTagType(TTK_Struct, "objc_selector");
+mangleArtificalTagType(TTK_Struct, ".objc_selector");
 break;
 
 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
@@ -2570,9 +2570,10 @@ void MicrosoftCXXNameMangler::mangleType
 
 void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, 
Qualifiers,
  SourceRange) {
-  // ObjC interfaces have structs underlying them.
+  // ObjC interfaces are mangled as if they were structs with a name that is
+  // not a valid C/C++ identifier
   mangleTagTypeKind(TTK_Struct);
-  mangleName(T->getDecl());
+  mangle(T->getDecl(), ".objc_cls_");
 }
 
 void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
@@ -2590,11 +2591,11 @@ void MicrosoftCXXNameMangler::mangleType
 
   Out << "?$";
   if (T->isObjCId())
-mangleSourceName("objc_object");
+mangleSourceName(".objc_object");
   else if (T->isObjCClass())
-mangleSourceName("objc_class");
+mangleSourceName(".objc_class");
   else
-mangleSourceName(T->getInterface()->getName());
+mangleSourceName((".objc_cls_" + T->getInterface()->getName()).str());
 
   for (const auto &Q : T->quals())
 mangleObjCProtocol(Q);

Modified: cfe/trunk/lib/CodeGen/CGException.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGException.cpp?rev=339428&r1=339427&r2=339428&view=diff
==
--

r339317 - Correctly initialise global blocks on Windows.

2018-08-09 Thread David Chisnall via cfe-commits
Author: theraven
Date: Thu Aug  9 01:02:42 2018
New Revision: 339317

URL: http://llvm.org/viewvc/llvm-project?rev=339317&view=rev
Log:
Correctly initialise global blocks on Windows.

Summary:
Windows does not allow globals to be initialised to point to globals in
another DLL.  Exported globals may be referenced only from code.  Work
around this by creating an initialiser that runs in early library
initialisation and sets the isa pointer.

Reviewers: rjmccall

Reviewed By: rjmccall

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/CodeGen/global-blocks-win32.c
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=339317&r1=339316&r2=339317&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Thu Aug  9 01:02:42 2018
@@ -1213,9 +1213,13 @@ static llvm::Constant *buildGlobalBlock(
   auto fields = builder.beginStruct();
 
   bool IsOpenCL = CGM.getLangOpts().OpenCL;
+  bool IsWindows = CGM.getTarget().getTriple().isOSWindows();
   if (!IsOpenCL) {
 // isa
-fields.add(CGM.getNSConcreteGlobalBlock());
+if (IsWindows)
+  fields.addNullPointer(CGM.Int8PtrPtrTy);
+else
+  fields.add(CGM.getNSConcreteGlobalBlock());
 
 // __flags
 BlockFlags flags = BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE;
@@ -1250,7 +1254,27 @@ static llvm::Constant *buildGlobalBlock(
 
   llvm::Constant *literal = fields.finishAndCreateGlobal(
   "__block_literal_global", blockInfo.BlockAlign,
-  /*constant*/ true, llvm::GlobalVariable::InternalLinkage, AddrSpace);
+  /*constant*/ !IsWindows, llvm::GlobalVariable::InternalLinkage, 
AddrSpace);
+
+  // Windows does not allow globals to be initialised to point to globals in
+  // different DLLs.  Any such variables must run code to initialise them.
+  if (IsWindows) {
+auto *Init = llvm::Function::Create(llvm::FunctionType::get(CGM.VoidTy,
+  {}), llvm::GlobalValue::InternalLinkage, ".block_isa_init",
+&CGM.getModule());
+llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",
+  Init));
+b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),
+b.CreateStructGEP(literal, 0), CGM.getPointerAlign().getQuantity());
+b.CreateRetVoid();
+// We can't use the normal LLVM global initialisation array, because we
+// need to specify that this runs early in library initialisation.
+auto *InitVar = new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
+/*isConstant*/true, llvm::GlobalValue::InternalLinkage,
+Init, ".block_isa_init_ptr");
+InitVar->setSection(".CRT$XCLa");
+CGM.addUsedGlobal(InitVar);
+  }
 
   // Return a constant of the appropriately-casted type.
   llvm::Type *RequiredType =

Added: cfe/trunk/test/CodeGen/global-blocks-win32.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/global-blocks-win32.c?rev=339317&view=auto
==
--- cfe/trunk/test/CodeGen/global-blocks-win32.c (added)
+++ cfe/trunk/test/CodeGen/global-blocks-win32.c Thu Aug  9 01:02:42 2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -fblocks -triple i386-pc-windows-msvc %s -emit-llvm -o - 
-fblocks | FileCheck %s
+
+
+int (^x)(void) = ^() { return 21; };
+
+
+// Check that the block literal is emitted with a null isa pointer
+// CHECK: @__block_literal_global = internal global { i8**, i32, i32, i8*, 
%struct.__block_descriptor* } { i8** null, 
+
+// Check that _NSConcreteGlobalBlock has the correct dllimport specifier.
+// CHECK: @_NSConcreteGlobalBlock = external dllimport global i8*
+// Check that we create an initialiser pointer in the correct section (early 
library initialisation).
+// CHECK: @.block_isa_init_ptr = internal constant void ()* @.block_isa_init, 
section ".CRT$XCLa"
+
+// Check that we emit an initialiser for it.
+// CHECK: define internal void @.block_isa_init() {
+// CHECK: store i8** @_NSConcreteGlobalBlock, i8*** getelementptr inbounds ({ 
i8**, i32, i32, i8*, %struct.__block_descriptor* }, { i8**, i32, i32, i8*, 
%struct.__block_descriptor* }* @__block_literal_global, i32 0, i32 0), align 4
+


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


r339128 - [objc-gnustep] Don't emit .guess ivar offset vars.

2018-08-07 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue Aug  7 05:02:46 2018
New Revision: 339128

URL: http://llvm.org/viewvc/llvm-project?rev=339128&view=rev
Log:
[objc-gnustep] Don't emit .guess ivar offset vars.

These were intended to allow non-fragile and fragile ABI code to be
mixed, as long as the fragile classes were higher up the hierarchy than
the non-fragile ones.  Unfortunately:

 - No one actually wants to do this.
 - Recent versions of Linux's run-time linker break it.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=339128&r1=339127&r2=339128&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue Aug  7 05:02:46 2018
@@ -3812,40 +3812,10 @@ llvm::GlobalVariable *CGObjCGNU::ObjCIva
   // is.  This allows code compiled with non-fragile ivars to work correctly
   // when linked against code which isn't (most of the time).
   llvm::GlobalVariable *IvarOffsetPointer = TheModule.getNamedGlobal(Name);
-  if (!IvarOffsetPointer) {
-// This will cause a run-time crash if we accidentally use it.  A value of
-// 0 would seem more sensible, but will silently overwrite the isa pointer
-// causing a great deal of confusion.
-uint64_t Offset = -1;
-// We can't call ComputeIvarBaseOffset() here if we have the
-// implementation, because it will create an invalid ASTRecordLayout object
-// that we are then stuck with forever, so we only initialize the ivar
-// offset variable with a guess if we only have the interface.  The
-// initializer will be reset later anyway, when we are generating the class
-// description.
-if (!CGM.getContext().getObjCImplementation(
-  const_cast(ID)))
-  Offset = ComputeIvarBaseOffset(CGM, ID, Ivar);
-
-llvm::ConstantInt *OffsetGuess = llvm::ConstantInt::get(Int32Ty, Offset,
- /*isSigned*/true);
-// Don't emit the guess in non-PIC code because the linker will not be able
-// to replace it with the real version for a library.  In non-PIC code you
-// must compile with the fragile ABI if you want to use ivars from a
-// GCC-compiled class.
-if (CGM.getLangOpts().PICLevel) {
-  llvm::GlobalVariable *IvarOffsetGV = new llvm::GlobalVariable(TheModule,
-Int32Ty, false,
-llvm::GlobalValue::PrivateLinkage, OffsetGuess, Name+".guess");
-  IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
-IvarOffsetGV->getType(), false, 
llvm::GlobalValue::LinkOnceAnyLinkage,
-IvarOffsetGV, Name);
-} else {
-  IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
-  llvm::Type::getInt32PtrTy(VMContext), false,
-  llvm::GlobalValue::ExternalLinkage, nullptr, Name);
-}
-  }
+  if (!IvarOffsetPointer)
+IvarOffsetPointer = new llvm::GlobalVariable(TheModule,
+llvm::Type::getInt32PtrTy(VMContext), false,
+llvm::GlobalValue::ExternalLinkage, nullptr, Name);
   return IvarOffsetPointer;
 }
 


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


Re: r332963 - Revert "Revert r332955 "GNUstep Objective-C ABI version 2""

2018-05-23 Thread David Chisnall via cfe-commits
On 23 May 2018, at 08:38, Hans Wennborg  wrote:
> 
> Hi David,
> 
> On Tue, May 22, 2018 at 12:13 PM, David Chisnall via cfe-commits
>  wrote:
>> Author: theraven
>> Date: Tue May 22 03:13:06 2018
>> New Revision: 332963
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=332963&view=rev
>> Log:
>> Revert "Revert r332955 "GNUstep Objective-C ABI version 2""
>> 
>> Added:
>>cfe/trunk/test/CodeGenObjC/forward-declare-protocol-gnu.m
>>cfe/trunk/test/CodeGenObjC/gnu-init.m
>>cfe/trunk/test/CodeGenObjC/gnustep2-category.m
>>cfe/trunk/test/CodeGenObjC/gnustep2-class.m
>>cfe/trunk/test/CodeGenObjC/gnustep2-ivar-offset.m
>>cfe/trunk/test/CodeGenObjC/gnustep2-proto.m
>> Modified:
>>cfe/trunk/include/clang/AST/Expr.h
>>cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
>>cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
>>cfe/trunk/lib/Driver/ToolChains/Clang.cpp
>>cfe/trunk/lib/Frontend/InitPreprocessor.cpp
>>cfe/trunk/test/CodeGenObjC/constant-strings.m
>>cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
>>cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m
>>cfe/trunk/test/Preprocessor/init.c
> 
> Do you want to add something about this to the release notes?

Yes, I will do a bit nearer the time, once I’m sure how stable it is - I intend 
to treat it as experimental between now and the 7.0 release, but might want to 
keep it experimental until 8.0 (or back-port fixes to 7.1, given that it’s 
fairly self-contained within clang).

David

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


r332964 - [objc-gnustep2] Use isalnum instead of a less efficient and nonportable equivalent.

2018-05-22 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue May 22 03:13:11 2018
New Revision: 332964

URL: http://llvm.org/viewvc/llvm-project?rev=332964&view=rev
Log:
[objc-gnustep2] Use isalnum instead of a less efficient and nonportable 
equivalent.

Patch by Hans Wennborg!

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=332964&r1=332963&r2=332964&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue May 22 03:13:11 2018
@@ -1054,7 +1054,7 @@ class CGObjCGNUstep2 : public CGObjCGNUs
   StringName = ".objc_str_";
   for (int i=0,e=Str.size() ; ihttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332966 - [objc-gnustep2] Use unsigned char to avoid potential UB in isalnum.

2018-05-22 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue May 22 03:13:17 2018
New Revision: 332966

URL: http://llvm.org/viewvc/llvm-project?rev=332966&view=rev
Log:
[objc-gnustep2] Use unsigned char to avoid potential UB in isalnum.

Suggested by Gabor Buella.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=332966&r1=332965&r2=332966&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue May 22 03:13:17 2018
@@ -1053,7 +1053,7 @@ class CGObjCGNUstep2 : public CGObjCGNUs
 if (isNamed) {
   StringName = ".objc_str_";
   for (int i=0,e=Str.size() ; ihttp://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r332965 - [objc-gnu] Fix test.

2018-05-22 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue May 22 03:13:14 2018
New Revision: 332965

URL: http://llvm.org/viewvc/llvm-project?rev=332965&view=rev
Log:
[objc-gnu] Fix test.

The test was implicitly capturing the local filesystem layout.

Patch by Hans Wennborg!

Modified:
cfe/trunk/test/CodeGenObjC/gnu-init.m

Modified: cfe/trunk/test/CodeGenObjC/gnu-init.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-init.m?rev=332965&r1=332964&r2=332965&view=diff
==
--- cfe/trunk/test/CodeGenObjC/gnu-init.m (original)
+++ cfe/trunk/test/CodeGenObjC/gnu-init.m Tue May 22 03:13:14 2018
@@ -60,7 +60,7 @@
 // CHECK-NEW-SAME: @.objc_init
 // CHECK-NEW-NEXT: ret void
 
-// CHECK-OLD: @4 = internal global { i64, i64, i8*, { i64, { i8*, i8* }*, i16, 
i16, [4 x i8*] }* } { i64 9, i64 32, i8* getelementptr inbounds ([103 x i8], 
[103 x i8]* @.objc_source_file_name, i64 0, i64 0), { i64, { i8*, i8* }*, i16, 
i16, [4 x i8*] }* @3 }, align 8
+// CHECK-OLD: @4 = internal global { i64, i64, i8*, { i64, { i8*, i8* }*, i16, 
i16, [4 x i8*] }* } { i64 9, i64 32, i8* getelementptr inbounds ([{{[0-9]+}} x 
i8], [{{[0-9]+}} x i8]* @.objc_source_file_name, i64 0, i64 0), { i64, { i8*, 
i8* }*, i16, i16, [4 x i8*] }* @3 }, align 8
 // CHECK-OLD: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* 
}] [{ i32, void ()*, i8* } { i32 65535, void ()* @.objc_load_function, i8* null 
}]
 
 // CHECK-OLD: define internal void @.objc_load_function() {


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


r332955 - Add cctype include.

2018-05-22 Thread David Chisnall via cfe-commits
Author: theraven
Date: Tue May 22 00:22:50 2018
New Revision: 332955

URL: http://llvm.org/viewvc/llvm-project?rev=332955&view=rev
Log:
Add cctype include.

This appears to leak in already on libc++ platforms, but is breaking on
some other targets.

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

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=332955&r1=332954&r2=332955&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue May 22 00:22:50 2018
@@ -35,6 +35,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ConvertUTF.h"
+#include 
 
 using namespace clang;
 using namespace CodeGen;


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


Re: r329882 - ObjCGNU: Fix empty v3 protocols being emitted two fields short

2018-04-12 Thread David Chisnall via cfe-commits
It does seem to be.  I used arc to apply the change, so I’m not sure what 
happened - I thought it normally set the author correctly.

David

> On 12 Apr 2018, at 08:09, Shoaib Meenai  wrote:
> 
> This is missing an attribution of changes, right?
>  
> From: cfe-commits  on behalf of David 
> Chisnall via cfe-commits 
> Reply-To: David Chisnall 
> Date: Wednesday, April 11, 2018 at 11:49 PM
> To: "cfe-commits@lists.llvm.org" 
> Subject: r329882 - ObjCGNU: Fix empty v3 protocols being emitted two fields 
> short
>  
> Author: theraven
> Date: Wed Apr 11 23:46:15 2018
> New Revision: 329882
>  
> URL: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D329882-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=kOSrBx9BPwaPzisR4ZjTMKz416HW7XRohfwPXtT5O9E&s=69tkdQlTNiO-wOTuNHO7a35iqDVy9hW6Jrw-hSq_q6s&e=
> Log:
> ObjCGNU: Fix empty v3 protocols being emitted two fields short
>  
> Summary:
> Protocols that were being referenced but could not be fully realized were 
> being emitted without `properties`/`optional_properties`. Since all v3 
> protocols must be 9 processor words wide, the lack of these fields is 
> catastrophic for the runtime.
>  
> As an example, the runtime cannot know 
> [here](https://github.com/gnustep/libobjc2/blob/master/protocol.c#L73) that 
> `properties` and `optional_properties` are invalid.
>  
> Reviewers: rjmccall, theraven
>  
> Reviewed By: rjmccall, theraven
>  
> Subscribers: cfe-commits
>  
> Tags: #clang
>  
> Differential Revision: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D45305&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=kOSrBx9BPwaPzisR4ZjTMKz416HW7XRohfwPXtT5O9E&s=JoyP68pCdLsffM8xX9NMx9VXafshpTnxECegbsdc4rc&e=
>  
> Added:
> cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
> Modified:
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
>  
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_CodeGen_CGObjCGNU.cpp-3Frev-3D329882-26r1-3D329881-26r2-3D329882-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=kOSrBx9BPwaPzisR4ZjTMKz416HW7XRohfwPXtT5O9E&s=v2_iviP5qFoN3SvBUJtLVbxpLsyewCRlyAbxv96yJiI&e=
> ==
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Apr 11 23:46:15 2018
> @@ -1748,11 +1748,13 @@ CGObjCGNU::GenerateEmptyProtocol(const s
>llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy));
>Elements.add(MakeConstantString(ProtocolName, ".objc_protocol_name"));
> -  Elements.add(ProtocolList);
> -  Elements.add(MethodList);
> -  Elements.add(MethodList);
> -  Elements.add(MethodList);
> -  Elements.add(MethodList);
> +  Elements.add(ProtocolList); /* .protocol_list */
> +  Elements.add(MethodList);   /* .instance_methods */
> +  Elements.add(MethodList);   /* .class_methods */
> +  Elements.add(MethodList);   /* .optional_instance_methods */
> +  Elements.add(MethodList);   /* .optional_class_methods */
> +  Elements.add(NULLPtr);  /* .properties */
> +  Elements.add(NULLPtr);  /* .optional_properties */
>return Elements.finishAndCreateGlobal(".objc_protocol",
>  CGM.getPointerAlign());
> }
>  
> Added: cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
> URL: 
> https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_CodeGenObjC_gnu-2Dempty-2Dprotocol-2Dv3.m-3Frev-3D329882-26view-3Dauto&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=kOSrBx9BPwaPzisR4ZjTMKz416HW7XRohfwPXtT5O9E&s=arR3-NaqV7bUw3lmGH8VA1UAMCgPZ2Xf4Zbn-tKJY-A&e=
> ==
> --- cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m (added)
> +++ cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m Wed Apr 11 23:46:15 
> 2018
> @@ -0,0 +1,25 @@
> +// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 
> -emit-llvm -o - %s | FileCheck %s
> +
> +@protocol X;
> +
> +__attribute__((objc_root_class))
> +@interface Z 
> +@end
> +
> +@implementation Z
> +@end
> +
> +// CHECK:  @.objc_protocol_list = internal global { i8*, i32, [0 x i8*] 
> } zeroinitializer, align 4
> +// CHECK:  @.objc_method_list = internal global { i32, [0 x { i8*, i8* 
> }] } zeroinitializer, align 4
> +// CHECK:  @.objc_protocol_name = private unnamed_addr constant

r329882 - ObjCGNU: Fix empty v3 protocols being emitted two fields short

2018-04-11 Thread David Chisnall via cfe-commits
Author: theraven
Date: Wed Apr 11 23:46:15 2018
New Revision: 329882

URL: http://llvm.org/viewvc/llvm-project?rev=329882&view=rev
Log:
ObjCGNU: Fix empty v3 protocols being emitted two fields short

Summary:
Protocols that were being referenced but could not be fully realized were being 
emitted without `properties`/`optional_properties`. Since all v3 protocols must 
be 9 processor words wide, the lack of these fields is catastrophic for the 
runtime.

As an example, the runtime cannot know 
[here](https://github.com/gnustep/libobjc2/blob/master/protocol.c#L73) that 
`properties` and `optional_properties` are invalid.

Reviewers: rjmccall, theraven

Reviewed By: rjmccall, theraven

Subscribers: cfe-commits

Tags: #clang

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

Added:
cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=329882&r1=329881&r2=329882&view=diff
==
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Wed Apr 11 23:46:15 2018
@@ -1748,11 +1748,13 @@ CGObjCGNU::GenerateEmptyProtocol(const s
   llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy));
 
   Elements.add(MakeConstantString(ProtocolName, ".objc_protocol_name"));
-  Elements.add(ProtocolList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
-  Elements.add(MethodList);
+  Elements.add(ProtocolList); /* .protocol_list */
+  Elements.add(MethodList);   /* .instance_methods */
+  Elements.add(MethodList);   /* .class_methods */
+  Elements.add(MethodList);   /* .optional_instance_methods */
+  Elements.add(MethodList);   /* .optional_class_methods */
+  Elements.add(NULLPtr);  /* .properties */
+  Elements.add(NULLPtr);  /* .optional_properties */
   return Elements.finishAndCreateGlobal(".objc_protocol",
 CGM.getPointerAlign());
 }

Added: cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m?rev=329882&view=auto
==
--- cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m (added)
+++ cfe/trunk/test/CodeGenObjC/gnu-empty-protocol-v3.m Wed Apr 11 23:46:15 2018
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -triple i686-pc-linux-gnu -fobjc-runtime=gnustep-1.9 
-emit-llvm -o - %s | FileCheck %s
+
+@protocol X;
+
+__attribute__((objc_root_class))
+@interface Z 
+@end
+
+@implementation Z
+@end
+
+// CHECK:  @.objc_protocol_list = internal global { i8*, i32, [0 x i8*] } 
zeroinitializer, align 4
+// CHECK:  @.objc_method_list = internal global { i32, [0 x { i8*, i8* }] 
} zeroinitializer, align 4
+// CHECK:  @.objc_protocol_name = private unnamed_addr constant [2 x i8] 
c"X\00", align 1
+// CHECK:  @.objc_protocol = internal global { i8*, i8*, { i8*, i32, [0 x 
i8*] }*, { i32, [0 x { i8*, i8* }] }*, { i32, [0 x { i8*, i8* }] }*, { i32, [0 
x { i8*, i8* }] }*, { i32, [0 x { i8*, i8* }] }*, i8*, i8* } {
+// CHECK-SAME: i8* inttoptr (i32 3 to i8*),
+// CHECK-SAME: i8* getelementptr inbounds ([2 x i8], [2 x i8]* 
@.objc_protocol_name, i32 0, i32 0),
+// CHECK-SAME: { i8*, i32, [0 x i8*] }* @.objc_protocol_list,
+// CHECK-SAME: { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME: { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME: { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME: { i32, [0 x { i8*, i8* }] }* @.objc_method_list,
+// CHECK-SAME: i8* null,
+// CHECK-SAME: i8* null
+// CHECK-SAME: }, align 4


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


[PATCH] D25431: [libcxx] Convert Solaris support library to C++ to fix -std=c++11 build

2016-10-18 Thread David Chisnall via cfe-commits
theraven added a comment.

Looks like a much better change to me.


https://reviews.llvm.org/D25431



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


[PATCH] D25431: [libcxx] [CMake] Build Solaris compat as separate C lib, to avoid -std= issues

2016-10-10 Thread David Chisnall via cfe-commits
theraven added a comment.

It sounds as if the bug here is either that the .c files are being treated as 
c++, or that we're sticking -std=c++{whatever} in CFLAGS as well as CXXFLAGS.  
This is probably the bug that should be fixed.


https://reviews.llvm.org/D25431



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


Re: [PATCH] D21329: Rename and rework `_LIBCPP_TRIVIAL_PAIR_COPY_CTOR`. Move FreeBSD configuration in-tree.

2016-07-06 Thread David Chisnall via cfe-commits
theraven added a comment.

Looks fine to me, though I wonder if we want to move to the new ABI for 
FreeBSD11 and use the old one for <=10.


http://reviews.llvm.org/D21329



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


Re: [cfe-dev] RFC: Default language standard mode policy

2016-06-30 Thread David Chisnall via cfe-commits
On 29 Jun 2016, at 23:07, Richard Smith via cfe-dev  
wrote:
> 
> Yes, those are real problems, but it's not reasonable for us to keep the 
> default at C++98/03 forever. GCC has already taken the plunge here, so a lot 
> of open-source code that doesn't work in C++11 onwards already explicitly 
> specifies an appropriate -std= flag.
> 

Could you clarify exactly what the issue is?  Currently, if I have some legacy 
C++98 code, the odds are that it just compiles with ${CXX}.  If I have new 
C++11 or C++14 code, then its build system likely sticks on the required -std= 
flag and it builds independent of what the compiler default is.

What code would be broken by keeping the default at the language version 
accepted by code that didn’t know about newer standards?  As long as we’re 
keeping support for C++98 in the front end, keeping the default there doesn’t 
seem particularly arduous for us and will avoid breaking third-party code.

David



smime.p7s
Description: S/MIME cryptographic signature
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2016-04-16 Thread David Chisnall via cfe-commits
theraven added a comment.

In http://reviews.llvm.org/D11781#403335, @rmaprath wrote:

> For us (ARM), a threads porting layer is important on several RTOSes (where a 
> full-blown pthreads implementations is not available). I will see if I can 
> publish one of those porting layer implementations, but perhaps a windows 
> porting layer is more interesting to the community, in which case I'll look 
> into hacking one up (unless of course, if @espositofulvio has already got 
> one).


I'd be equally interested (and willing to review) an mbed implementation.


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D13051: Add placeholder __libcpp_relaxed_store() for when atomic builtins are not available.

2015-09-22 Thread David Chisnall via cfe-commits
theraven added a comment.

Looks fine (though this probably won't actually work correctly on ARMv4).

It's a shame that libc++ decided to reinvent the wheel here and not use the C11 
atomics support...


http://reviews.llvm.org/D13051



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-11 Thread David Chisnall via cfe-commits
theraven added inline comments.


Comment at: include/__config:742
@@ +741,3 @@
+#ifndef _LIBCPP_HAS_NO_THREADS
+# if defined(__FreeBSD__) || \
+defined(__NetBSD__) || \

espositofulvio wrote:
> jroelofs wrote:
> > espositofulvio wrote:
> > > jroelofs wrote:
> > > > jroelofs wrote:
> > > > > @espositofulvio: @ed meant this:
> > > > > 
> > > > > ```
> > > > > #ifndef _WIN32
> > > > > #  include 
> > > > > #  if _POSIX_THREADS > 0
> > > > > ...
> > > > > #  endif
> > > > > #endif
> > > > > ```
> > > > > 
> > > > > Which //is// the correct way to test for this.
> > > > That being said, there have been discussions before about whether or 
> > > > not we should #include  in <__config>, with the conclusion 
> > > > being that we shouldn't.
> > > > 
> > > > It would be better if this were a CMake configure-time check that sets 
> > > > _LIBCPP_THREAD_API, rather than these build-time guards.
> > > Tried adding that as configure time checks, but then libcxxabi fails to 
> > > compile because of the guard in __config to check that _LIBCPP_THREAD_API 
> > > has beed defined when _LIBCPP_HAS_NO_THREADS is not. 
> > > 
> > > As a side note: Is Windows the only OS which hasn't got unistd.h?
> > > Tried adding that as configure time checks...
> > 
> > Can you put the patch for that up on gist.github.com, or a pastebin?... 
> > I'll take a look.
> > 
> > > As a side note: Is Windows the only OS which hasn't got unistd.h?
> > 
> > For the platforms libcxx currently builds on, yes.
> > Can you put the patch for that up on gist.github.com, or a pastebin?... 
> > I'll take a look.
> 
> It's here https://gist.github.com/espositofulvio/eac2fb08acf2e430c516
I'm sorry to have triggered this bikeshed.  Given that, of the currently 
supported platforms, Windows is the only one where we want to use threads but 
don't want to use PTHREADS, I think it's fine to have this check be !WIN32.  
The important thing is having the check *in one place* so that the person who 
wants to add the *second* non-pthread threading implementation doesn't have a 
load of different places to look: they can just change it in `__config` and 
then chase all of the compile failures.


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-10 Thread David Chisnall via cfe-commits
theraven added a comment.

It would be nice to use rwlocks, but that's an ABI-breaking change.  We'd need 
to bump the .so version and other annoyances.  Definitely something I'd be in 
favour of seeing hidden behind some #ifdefs (and enabled for FreeBSD 11 and 
probably for the libc++ in packages), but it's beyond the scope of this set of 
changes.


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-08 Thread David Chisnall via cfe-commits
theraven added a comment.

This version looks much better (well, the previous one is cleaner, but this one 
looks like it shouldn't break the ABI - did you test this?  It looks like it 
should work, but I've not actually tried it).



Comment at: include/__config:742
@@ +741,3 @@
+#ifndef _LIBCPP_HAS_NO_THREADS
+# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) || 
defined(__APPLE__)
+#  define _LIBCPP_THREAD_API _LIBCPP_PTHREAD

#ifdef unix will catch most of these (for some reason, not OS X, even though 
it's the only one that actually is certified as UNIX...)


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-07 Thread David Chisnall via cfe-commits
theraven added inline comments.


Comment at: include/__mutex_base:246
@@ -266,3 +245,3 @@
 
-class _LIBCPP_TYPE_VIS condition_variable
+class _LIBCPP_TYPE_VIS condition_variable : private 
__libcxx_support::condition_variable
 {

espositofulvio wrote:
> theraven wrote:
> > espositofulvio wrote:
> > > theraven wrote:
> > > > Does this change the ABI for a mutex on *NIX platforms?  We can't 
> > > > change the class layout for existing platforms (though we can indirect 
> > > > things via typedefs).
> > > My hunch is that it doesn't, std::condition_variable has no data member 
> > > now and the first base class (__libcxx_support::condition_variable) 
> > > contains only pthread_cond_t which will be effectively laid out at the 
> > > starting address of the object,  as it was previously for 
> > > std::condition_variable,. I will check this out later in the evening 
> > > though.
> > I *think* that it's correct, but it's worth compiling a program that has 
> > one compilation unit using the old header and another using the new one and 
> > check that it's able to interoperate correctly.
> > 
> > Also check whether this depends on the implementation of the condition 
> > variable.  On FreeBSD, the pthread types are all pointers (currently - 
> > we're going to have some painful ABI breakage at some point when we move 
> > them to being something that can live in shared memory).  In glibc, they're 
> > structures.  I don't think that you'll end up with different padding in the 
> > ABI from wrapping them in a class, but it's worth checking.
> > it's worth compiling a program that has one compilation unit using the old 
> > header and another using the new one and check that it's able to 
> > interoperate correctly
> 
> Unfortunately this isn't going to work, some simbols are now defined in 
> __libcxx_support and not in std (they are just made available through using), 
> so an object file that includes the old header won't link against the new 
> library (unreferenced symbols). The alternative is to create inline 
> forwarding methods.
> 
> 
> 
That's going to need some more refactoring then.  Breaking the public ABI of 
libc++ would be a show-stopper.


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-06 Thread David Chisnall via cfe-commits
theraven added inline comments.


Comment at: include/__mutex_base:246
@@ -266,3 +245,3 @@
 
-class _LIBCPP_TYPE_VIS condition_variable
+class _LIBCPP_TYPE_VIS condition_variable : private 
__libcxx_support::condition_variable
 {

espositofulvio wrote:
> theraven wrote:
> > Does this change the ABI for a mutex on *NIX platforms?  We can't change 
> > the class layout for existing platforms (though we can indirect things via 
> > typedefs).
> My hunch is that it doesn't, std::condition_variable has no data member now 
> and the first base class (__libcxx_support::condition_variable) contains only 
> pthread_cond_t which will be effectively laid out at the starting address of 
> the object,  as it was previously for std::condition_variable,. I will check 
> this out later in the evening though.
I *think* that it's correct, but it's worth compiling a program that has one 
compilation unit using the old header and another using the new one and check 
that it's able to interoperate correctly.

Also check whether this depends on the implementation of the condition 
variable.  On FreeBSD, the pthread types are all pointers (currently - we're 
going to have some painful ABI breakage at some point when we move them to 
being something that can live in shared memory).  In glibc, they're structures. 
 I don't think that you'll end up with different padding in the ABI from 
wrapping them in a class, but it's worth checking.


Comment at: include/mutex:182
@@ -181,2 +181,3 @@
 #endif
-#include 
+#ifndef _WIN32
+#include 

espositofulvio wrote:
> theraven wrote:
> > As above, there should probably be in a cross-platform support file that 
> > includes these.  In particular, not-win32 is not the correct condition for 
> > uses-pthreads.  We should probably have something in __config that 
> > determines the thread library to use.  It would be quite nice to have a C11 
> > thread back end, for example (though most implementations currently wrap 
> > pthreads).
> In this case having a series of #ifdef __FreeBSD__ (or _WIN32, etc.) doesn't 
> quite cut it as we want to be able to select C11 or pthread on most of them 
> and on Windows one day it might even be C11, pthread or the win32 api. I 
> guess the alternative is to provide a cmake variable that default to 
> something different on each platform?
> 
We'll probably end up with a set of #ifdef FreeBSD (or whatever) things, but 
making sure that they're all in a single file will help.  If you're doing 
bring-up of a new platform, just having to set #define __LIBCXX_THREAD_API 
__LIBCXX_PTHREAD, or __LIBCXX_C11_THREADS, (or Haiku threads, or whatever) in 
one place makes life a bit easier.  One of the annoyances with trying to port 
asan was that the original developers used #ifdef __APPLE__ to mean 'is not 
Linux' and 'is Darwin' in various places, so we needed to look at every single 
change and determine whether they were shared between multiple non-GNU 
platforms or whether they were specific to OS X / iOS.  


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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


Re: [PATCH] D11781: Refactored pthread usage in libcxx

2015-08-06 Thread David Chisnall via cfe-commits
theraven added inline comments.


Comment at: include/__mutex_base:246
@@ -266,3 +245,3 @@
 
-class _LIBCPP_TYPE_VIS condition_variable
+class _LIBCPP_TYPE_VIS condition_variable : private 
__libcxx_support::condition_variable
 {

Does this change the ABI for a mutex on *NIX platforms?  We can't change the 
class layout for existing platforms (though we can indirect things via 
typedefs).


Comment at: include/mutex:182
@@ -181,2 +181,3 @@
 #endif
-#include 
+#ifndef _WIN32
+#include 

As above, there should probably be in a cross-platform support file that 
includes these.  In particular, not-win32 is not the correct condition for 
uses-pthreads.  We should probably have something in __config that determines 
the thread library to use.  It would be quite nice to have a C11 thread back 
end, for example (though most implementations currently wrap pthreads).


Comment at: include/mutex:269
@@ -285,3 +268,3 @@
 bool
 recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, 
_Duration>& __t)
 {

I didn't realise this idiocy made it into C++11, I thought it was confined to 
C11.  Locking a mutex using anything other than time intervals on the monotonic 
time source is a great way of producing non-working programs.  We should 
probably warn if anyone actually calls this...


Repository:
  rL LLVM

http://reviews.llvm.org/D11781



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