File: string_global_name.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (26 lines) | stat: -rw-r--r-- 1,617 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// RUN: %target-swift-frontend -primary-file %s -emit-ir > %t.ir
// RUN: %FileCheck %s --input-file=%t.ir

// This test checks that `@.str` string constants have names accurately
// reflecting their contents. Other tests rely on this behavior so they can
// simply test the names of constants and assume that their values match.

func strings() {
  // String literal containing only identifier-safe characters.
  blackHole("01234567890123456789")
  // CHECK-DAG: @.str.20.01234567890123456789 = private unnamed_addr constant [21 x i8] c"01234567890123456789\00"

  // String literal containing spaces and punctuation.
  blackHole("Hello, world! Padding past 16.")
  // CHECK-DAG: @".str.30.Hello, world! Padding past 16." = private unnamed_addr constant [31 x i8] c"Hello, world! Padding past 16.\00"
  
  // String literal containing non-ASCII characters.
  blackHole("🏳️‍⚧️👩‍❤️‍💋‍👩🥹")
  // CHECK-DAG:  @".str.47.\F0\9F\8F\B3\EF\B8\8F\E2\80\8D\E2\9A\A7\EF\B8\8F\F0\9F\91\A9\E2\80\8D\E2\9D\A4\EF\B8\8F\E2\80\8D\F0\9F\92\8B\E2\80\8D\F0\9F\91\A9\F0\9F\A5\B9" = private unnamed_addr constant [48 x i8] c"\F0\9F\8F\B3\EF\B8\8F\E2\80\8D\E2\9A\A7\EF\B8\8F\F0\9F\91\A9\E2\80\8D\E2\9D\A4\EF\B8\8F\E2\80\8D\F0\9F\92\8B\E2\80\8D\F0\9F\91\A9\F0\9F\A5\B9\00"

  // String literal containing nul characters. These require special encoding.
  blackHole("\01\02\03\04\05\06\07\08")
  // CHECK-DAG: @.str.16._1_2_3_4_5_6_7_8.nul8.nul10.nul12.nul14.nul16.nul18.nul20.nul22 = private unnamed_addr constant [17 x i8] c"\001\002\003\004\005\006\007\008\00"
}

@inline(never) func blackHole(_: String) {}