[PATCH] D15324: [Sema] Emit warnings when comparing result of a function with `returns_nonnull` to null
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 8 05:43:44 PST 2015
aaron.ballman added a subscriber: aaron.ballman.
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2747
@@ +2746,3 @@
+ "comparison of nonnull %select{function call|parameter}0 '%1' "
+ "%select{not |}2equal to a null pointer is %select{true|false}2 on first "
+ "encounter">,
----------------
I know this is existing behavior, but can you quote true and false in this diagnostic, similar to the way true is quoted above?
================
Comment at: lib/Sema/SemaChecking.cpp:7674
@@ +7673,3 @@
+ : diag::warn_cast_nonnull_to_bool;
+ Diag(E->getExprLoc(), DiagID) << int(IsParam) << S.str()
+ << E->getSourceRange() << Range << IsEqual;
----------------
No need to cast IsParam to int; the diagnostic builder already does the right thing here.
================
Comment at: lib/Sema/SemaChecking.cpp:7682
@@ +7681,3 @@
+ if (Callee->hasAttr<ReturnsNonNullAttr>())
+ return ComplainAboutNonnullParamOrCall(false);
+
----------------
I think this should be:
```
if (Callee->hasAttr<ReturnsNonNullAttr>() &&
ComplainAboutNonnullParamOrCall(false))
return;
```
Otherwise, we skip out on the rest of the checking in the presence of ReturnsNonNullAttr.
================
Comment at: lib/Sema/SemaChecking.cpp:7716
@@ -7711,1 +7715,3 @@
+ (AttrNonNull[i] || PV->hasAttr<NonNullAttr>()))
+ return ComplainAboutNonnullParamOrCall(true);
}
----------------
Same here as above. The return should only be on failure.
http://reviews.llvm.org/D15324
More information about the cfe-commits
mailing list