[clang] b922554 - DeferredDiagnosticsEmitter crashes

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 8 08:45:24 PDT 2020


Author: Geoff Levner
Date: 2020-10-08T11:42:21-04:00
New Revision: b9225543e844bee5091aa16108e0c54bd2abe485

URL: https://github.com/llvm/llvm-project/commit/b9225543e844bee5091aa16108e0c54bd2abe485
DIFF: https://github.com/llvm/llvm-project/commit/b9225543e844bee5091aa16108e0c54bd2abe485.diff

LOG: DeferredDiagnosticsEmitter crashes

Patch VisitCXXDeleteExpr() in clang::UsedDeclVisitor to avoid it crashing
when the expression's destroyed type is null. According to the comments
in CXXDeleteExpr::getDestroyedType(), this can happen when the type to
delete is a dependent type.

Patch by Geoff Levner.

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

Added: 
    

Modified: 
    clang/lib/Sema/UsedDeclVisitor.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/UsedDeclVisitor.h b/clang/lib/Sema/UsedDeclVisitor.h
index d207e07f451a..c33d30478e2a 100644
--- a/clang/lib/Sema/UsedDeclVisitor.h
+++ b/clang/lib/Sema/UsedDeclVisitor.h
@@ -67,10 +67,13 @@ class UsedDeclVisitor : public EvaluatedExprVisitor<Derived> {
   void VisitCXXDeleteExpr(CXXDeleteExpr *E) {
     if (E->getOperatorDelete())
       asImpl().visitUsedDecl(E->getBeginLoc(), E->getOperatorDelete());
-    QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType());
-    if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
-      CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
-      asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+    QualType DestroyedOrNull = E->getDestroyedType();
+    if (!DestroyedOrNull.isNull()) {
+      QualType Destroyed = S.Context.getBaseElementType(DestroyedOrNull);
+      if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
+        CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
+        asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
+      }
     }
 
     Inherited::VisitCXXDeleteExpr(E);


        


More information about the cfe-commits mailing list