@@ -1658,7 +1658,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
16581658} // end anonymous namespace
16591659
16601660// TODO: move onto SGF directly and reuse in SILGenDistributed and other places
1661- static PreparedArguments emitStringLiteral (SILGenFunction &SGF, Expr * E,
1661+ static PreparedArguments emitStringLiteralArgs (SILGenFunction &SGF, SILLocation E,
16621662 StringRef Str, SGFContext C,
16631663 StringLiteralExpr::Encoding encoding) {
16641664 uint64_t Length;
@@ -1695,7 +1695,6 @@ static PreparedArguments emitStringLiteral(SILGenFunction &SGF, Expr *E,
16951695 auto Int1Ty = SILType::getBuiltinIntegerType (1 , SGF.getASTContext ());
16961696 auto *isASCIIInst = SGF.B .createIntegerLiteral (E, Int1Ty, isASCII);
16971697
1698-
16991698 ManagedValue EltsArray[] = {
17001699 ManagedValue::forUnmanaged (string),
17011700 ManagedValue::forUnmanaged (lengthInst),
@@ -1840,7 +1839,7 @@ static bool hasUnownedInnerPointerResult(CanSILFunctionType fnType) {
18401839static inline PreparedArguments
18411840buildBuiltinLiteralArgs (SILGenFunction &SGF, SGFContext C,
18421841 StringLiteralExpr *stringLiteral) {
1843- return emitStringLiteral (SGF, stringLiteral, stringLiteral->getValue (), C,
1842+ return emitStringLiteralArgs (SGF, stringLiteral, stringLiteral->getValue (), C,
18441843 stringLiteral->getEncoding ());
18451844}
18461845
@@ -1902,7 +1901,7 @@ buildBuiltinLiteralArgs(SILGenFunction &SGF, SGFContext C,
19021901 RegexLiteralExpr *expr) {
19031902 auto &ctx = SGF.getASTContext ();
19041903 // %0 = string_literal <regex text>
1905- auto strLiteralArgs = emitStringLiteral (SGF, expr, expr->getRegexText (), C,
1904+ auto strLiteralArgs = emitStringLiteralArgs (SGF, expr, expr->getRegexText (), C,
19061905 StringLiteralExpr::Encoding::UTF8);
19071906 // %1 = function_ref String.init(
19081907 // _builtinStringLiteral:utf8CodeUnitCount:isASCII:)
@@ -1949,20 +1948,20 @@ buildBuiltinLiteralArgs(SILGenFunction &SGF, SGFContext C,
19491948 case MagicIdentifierLiteralExpr::FileIDSpelledAsFile:
19501949 case MagicIdentifierLiteralExpr::FileID: {
19511950 std::string value = loc.isValid () ? SGF.getMagicFileIDString (loc) : " " ;
1952- return emitStringLiteral (SGF, magicLiteral, value, C,
1951+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
19531952 magicLiteral->getStringEncoding ());
19541953 }
19551954
19561955 case MagicIdentifierLiteralExpr::FilePathSpelledAsFile:
19571956 case MagicIdentifierLiteralExpr::FilePath: {
19581957 StringRef value = loc.isValid () ? SGF.getMagicFilePathString (loc) : " " ;
1959- return emitStringLiteral (SGF, magicLiteral, value, C,
1958+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
19601959 magicLiteral->getStringEncoding ());
19611960 }
19621961
19631962 case MagicIdentifierLiteralExpr::Function: {
19641963 StringRef value = loc.isValid () ? SGF.getMagicFunctionString () : " " ;
1965- return emitStringLiteral (SGF, magicLiteral, value, C,
1964+ return emitStringLiteralArgs (SGF, magicLiteral, value, C,
19661965 magicLiteral->getStringEncoding ());
19671966 }
19681967
@@ -2012,6 +2011,24 @@ static inline PreparedArguments buildBuiltinLiteralArgs(SILGenFunction &SGF,
20122011 }
20132012}
20142013
2014+ ManagedValue SILGenFunction::emitStringLiteral (SILLocation loc,
2015+ StringRef text,
2016+ StringLiteralExpr::Encoding encoding,
2017+ SGFContext ctx) {
2018+ auto &C = getASTContext ();
2019+
2020+ // === Prepare the arguments
2021+ auto args = emitStringLiteralArgs (*this , loc, text, ctx, encoding);
2022+
2023+ // === Find the constructor
2024+ auto strInitDecl = C.getStringBuiltinInitDecl (C.getStringDecl ());
2025+
2026+ RValue r = emitApplyAllocatingInitializer (loc, strInitDecl, std::move (args),
2027+ /* overriddenSelfType*/ Type (), ctx);
2028+
2029+ return std::move (r).getScalarValue ();
2030+ }
2031+
20152032// ===----------------------------------------------------------------------===//
20162033// Argument Emission
20172034// ===----------------------------------------------------------------------===//
0 commit comments