[all-commits] [llvm/llvm-project] 1756d6: [llvm][clang][mlir] Add checks for the return valu...

Fangrui Song via All-commits all-commits at lists.llvm.org
Sat Nov 21 21:04:27 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 1756d67934bb5fe3b12bdb5fa55d61f61bd70bc5
      https://github.com/llvm/llvm-project/commit/1756d67934bb5fe3b12bdb5fa55d61f61bd70bc5
  Author: Ella Ma <alansnape3058 at gmail.com>
  Date:   2020-11-21 (Sat, 21 Nov 2020)

  Changed paths:
    M clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
    M clang/tools/driver/cc1as_main.cpp
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
    M llvm/lib/CodeGen/LLVMTargetMachine.cpp
    M llvm/lib/CodeGen/ParallelCG.cpp
    M llvm/lib/LTO/LTOBackend.cpp
    M llvm/lib/LTO/LTOCodeGenerator.cpp
    M llvm/lib/LTO/LTOModule.cpp
    M llvm/lib/LTO/ThinLTOCodeGenerator.cpp
    M llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
    M llvm/tools/llvm-exegesis/lib/LlvmState.cpp
    M llvm/tools/llvm-exegesis/llvm-exegesis.cpp
    M llvm/tools/llvm-mc/llvm-mc.cpp
    M llvm/tools/llvm-mca/llvm-mca.cpp
    M llvm/tools/llvm-ml/llvm-ml.cpp
    M llvm/tools/llvm-objdump/MachODump.cpp
    M llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
    M mlir/lib/Conversion/GPUCommon/ConvertKernelFuncToBlob.cpp
    M mlir/lib/ExecutionEngine/ExecutionEngine.cpp

  Log Message:
  -----------
  [llvm][clang][mlir] Add checks for the return values from Target::createXXX to prevent protential null deref

All these potential null pointer dereferences are reported by my static analyzer for null smart pointer dereferences, which has a different implementation from `alpha.cplusplus.SmartPtr`.

The checked pointers in this patch are initialized by Target::createXXX functions. When the creator function pointer is not correctly set, a null pointer will be returned, or the creator function may originally return a null pointer.

Some of them may not make sense as they may be checked before entering the function, but I fixed them all in this patch. I submit this fix because 1) similar checks are found in some other places in the LLVM codebase for the same return value of the function; and, 2) some of the pointers are dereferenced before they are checked, which may definitely trigger a null pointer dereference if the return value is nullptr.

Reviewed By: tejohnson, MaskRay, jpienaar

Differential Revision: https://reviews.llvm.org/D91410




More information about the All-commits mailing list