diff options
author | Akira Hatanaka <ahatanaka@apple.com> | 2019-03-08 04:45:37 +0000 |
---|---|---|
committer | Akira Hatanaka <ahatanaka@apple.com> | 2019-03-08 04:45:37 +0000 |
commit | 4874bff565a9f92c41a1efad0b3d633371b5930c (patch) | |
tree | 5620f4c9ea9bb1c7c778aee2b803517e7ed01afc /test/CodeGenObjC/boxing.m | |
parent | 53b90c6143ce37544aa76a140b07defb21166f65 (diff) | |
download | clang-4874bff565a9f92c41a1efad0b3d633371b5930c.tar.gz |
[ObjC] Emit a boxed expression as a compile-time constant if the
expression inside the parentheses is a valid UTF-8 string literal.
Previously clang emitted an expression like @("abc") as a message send
to stringWithUTF8String. This commit makes clang emit the boxed
expression as a compile-time constant instead.
This commit also has the effect of silencing the nullable-to-nonnull
conversion warning clang started emitting after r317727, which
originally motivated this commit (see https://oleb.net/2018/@keypath).
rdar://problem/42684601
Differential Revision: https://reviews.llvm.org/D58729
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355662 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenObjC/boxing.m')
-rw-r--r-- | test/CodeGenObjC/boxing.m | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/CodeGenObjC/boxing.m b/test/CodeGenObjC/boxing.m index 42dd33337f..9b501b18bc 100644 --- a/test/CodeGenObjC/boxing.m +++ b/test/CodeGenObjC/boxing.m @@ -53,6 +53,9 @@ typedef signed char BOOL; + (id)stringWithUTF8String:(const char *)nullTerminatedCString; @end +// CHECK: [[V0:%.*]] = type opaque +// CHECK: [[STRUCT_NSCONSTANT_STRING_TAG:%.*]] = type { i32*, i32, i8*, i64 } + // CHECK: [[WithIntMeth:@.*]] = private unnamed_addr constant [15 x i8] c"numberWithInt:\00" // CHECK: [[WithIntSEL:@.*]] = private externally_initialized global i8* getelementptr inbounds ([15 x i8], [15 x i8]* [[WithIntMeth]] // CHECK: [[WithCharMeth:@.*]] = private unnamed_addr constant [16 x i8] c"numberWithChar:\00" @@ -65,8 +68,12 @@ typedef signed char BOOL; // CHECK: [[WithUnsignedIntegerSEL:@.*]] = private externally_initialized global i8* getelementptr inbounds ([27 x i8], [27 x i8]* [[WithUnsignedIntegerMeth]] // CHECK: [[stringWithUTF8StringMeth:@.*]] = private unnamed_addr constant [22 x i8] c"stringWithUTF8String:\00" // CHECK: [[stringWithUTF8StringSEL:@.*]] = private externally_initialized global i8* getelementptr inbounds ([22 x i8], [22 x i8]* [[stringWithUTF8StringMeth]] +// CHECK: [[STR0:.*]] = private unnamed_addr constant [4 x i8] c"abc\00", section "__TEXT,__cstring,cstring_literals", align 1 +// CHECK: [[UNNAMED_CFSTRING:.*]] = private global [[STRUCT_NSCONSTANT_STRING_TAG]] { i32* getelementptr inbounds ([0 x i32], [0 x i32]* @__CFConstantStringClassReference, i32 0, i32 0), i32 1992, i8* getelementptr inbounds ([4 x i8], [4 x i8]* [[STR0]], i32 0, i32 0), i64 3 }, section "__DATA,__cfstring", align 8 int main() { + // CHECK: [[T:%.*]] = alloca [[V0]]*, align 8 + // CHECK: load i8*, i8** [[WithIntSEL]] int i; @(i); // CHECK: load i8*, i8** [[WithCharSEL]] @@ -92,4 +99,7 @@ int main() { Color col = Red; // CHECK: load i8*, i8** [[WithIntegerSEL]] @(col); + + // CHECK: store [[V0]]* bitcast ([[STRUCT_NSCONSTANT_STRING_TAG]]* [[UNNAMED_CFSTRING]] to [[V0]]*), [[V0]]** [[T]], align 8 + NSString *t = @("abc"); } |