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
I think you can fold this a bit more. :) You have exactly the same switch statement below, and several of the cases are identical; for the others, you can just sink the isInit check into the case.
Note that calling EmitStoreOfScalar and returning has the same behavior as "falling into the normal path". isObjCWeak() / isObjCStrong() are checking for the GC qualifiers, which are exclusive with ARC lifetime.