Skip to content

Commit e4f4b89

Browse files
authored
Merge pull request #36591 from ahoppen/pr/no-nullptr-sugared-types
[Diags] Add check for null when printing type for diags
2 parents 7a17592 + f25c53a commit e4f4b89

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,13 +556,27 @@ static void formatDiagnosticArgument(StringRef Modifier,
556556

557557
if (Arg.getKind() == DiagnosticArgumentKind::Type) {
558558
type = Arg.getAsType()->getWithoutParens();
559+
if (type.isNull()) {
560+
// FIXME: We should never receive a nullptr here, but this is causing
561+
// crashes (rdar://75740683). Remove once ParenType never contains
562+
// nullptr as the underlying type.
563+
Out << "<null>";
564+
break;
565+
}
559566
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
560567
printOptions.PrintFunctionRepresentationAttrs =
561568
PrintOptions::FunctionRepresentationMode::Full;
562569
needsQualification = typeSpellingIsAmbiguous(type, Args, printOptions);
563570
} else {
564571
assert(Arg.getKind() == DiagnosticArgumentKind::FullyQualifiedType);
565572
type = Arg.getAsFullyQualifiedType().getType()->getWithoutParens();
573+
if (type.isNull()) {
574+
// FIXME: We should never receive a nullptr here, but this is causing
575+
// crashes (rdar://75740683). Remove once ParenType never contains
576+
// nullptr as the underlying type.
577+
Out << "<null>";
578+
break;
579+
}
566580
if (type->getASTContext().TypeCheckerOpts.PrintFullConvention)
567581
printOptions.PrintFunctionRepresentationAttrs =
568582
PrintOptions::FunctionRepresentationMode::Full;

lib/AST/Type.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,11 @@ ParenType::ParenType(Type baseType, RecursiveTypeProperties properties,
14441444
: SugarType(TypeKind::Paren,
14451445
flags.isInOut() ? InOutType::get(baseType) : baseType,
14461446
properties) {
1447+
// In some situations (rdar://75740683) we appear to end up with ParenTypes
1448+
// that contain a nullptr baseType. Once this is eliminated, we can remove
1449+
// the checks for `type.isNull()` in the `DiagnosticArgumentKind::Type` case
1450+
// of `formatDiagnosticArgument`.
1451+
assert(baseType && "A ParenType should always wrap a non-null type");
14471452
Bits.ParenType.Flags = flags.toRaw();
14481453
if (flags.isInOut())
14491454
assert(!baseType->is<InOutType>() && "caller did not pass a base type");

0 commit comments

Comments
 (0)