[PATCH] D61974: [ObjC] Fix encoding of ObjC pointer types that are pointers to typedefs

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 15 18:48:25 PDT 2019


ahatanak created this revision.
ahatanak added reviewers: rjmccall, theraven.
ahatanak added a project: clang.
Herald added subscribers: dexonsmith, jkorous.

clang currently emits different strings for `s0` and `s1` in the following code because pointers to typedefs are encoded as "^{PointeeClassName=#}" while ObjC pointer types that aren't pointers to typedefs are encoded as "@".

  @class Class1;
  
  typedef NSArray<Class1 *> MyArray;
  
  void foo1(void) {
    const char *s0 = @encode(MyArray *); // "^{NSArray=#}"
    const char *s1 = @encode(NSArray<Class1 *> *); // "@" 
  }

It seems that this was a deliberate choice made in r61387 to make clang compatible with gcc (see http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20081222/010465.html), but it causes apple's runtime to crash. This patch fixes the bug by checking whether the runtime is one of the GNU runtimes before using the special encoding for typedefs.

rdar://problem/50563529


Repository:
  rC Clang

https://reviews.llvm.org/D61974

Files:
  lib/AST/ASTContext.cpp
  test/CodeGenObjC/encode-test-6.m
  test/CodeGenObjC/encode-test.m
  test/CodeGenObjCXX/encode.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61974.199710.patch
Type: text/x-patch
Size: 4685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190516/3472ed38/attachment.bin>


More information about the cfe-commits mailing list