Manna created this revision. Manna added a reviewer: erichkeane. Herald added subscribers: manas, ASDenysPetrov, luismarques, s.egerton, dkrupp, donat.nagy, Szelethus, PkmX, a.sidorin, simoncook, baloghadamsoftware, arichardson. Herald added a project: All. Manna requested review of this revision. Herald added a subscriber: pcwang-thead. Herald added a project: clang.
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 removes duplicate code and moves the line `StringRef IntrinsicClass = II->getName()` after null checking `II` Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150895 Files: clang/lib/Parse/ParsePragma.cpp Index: clang/lib/Parse/ParsePragma.cpp =================================================================== --- clang/lib/Parse/ParsePragma.cpp +++ clang/lib/Parse/ParsePragma.cpp @@ -4040,8 +4040,6 @@ } PP.Lex(Tok); - II = Tok.getIdentifierInfo(); - StringRef IntrinsicClass = II->getName(); if (!II || !(II->isStr("vector") || II->isStr("sifive_vector"))) { PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument) << PP.getSpelling(Tok) << "riscv" << /*Expected=*/true @@ -4056,6 +4054,7 @@ return; } + StringRef IntrinsicClass = II->getName(); if (IntrinsicClass == "vector") Actions.DeclareRISCVVBuiltins = true; else if (IntrinsicClass == "sifive_vector")
Index: clang/lib/Parse/ParsePragma.cpp =================================================================== --- clang/lib/Parse/ParsePragma.cpp +++ clang/lib/Parse/ParsePragma.cpp @@ -4040,8 +4040,6 @@ } PP.Lex(Tok); - II = Tok.getIdentifierInfo(); - StringRef IntrinsicClass = II->getName(); if (!II || !(II->isStr("vector") || II->isStr("sifive_vector"))) { PP.Diag(Tok.getLocation(), diag::warn_pragma_invalid_argument) << PP.getSpelling(Tok) << "riscv" << /*Expected=*/true @@ -4056,6 +4054,7 @@ return; } + StringRef IntrinsicClass = II->getName(); if (IntrinsicClass == "vector") Actions.DeclareRISCVVBuiltins = true; else if (IntrinsicClass == "sifive_vector")
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits