Manna updated this revision to Diff 531976. Manna retitled this revision from "[NFC][CLANG] Fix potential null pointer dereference bugs" to "[CLANG]Fix potential null pointer dereference bugs". Manna added a comment. Herald added subscribers: steakhal, martong.
Address review comment and update patch CHANGES SINCE LAST ACTION https://reviews.llvm.org/D153033/new/ https://reviews.llvm.org/D153033 Files: clang/lib/AST/ASTContext.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/Analysis/ThreadSafety.cpp clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -1204,10 +1204,12 @@ // FIXME: Add a checker option to turn this uniqueing feature off. const ExplodedNode *StreamOpenNode = getAcquisitionSite(Err, LeakSym, C); assert(StreamOpenNode && "Could not find place of stream opening."); - PathDiagnosticLocation LocUsedForUniqueing = - PathDiagnosticLocation::createBegin( - StreamOpenNode->getStmtForDiagnostics(), C.getSourceManager(), - StreamOpenNode->getLocationContext()); + + PathDiagnosticLocation LocUsedForUniqueing; + if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics()) + LocUsedForUniqueing = PathDiagnosticLocation::createBegin( + StreamStmt, C.getSourceManager(), + StreamOpenNode->getLocationContext()); std::unique_ptr<PathSensitiveBugReport> R = std::make_unique<PathSensitiveBugReport>( Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -4955,7 +4955,8 @@ }; // The matrix subscript operator ([][])is considered a single operator. // Separating the index expressions by parenthesis is not allowed. - if (base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) && + if (base && !base->getType().isNull() && + base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) && !isa<MatrixSubscriptExpr>(base)) { Diag(base->getExprLoc(), diag::err_matrix_separate_incomplete_index) << SourceRange(base->getBeginLoc(), rbLoc); Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -3365,7 +3365,7 @@ if (getDataSharingMode(CGM) != CGOpenMPRuntimeGPU::Generic) return Address::invalid(); - VD = VD->getCanonicalDecl(); + VD = cast<VarDecl>(VD->getCanonicalDecl()); auto I = FunctionGlobalizedDecls.find(CGF.CurFn); if (I == FunctionGlobalizedDecls.end()) return Address::invalid(); Index: clang/lib/Analysis/ThreadSafety.cpp =================================================================== --- clang/lib/Analysis/ThreadSafety.cpp +++ clang/lib/Analysis/ThreadSafety.cpp @@ -502,9 +502,8 @@ for (Context::iterator I = C.begin(), E = C.end(); I != E; ++I) { const NamedDecl *D = I.getKey(); D->printName(llvm::errs()); - const unsigned *i = C.lookup(D); llvm::errs() << " -> "; - dumpVarDefinitionName(*i); + dumpVarDefinitionName(I.getData()); llvm::errs() << "\n"; } } Index: clang/lib/AST/MicrosoftMangle.cpp =================================================================== --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -2693,7 +2693,7 @@ // Copy constructor closure always takes an unqualified reference. mangleFunctionArgumentType(getASTContext().getLValueReferenceType( Proto->getParamType(0) - ->getAs<LValueReferenceType>() + ->castAs<LValueReferenceType>() ->getPointeeType(), /*SpelledAsLValue=*/true), Range); Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -10030,6 +10030,9 @@ return false; ObjCTypeParamList *typeParams = iface->getTypeParamList(); + if (!typeParams) + return false; + for (unsigned i = 0, n = lhsArgs.size(); i != n; ++i) { if (ctx.hasSameType(lhsArgs[i], rhsArgs[i])) continue;
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp =================================================================== --- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp +++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp @@ -1204,10 +1204,12 @@ // FIXME: Add a checker option to turn this uniqueing feature off. const ExplodedNode *StreamOpenNode = getAcquisitionSite(Err, LeakSym, C); assert(StreamOpenNode && "Could not find place of stream opening."); - PathDiagnosticLocation LocUsedForUniqueing = - PathDiagnosticLocation::createBegin( - StreamOpenNode->getStmtForDiagnostics(), C.getSourceManager(), - StreamOpenNode->getLocationContext()); + + PathDiagnosticLocation LocUsedForUniqueing; + if (const Stmt *StreamStmt = StreamOpenNode->getStmtForDiagnostics()) + LocUsedForUniqueing = PathDiagnosticLocation::createBegin( + StreamStmt, C.getSourceManager(), + StreamOpenNode->getLocationContext()); std::unique_ptr<PathSensitiveBugReport> R = std::make_unique<PathSensitiveBugReport>( Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -4955,7 +4955,8 @@ }; // The matrix subscript operator ([][])is considered a single operator. // Separating the index expressions by parenthesis is not allowed. - if (base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) && + if (base && !base->getType().isNull() && + base->hasPlaceholderType(BuiltinType::IncompleteMatrixIdx) && !isa<MatrixSubscriptExpr>(base)) { Diag(base->getExprLoc(), diag::err_matrix_separate_incomplete_index) << SourceRange(base->getBeginLoc(), rbLoc); Index: clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp =================================================================== --- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -3365,7 +3365,7 @@ if (getDataSharingMode(CGM) != CGOpenMPRuntimeGPU::Generic) return Address::invalid(); - VD = VD->getCanonicalDecl(); + VD = cast<VarDecl>(VD->getCanonicalDecl()); auto I = FunctionGlobalizedDecls.find(CGF.CurFn); if (I == FunctionGlobalizedDecls.end()) return Address::invalid(); Index: clang/lib/Analysis/ThreadSafety.cpp =================================================================== --- clang/lib/Analysis/ThreadSafety.cpp +++ clang/lib/Analysis/ThreadSafety.cpp @@ -502,9 +502,8 @@ for (Context::iterator I = C.begin(), E = C.end(); I != E; ++I) { const NamedDecl *D = I.getKey(); D->printName(llvm::errs()); - const unsigned *i = C.lookup(D); llvm::errs() << " -> "; - dumpVarDefinitionName(*i); + dumpVarDefinitionName(I.getData()); llvm::errs() << "\n"; } } Index: clang/lib/AST/MicrosoftMangle.cpp =================================================================== --- clang/lib/AST/MicrosoftMangle.cpp +++ clang/lib/AST/MicrosoftMangle.cpp @@ -2693,7 +2693,7 @@ // Copy constructor closure always takes an unqualified reference. mangleFunctionArgumentType(getASTContext().getLValueReferenceType( Proto->getParamType(0) - ->getAs<LValueReferenceType>() + ->castAs<LValueReferenceType>() ->getPointeeType(), /*SpelledAsLValue=*/true), Range); Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -10030,6 +10030,9 @@ return false; ObjCTypeParamList *typeParams = iface->getTypeParamList(); + if (!typeParams) + return false; + for (unsigned i = 0, n = lhsArgs.size(); i != n; ++i) { if (ctx.hasSameType(lhsArgs[i], rhsArgs[i])) continue;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits