[PATCH] D25547: [CodeGen][ObjC] Do not emit objc_storeStrong to initialize a constexpr variable

Akira Hatanaka via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 12 22:03:05 PDT 2016


ahatanak created this revision.
ahatanak added a reviewer: rjmccall.
ahatanak added a subscriber: cfe-commits.

When compiling a constexpr NSString initialized with an objective-c string literal, CodeGen currently emits objc_storeStrong on an uninitialized alloca, which causes a crash:

  constexpr NSString *S = @"abc";



  %S = alloca %0*, align 8
  %0 = bitcast %0** %S to i8** ; this points to uninitialized memory
  call void @objc_storeStrong(i8** %0, i8* bitcast (%struct.__NSConstantString_tag* @_unnamed_cfstring_ to i8*)) #1

This patch fixes the crash by directly storing the pointer to the __NSConstantString_tag for the string into the allocated alloca. The rationale for this change is that retain or release on an Objective-c string literal (or anything used to initialize a constexpr variable) has no effect and therefore objc_storeStrong isn't needed in this case.

rdar://problem/28562009


https://reviews.llvm.org/D25547

Files:
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjCXX/arc-constexpr.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25547.74473.patch
Type: text/x-patch
Size: 7260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161013/6d939b17/attachment.bin>


More information about the cfe-commits mailing list