================
@@ -132,9 +132,20 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr
*E, bool CountInBytes,
// `BoundsSafetyCheckUseOfCountAttrPtr`
//
// * When the pointee type is always an incomplete type (e.g.
- // `void`) the attribute is disallowed by this method because we know the
- // type can never be completed so there's no reason to allow it.
- InvalidTypeKind = CountedByInvalidPointeeTypeKind::INCOMPLETE;
+ // `void` in strict C mode) the attribute is disallowed by this method
+ // because we know the type can never be completed so there's no reason
+ // to allow it.
+ //
+ // Exception: In GNU mode, void has an implicit size of 1 byte for pointer
+ // arithmetic. Therefore, counted_by on void* is allowed as a GNU extension
+ // and behaves equivalently to sized_by (treating the count as bytes).
+ bool IsVoidPtrInGNUMode = PointeeTy->isVoidType() && getLangOpts().GNUMode;
----------------
efriedma-quic wrote:
The reason -std=c11 and -std=gnu11 both exist is for compatibility with old gcc
extensions: very old versions of gcc were not careful about avoiding
keywords/constructs that could overlap with future standardized keywords, and
"gnu" mode enables those keywords. We shouldn't extend it beyond that.
If you think this construct likely indicates a bug, make it warn by default;
users can decide if they want to fix their code, or just disable the warning.
https://github.com/llvm/llvm-project/pull/164737
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits