File: string_global_name.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (26 lines) | stat: -rw-r--r-- 1,617 bytes parent folder | download
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) {}