From d7d564148725de3b7cc8dcf3d3cb6c2b88cb117a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 4 Jun 2025 23:51:03 -0400 Subject: [PATCH] AST: Add assertion to BuiltinLiteralExpr::setBuiltinInitializer() I just spent way too long debugging an issue where a null pointer was passed here, and SILGen crashed much later. --- include/swift/AST/Expr.h | 4 +--- lib/AST/Expr.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index fa7fc3664b083..7d8e07de69957 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -696,9 +696,7 @@ class BuiltinLiteralExpr : public LiteralExpr { /// Set the builtin initializer that will be used to construct the /// literal. - void setBuiltinInitializer(ConcreteDeclRef builtinInitializer) { - BuiltinInitializer = builtinInitializer; - } + void setBuiltinInitializer(ConcreteDeclRef builtinInitializer); }; /// The 'nil' literal. diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index be42874021291..03209bd1c14c7 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1089,7 +1089,14 @@ StringRef LiteralExpr::getLiteralKindDescription() const { llvm_unreachable("Unhandled literal"); } -IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc) { +void BuiltinLiteralExpr::setBuiltinInitializer( + ConcreteDeclRef builtinInitializer) { + ASSERT(builtinInitializer); + BuiltinInitializer = builtinInitializer; +} + +IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned( + ASTContext &C, unsigned value, SourceLoc loc) { llvm::SmallString<8> Scratch; llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false); auto Text = C.AllocateCopy(StringRef(Scratch));