[libc-commits] [PATCH] D85790: [libc][NFC] Extend <ASSERT|EXPECT>_STR* macros to compare with nullptr.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Aug 11 15:09:44 PDT 2020


sivachandra created this revision.
sivachandra added reviewers: abrachet, cgyurgyik.
Herald added subscribers: libc-commits, ecnelises, tschuett.
Herald added a project: libc-project.
sivachandra requested review of this revision.

In future, pointer comparison might also need to be extended to compare
with nullptr values. That can be taken up when needed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85790

Files:
  libc/utils/UnitTest/Test.cpp


Index: libc/utils/UnitTest/Test.cpp
===================================================================
--- libc/utils/UnitTest/Test.cpp
+++ libc/utils/UnitTest/Test.cpp
@@ -242,6 +242,8 @@
 bool Test::testStrEq(RunContext &Ctx, const char *LHS, const char *RHS,
                      const char *LHSStr, const char *RHSStr, const char *File,
                      unsigned long Line) {
+  if (LHS == nullptr || RHS == nullptr)
+    return LHS == RHS;
   return internal::test(Ctx, Cond_EQ, llvm::StringRef(LHS),
                         llvm::StringRef(RHS), LHSStr, RHSStr, File, Line);
 }
@@ -249,6 +251,8 @@
 bool Test::testStrNe(RunContext &Ctx, const char *LHS, const char *RHS,
                      const char *LHSStr, const char *RHSStr, const char *File,
                      unsigned long Line) {
+  if (LHS == nullptr || RHS == nullptr)
+    return LHS != RHS;
   return internal::test(Ctx, Cond_NE, llvm::StringRef(LHS),
                         llvm::StringRef(RHS), LHSStr, RHSStr, File, Line);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85790.284910.patch
Type: text/x-patch
Size: 1014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200811/077dde97/attachment.bin>


More information about the libc-commits mailing list