[PATCH] D91960: [llvm][unittests] Fix protential nullptr dereferences due to unchecked return value or EXPECT_* macro

Ella Ma via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 23 05:04:32 PST 2020


OikawaKirie created this revision.
OikawaKirie added reviewers: Tyker, mtrofin, kbarton, lebedev.ri, yamauchi, fhahn, vitalybuka, jmolloy, aqjune, fpetrogalli, sanwou01, vsk, aprantl, nickdesaulniers, sdmitriev, amontanez, friss, JDevlieghere, thegameg, andrew.w.kaylor, samparker, bbn, modocache, yrouban, Whitney, aeubanks, rnk, fedor.sergeev, greened, jsji.
OikawaKirie added a project: LLVM.
Herald added subscribers: llvm-commits, okura, kuter, zzheng, nemanjai.
OikawaKirie requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added a reviewer: baziotis.

These problems are reported by my static analyzer on smart pointers.

In GTest, the `ASSERT_*` macro will stop the execution of the current test case or function, while `EXPECT_*` will not. Besides, If the `ASSERT_*` macro is used in a sub-function of a test case, it will only stop the execution of the current function and return to the caller test function. Although a test failure will be reported, the test program will still crash, which will skip some unit tests in the current test program. (See https://github.com/google/googletest/blob/master/googletest/docs/primer.md#basic-assertions)
In addition, in some test cases, the return value of a parser function is checked in a wrapper function, but both branches are allowed to reach the dereference site.

In this patch, I fixed some of the nullptr dereference with the problems above. The fix will not dismiss any check failures but can make the test program skip the current test case and continue with the next, rather than crash immediately.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91960

Files:
  llvm/unittests/Analysis/AssumeBundleQueriesTest.cpp
  llvm/unittests/Analysis/FunctionPropertiesAnalysisTest.cpp
  llvm/unittests/Analysis/IVDescriptorsTest.cpp
  llvm/unittests/Analysis/LoadsTest.cpp
  llvm/unittests/Analysis/ValueTrackingTest.cpp
  llvm/unittests/Analysis/VectorFunctionABITest.cpp
  llvm/unittests/IR/DebugInfoTest.cpp
  llvm/unittests/IR/InstructionsTest.cpp
  llvm/unittests/IR/LegacyPassManagerTest.cpp
  llvm/unittests/InterfaceStub/ELFYAMLTest.cpp
  llvm/unittests/MC/DwarfLineTables.cpp
  llvm/unittests/MC/MCInstPrinter.cpp
  llvm/unittests/Remarks/BitstreamRemarksParsingTest.cpp
  llvm/unittests/Remarks/YAMLRemarksParsingTest.cpp
  llvm/unittests/Support/MemoryBufferTest.cpp
  llvm/unittests/Target/ARM/MachineInstrTest.cpp
  llvm/unittests/Transforms/IPO/AttributorTestBase.h
  llvm/unittests/Transforms/Utils/BasicBlockUtilsTest.cpp
  llvm/unittests/Transforms/Utils/CallPromotionUtilsTest.cpp
  llvm/unittests/Transforms/Utils/CloningTest.cpp
  llvm/unittests/Transforms/Utils/CodeMoverUtilsTest.cpp
  llvm/unittests/Transforms/Utils/LocalTest.cpp
  llvm/unittests/Transforms/Utils/LoopRotationUtilsTest.cpp
  llvm/unittests/Transforms/Utils/LoopUtilsTest.cpp
  llvm/unittests/Transforms/Utils/UnrollLoopTest.cpp
  llvm/unittests/tools/llvm-exegesis/PowerPC/AnalysisTest.cpp
  llvm/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91960.307036.patch
Type: text/x-patch
Size: 66417 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201123/6689fafe/attachment.bin>


More information about the llvm-commits mailing list