[PATCH] D25731: [analyzer] NumberObjectConversion: Support OSNumber and CFNumberRef.

Anna Zaks via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 21 10:03:10 PDT 2016


zaks.anna added inline comments.


================
Comment at: test/Analysis/number-object-conversion.c:14
+  if (p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean value for branching; please compare the pointer to NULL instead to suppress this warning}}
+  if (!p) {} // expected-warning{{Converting 'CFNumberRef' to a plain boolean value for branching; please compare the pointer to NULL instead to suppress this warning}}
+  p ? 1 : 2; // expected-warning{{Converting 'CFNumberRef' to a plain boolean value for branching; please compare the pointer to NULL instead to suppress this warning}}
----------------
NoQ wrote:
> zaks.anna wrote:
> > How about:
> > "Converting 'CFNumberRef' pointer to a plain boolean value; instead, compare the pointer to NULL or compare to the encapsulated scalar value"
> > 
> > - I've added "pointer".
> > - I would remove "for branching". Does it add anything?
> > - Also, we should remove "please" as it makes the warning text longer.
> > 
> > I would remove "for branching". Does it add anything?
> 
> Because there's otherwise no obvious boolean value around, i wanted to point out what exactly is going on.
> 
> > or compare to the encapsulated scalar value
> 
> They don't necessarily compare the value. Maybe "take"?
> 
> > I've added "pointer".
> 
> Not sure it's worth keeping for other objects ("`'NSNumber *' pointer`" sounds like a pointer to a pointer).
>> or compare to the encapsulated scalar value
> They don't necessarily compare the value. Maybe "take"?

OSBoolean or CFNumber:
[Comparing|Converting] a pointer value of type '[CFNumberRef|NSNumber *]' to a scalar [boolean|integer] value; instead, either compare the pointer to [NULL|nullptr|nil] or [call [APIName] | compare the result of calling [API Name]].

NSNumber or OSNumber:
Converting a pointer value of type '[NSNumber *]' to a scalar [boolean|integer] value; instead, either compare the pointer to [NULL|nullptr|nil] or call a method on '[NSNumber *]' to get the scalar value.

Comparing a pointer value of type '[NSNumber *]' to a scalar [boolean|integer] value; instead, either compare the pointer to [NULL|nullptr|nil] or call a method on '[NSNumber *]' to get the scalar value.



================
Comment at: test/Analysis/number-object-conversion.c:23
+#endif
+  if (p > 0) {} // expected-warning{{Converting 'CFNumberRef' pointer to a plain integer value; pointer value is being used instead}}
+  int x = p; // expected-warning{{Converting 'CFNumberRef' pointer to a plain integer value; pointer value is being used instead}}
----------------
Comparing a pointer value of type '[CFNumberRef|NSNumber *]' to a primitive [boolean|integer] value; did you mean to compare the result of calling [API Name].


================
Comment at: test/Analysis/number-object-conversion.cpp:32
+  p ? 1 : 2; // expected-warning{{Converting 'const class OSBoolean *' pointer to a branch condition; instead, compare the pointer to nullptr or take the encapsulated scalar value}}
+  (bool)p; // expected-warning{{Converting 'const class OSBoolean *' pointer to a plain bool value; instead, compare the pointer to nullptr or take the encapsulated scalar value}}
+#else
----------------
Converting a pointer value of type '[CFNumberRef|NSNumber *]' to a primitive [boolean|integer] value; did you mean to call [APIName].



================
Comment at: test/Analysis/number-object-conversion.cpp:41
+  x = p; // expected-warning{{Converting 'const class OSBoolean *' pointer to a plain bool value; pointer value is being used instead}}
+  takes_bool(p); // expected-warning{{Converting 'const class OSBoolean *' pointer to a plain bool value; pointer value is being used instead}}
   takes_bool(x); // no-warning
----------------
Same as cast.


https://reviews.llvm.org/D25731





More information about the cfe-commits mailing list