[all-commits] [llvm/llvm-project] be37e3: [NFC][CLANG] Fix dereference issue before null che...

smanna12 via All-commits all-commits at lists.llvm.org
Fri May 19 10:17:07 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: be37e3e25982c9346df883fcc61e7b60311594a4
      https://github.com/llvm/llvm-project/commit/be37e3e25982c9346df883fcc61e7b60311594a4
  Author: Manna, Soumi <soumi.manna at intel.com>
  Date:   2023-05-19 (Fri, 19 May 2023)

  Changed paths:
    M clang/lib/Parse/ParsePragma.cpp

  Log Message:
  -----------
  [NFC][CLANG] Fix dereference issue before null check found by Coverity static analyzer tool

Reported by Coverity static analyzer tool:

Inside "ParsePragma.cpp" file, in <unnamed>::PragmaRISCVHandler::HandlePragma(clang::Preprocessor &, clang::PragmaIntroducer, clang::Token &): All paths that lead to this null pointer comparison already dereference the pointer earlier

  PP.Lex(Tok);
  II = Tok.getIdentifierInfo();
  //deref_ptr_in_call: Dereferencing pointer II.
  StringRef IntrinsicClass = II->getName();

    //Dereference before null check (REVERSE_INULL)
    //check_after_deref: Null-checking II suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
    if (!II || !(II->isStr("vector") || II->isStr("sifive_vector"))) {
      PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument)
          << PP.getSpelling(Tok) << "riscv" << /*Expected=*/true
          << "'vector' or 'sifive_vector'";
      return;
  }

This patch removes redundant StringRef type 'IntrinsicClass' and checks
II->isStr("vector") || II->isStr("sifive_vector") instead to set Actions.DeclareRISCVVBuiltins or
Actions.DeclareRISCVVectorBuiltins.

Reviewed By: erichkeane

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




More information about the All-commits mailing list