[PATCH] Add warnings so that Clang can catch most of the cases that GCC's -Waddress can catch

Richard Trieu rtrieu at google.com
Wed Feb 19 19:13:48 PST 2014



================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:2317
@@ -2299,1 +2316,3 @@
+  "pointer is always %select{true|false}1">,
+  InGroup<TautologicalPointerCompare>;
 
----------------
David Majnemer wrote:
> `warn_null_array_compare`, `warn_null_function_compare`, and `warn_null_pointer_compare` could be combined using `%select`
Merge the six diagnostics down to two.  Also renamed the notes so they aren't specific to the bool conversion warning.

================
Comment at: lib/Sema/SemaChecking.cpp:5698
@@ +5697,3 @@
+/// \param Range Extra SourceRange to highlight in the diagnostic
+void Sema::DiagnosePointer(Expr *E, Expr::NullPointerConstantKind NullKind,
+                           bool IsEqual, SourceRange Range) {
----------------
Richard Trieu wrote:
> David Majnemer wrote:
> > `DiagnosePointer` is rather vague, perhaps something like `diagnoseTautologicalPointerCompare` ?
> Tautological compare is only half of the warnings generated.  There are also pointer to bool conversion warnings here too.
Switched to `DiagnoseAlwaysNonNullPointer`.

================
Comment at: lib/Sema/SemaChecking.cpp:5710
@@ +5709,3 @@
+  bool function = false;
+  bool addressOf = false;
+
----------------
David Majnemer wrote:
> Shouldn't these be capitalized? Something like `IsArray`, `IsFunction`, etc.?
Fixed.

================
Comment at: lib/Sema/SemaChecking.cpp:5751
@@ +5750,3 @@
+  // Pretty print the expression for the diagnostic.
+  std::string str;
+  llvm::raw_string_ostream S(str);
----------------
David Majnemer wrote:
> Same goes for this variable.
Fixed.


http://llvm-reviews.chandlerc.com/D2645



More information about the cfe-commits mailing list