@@ -36,6 +36,45 @@ bool ignoreReport(SourceLocation SLoc, ReportOptions Opts, ErrorType ET) {
36
36
return SLoc.isDisabled () || IsPCSuppressed (ET, Opts.pc , SLoc.getFilename ());
37
37
}
38
38
39
+ // / Situations in which we might emit a check for the suitability of a
40
+ // / pointer or glvalue. Needs to be kept in sync with CodeGenFunction.h in
41
+ // / clang.
42
+ enum TypeCheckKind {
43
+ // / Checking the operand of a load. Must be suitably sized and aligned.
44
+ TCK_Load,
45
+ // / Checking the destination of a store. Must be suitably sized and aligned.
46
+ TCK_Store,
47
+ // / Checking the bound value in a reference binding. Must be suitably sized
48
+ // / and aligned, but is not required to refer to an object (until the
49
+ // / reference is used), per core issue 453.
50
+ TCK_ReferenceBinding,
51
+ // / Checking the object expression in a non-static data member access. Must
52
+ // / be an object within its lifetime.
53
+ TCK_MemberAccess,
54
+ // / Checking the 'this' pointer for a call to a non-static member function.
55
+ // / Must be an object within its lifetime.
56
+ TCK_MemberCall,
57
+ // / Checking the 'this' pointer for a constructor call.
58
+ TCK_ConstructorCall,
59
+ // / Checking the operand of a static_cast to a derived pointer type. Must be
60
+ // / null or an object within its lifetime.
61
+ TCK_DowncastPointer,
62
+ // / Checking the operand of a static_cast to a derived reference type. Must
63
+ // / be an object within its lifetime.
64
+ TCK_DowncastReference,
65
+ // / Checking the operand of a cast to a base object. Must be suitably sized
66
+ // / and aligned.
67
+ TCK_Upcast,
68
+ // / Checking the operand of a cast to a virtual base object. Must be an
69
+ // / object within its lifetime.
70
+ TCK_UpcastToVirtualBase,
71
+ // / Checking the value assigned to a _Nonnull pointer. Must not be null.
72
+ TCK_NonnullAssign,
73
+ // / Checking the operand of a dynamic_cast or a typeid expression. Must be
74
+ // / null or an object within its lifetime.
75
+ TCK_DynamicOperation
76
+ };
77
+
39
78
const char *TypeCheckKinds[] = {
40
79
" load of" , " store to" , " reference binding to" , " member access within" ,
41
80
" member call on" , " constructor call on" , " downcast of" , " downcast of" ,
@@ -50,7 +89,9 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
50
89
uptr Alignment = (uptr)1 << Data->LogAlignment ;
51
90
ErrorType ET;
52
91
if (!Pointer)
53
- ET = ErrorType::NullPointerUse;
92
+ ET = (Data->TypeCheckKind == TCK_NonnullAssign)
93
+ ? ErrorType::NullPointerUseWithNullability
94
+ : ErrorType::NullPointerUse;
54
95
else if (Pointer & (Alignment - 1 ))
55
96
ET = ErrorType::MisalignedPointerUse;
56
97
else
@@ -71,6 +112,7 @@ static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
71
112
72
113
switch (ET) {
73
114
case ErrorType::NullPointerUse:
115
+ case ErrorType::NullPointerUseWithNullability:
74
116
Diag (Loc, DL_Error, ET, " %0 null pointer of type %1" )
75
117
<< TypeCheckKinds[Data->TypeCheckKind ] << Data->Type ;
76
118
break ;
@@ -604,7 +646,8 @@ static void handleNonNullReturn(NonNullReturnData *Data, SourceLocation *LocPtr,
604
646
UNREACHABLE (" source location pointer is null!" );
605
647
606
648
SourceLocation Loc = LocPtr->acquire ();
607
- ErrorType ET = ErrorType::InvalidNullReturn;
649
+ ErrorType ET = IsAttr ? ErrorType::InvalidNullReturn
650
+ : ErrorType::InvalidNullReturnWithNullability;
608
651
609
652
if (ignoreReport (Loc, Opts, ET))
610
653
return ;
@@ -648,7 +691,8 @@ void __ubsan::__ubsan_handle_nullability_return_v1_abort(
648
691
static void handleNonNullArg (NonNullArgData *Data, ReportOptions Opts,
649
692
bool IsAttr) {
650
693
SourceLocation Loc = Data->Loc .acquire ();
651
- ErrorType ET = ErrorType::InvalidNullArgument;
694
+ ErrorType ET = IsAttr ? ErrorType::InvalidNullArgument
695
+ : ErrorType::InvalidNullArgumentWithNullability;
652
696
653
697
if (ignoreReport (Loc, Opts, ET))
654
698
return ;
0 commit comments