@@ -1076,24 +1076,32 @@ static bool isHardcodedCountedByPointerArgumentSafe(
1076
1076
1077
1077
// Checks if the argument passed to __single pointer is one of the following
1078
1078
// forms:
1079
- // 0. `nullptr`.
1080
- // 1. `&var`, if `var` is a variable identifier.
1081
- // 2. `&C[_]`, if `C` is a hardened container/view.
1082
- // 3. `sp.first(1).data()` and friends.
1083
- bool isSinglePointerArgumentSafe (ASTContext &Context, const Expr *Arg) {
1084
- const Expr *ArgNoImp = Arg->IgnoreParenImpCasts ();
1079
+ // 0. Anything, if the param type is a `void *__single`.
1080
+ // 1. `nullptr`.
1081
+ // 2. `&var`, if `var` is a variable identifier.
1082
+ // 3. `&C[_]`, if `C` is a hardened container/view.
1083
+ // 4. `sp.first(1).data()` and friends.
1084
+ bool isSinglePointerArgumentSafe (ASTContext &Context, QualType ParamTy,
1085
+ const Expr *Arg) {
1086
+ assert (ParamTy->isSinglePointerType ());
1085
1087
1086
1088
// Check form 0:
1087
- if (ArgNoImp-> getType ()->isNullPtrType ())
1089
+ if (ParamTy-> getPointeeType ()->isVoidType ())
1088
1090
return true ;
1089
1091
1092
+ const Expr *ArgNoImp = Arg->IgnoreParenImpCasts ();
1093
+
1090
1094
// Check form 1:
1095
+ if (ArgNoImp->getType ()->isNullPtrType ())
1096
+ return true ;
1097
+
1098
+ // Check form 2:
1091
1099
{
1092
1100
if (tryGetAddressofDRE (ArgNoImp))
1093
1101
return true ;
1094
1102
}
1095
1103
1096
- // Check form 2 :
1104
+ // Check form 3 :
1097
1105
{
1098
1106
if (const auto *UO = dyn_cast<UnaryOperator>(ArgNoImp))
1099
1107
if (UO->getOpcode () == UnaryOperator::Opcode::UO_AddrOf) {
@@ -1108,7 +1116,7 @@ bool isSinglePointerArgumentSafe(ASTContext &Context, const Expr *Arg) {
1108
1116
}
1109
1117
}
1110
1118
1111
- // Check form 3 :
1119
+ // Check form 4 :
1112
1120
if (const Expr *ExtentExpr =
1113
1121
extractExtentFromSubviewDataCall (Context, ArgNoImp)) {
1114
1122
std::optional<llvm::APSInt> ExtentVal =
@@ -3463,7 +3471,7 @@ class SinglePointerArgumentGadget : public WarningGadget {
3463
3471
ast_matchers::matchEachArgumentWithParamType (
3464
3472
*Call, [&Results, &Ctx, &Found](QualType QT, const Expr *Arg) {
3465
3473
if (isSinglePointerType (QT) &&
3466
- !isSinglePointerArgumentSafe (Ctx, Arg)) {
3474
+ !isSinglePointerArgumentSafe (Ctx, QT, Arg)) {
3467
3475
Results.emplace_back (ArgTag, DynTypedNode::create (*Arg));
3468
3476
Found = true ;
3469
3477
}
0 commit comments