Skip to content

Commit f25c53a

Browse files
committed
[Diags] Add check for null when printing type for diags
IIUC we should never have `ParenType`s that wrap a `nullptr` type. Adding an assertion to catch that situation. In the meantime check for null types in the `DiagnosticsEngine` to prevent a crash. Fixes rdar://75740683
1 parent cbd0206 commit f25c53a

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
@@ -1443,6 +1443,11 @@ ParenType::ParenType(Type baseType, RecursiveTypeProperties properties,
14431443
: SugarType(TypeKind::Paren,
14441444
flags.isInOut() ? InOutType::get(baseType) : baseType,
14451445
properties) {
1446+
// In some situations (rdar://75740683) we appear to end up with ParenTypes
1447+
// that contain a nullptr baseType. Once this is eliminated, we can remove
1448+
// the checks for `type.isNull()` in the `DiagnosticArgumentKind::Type` case
1449+
// of `formatDiagnosticArgument`.
1450+
assert(baseType && "A ParenType should always wrap a non-null type");
14461451
Bits.ParenType.Flags = flags.toRaw();
14471452
if (flags.isInOut())
14481453
assert(!baseType->is<InOutType>() && "caller did not pass a base type");

0 commit comments

Comments
 (0)