@@ -1064,24 +1064,32 @@ static bool isHardcodedCountedByPointerArgumentSafe(
1064
1064
1065
1065
// Checks if the argument passed to __single pointer is one of the following
1066
1066
// forms:
1067
- // 0. `nullptr`.
1068
- // 1. `&var`, if `var` is a variable identifier.
1069
- // 2. `&C[_]`, if `C` is a hardened container/view.
1070
- // 3. `sp.first(1).data()` and friends.
1071
- bool isSinglePointerArgumentSafe (ASTContext &Context, const Expr *Arg) {
1072
- const Expr *ArgNoImp = Arg->IgnoreParenImpCasts ();
1067
+ // 0. Anything, if the param type is a `void *__single`.
1068
+ // 1. `nullptr`.
1069
+ // 2. `&var`, if `var` is a variable identifier.
1070
+ // 3. `&C[_]`, if `C` is a hardened container/view.
1071
+ // 4. `sp.first(1).data()` and friends.
1072
+ bool isSinglePointerArgumentSafe (ASTContext &Context, QualType ParamTy,
1073
+ const Expr *Arg) {
1074
+ assert (ParamTy->isSinglePointerType ());
1073
1075
1074
1076
// Check form 0:
1075
- if (ArgNoImp-> getType ()->isNullPtrType ())
1077
+ if (ParamTy-> getPointeeType ()->isVoidType ())
1076
1078
return true ;
1077
1079
1080
+ const Expr *ArgNoImp = Arg->IgnoreParenImpCasts ();
1081
+
1078
1082
// Check form 1:
1083
+ if (ArgNoImp->getType ()->isNullPtrType ())
1084
+ return true ;
1085
+
1086
+ // Check form 2:
1079
1087
{
1080
1088
if (tryGetAddressofDRE (ArgNoImp))
1081
1089
return true ;
1082
1090
}
1083
1091
1084
- // Check form 2 :
1092
+ // Check form 3 :
1085
1093
{
1086
1094
if (const auto *UO = dyn_cast<UnaryOperator>(ArgNoImp))
1087
1095
if (UO->getOpcode () == UnaryOperator::Opcode::UO_AddrOf) {
@@ -1096,7 +1104,7 @@ bool isSinglePointerArgumentSafe(ASTContext &Context, const Expr *Arg) {
1096
1104
}
1097
1105
}
1098
1106
1099
- // Check form 3 :
1107
+ // Check form 4 :
1100
1108
if (const Expr *ExtentExpr =
1101
1109
extractExtentFromSubviewDataCall (Context, ArgNoImp)) {
1102
1110
std::optional<llvm::APSInt> ExtentVal =
@@ -3451,7 +3459,7 @@ class SinglePointerArgumentGadget : public WarningGadget {
3451
3459
ast_matchers::matchEachArgumentWithParamType (
3452
3460
*Call, [&Results, &Ctx, &Found](QualType QT, const Expr *Arg) {
3453
3461
if (isSinglePointerType (QT) &&
3454
- !isSinglePointerArgumentSafe (Ctx, Arg)) {
3462
+ !isSinglePointerArgumentSafe (Ctx, QT, Arg)) {
3455
3463
Results.emplace_back (ArgTag, DynTypedNode::create (*Arg));
3456
3464
Found = true ;
3457
3465
}
0 commit comments