@@ -220,41 +220,40 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr *E, bool CountInBytes,
220
220
221
221
static void EmitIncompleteCountedByPointeeNotes (Sema &S,
222
222
const CountAttributedType *CATy,
223
- NamedDecl *IncompleteTyDecl,
224
- bool NoteAttrLocation = true ) {
223
+ NamedDecl *IncompleteTyDecl) {
225
224
assert (IncompleteTyDecl == nullptr || isa<TypeDecl>(IncompleteTyDecl));
226
225
227
- if (NoteAttrLocation ) {
228
- // Note where the attribute is declared
229
- // This is an approximation that's not quite right. This points to the
230
- // the expression inside the attribute rather than the attribute itself .
226
+ if (IncompleteTyDecl ) {
227
+ // Suggest completing the pointee type if its a named typed (i.e.
228
+ // IncompleteTyDecl isn't nullptr). Suggest this first as it is more likely
229
+ // to be the correct fix .
231
230
//
232
- // TODO: Implement logic to find the relevant TypeLoc for the attribute and
233
- // get the SourceRange from that (#113582).
234
- SourceRange AttrSrcRange = CATy->getCountExpr ()->getSourceRange ();
235
- S.Diag (AttrSrcRange.getBegin (), diag::note_named_attribute)
236
- << CATy->getAttributeName (/* WithMacroPrefix=*/ true ) << AttrSrcRange;
231
+ // Note the `IncompleteTyDecl` type is the underlying type which might not
232
+ // be the same as `CATy->getPointeeType()` which could be a typedef.
233
+ //
234
+ // The diagnostic printed will be at the location of the underlying type but
235
+ // the diagnostic text will print the type of `CATy->getPointeeType()` which
236
+ // could be a typedef name rather than the underlying type. This is ok
237
+ // though because the diagnostic will print the underlying type name too.
238
+ S.Diag (IncompleteTyDecl->getBeginLoc (),
239
+ diag::note_counted_by_consider_completing_pointee_ty)
240
+ << CATy->getPointeeType ();
237
241
}
238
242
239
- if (!IncompleteTyDecl)
240
- return ;
241
-
242
- // If there's an associated forward declaration display it to emphasize
243
- // why the type is incomplete (all we have is a forward declaration).
244
-
245
- // Note the `IncompleteTyDecl` type is the underlying type which might not
246
- // be the same as `CATy->getPointeeType()` which could be a typedef.
243
+ // Suggest using __sized_by(_or_null) instead of __counted_by(_or_null) as
244
+ // __sized_by(_or_null) doesn't have the complete type restriction.
245
+ //
246
+ // We use the source range of the expression on the CountAttributedType as an
247
+ // approximation for the source range of the attribute. This isn't quite right
248
+ // but isn't easy to fix right now.
247
249
//
248
- // The diagnostic printed will be at the location of the underlying type but
249
- // the diagnostic text will print the type of `CATy->getPointeeType()` which
250
- // could be a typedef name rather than the underlying type. This is ok
251
- // though because the diagnostic will print the underlying type name too.
252
- // E.g:
250
+ // TODO: Implement logic to find the relevant TypeLoc for the attribute and
251
+ // get the SourceRange from that (#113582).
253
252
//
254
- // `forward declaration of 'Incomplete_Struct_t'
255
- // (aka 'struct IncompleteStructTy')`
256
- S.Diag (IncompleteTyDecl-> getBeginLoc (), diag::note_forward_declaration )
257
- << CATy->getPointeeType () ;
253
+ // TODO: We should emit a fix-it here.
254
+ SourceRange AttrSrcRange = CATy-> getCountExpr ()-> getSourceRange ();
255
+ S.Diag (AttrSrcRange. getBegin (), diag::note_counted_by_consider_using_sized_by )
256
+ << CATy->isOrNull () << AttrSrcRange ;
258
257
}
259
258
260
259
static std::tuple<const CountAttributedType *, QualType>
0 commit comments