[PATCH] D112235: [HIP][OpenMP] Fix assertion in deferred diag due to incomplete class definition

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 21 10:06:21 PDT 2021


yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall.
Herald added a subscriber: guansong.
yaxunl requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Fix assertion in UsedDeclVisitor where clang is trying to look up a destructor for
a forward declared class.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=52250


https://reviews.llvm.org/D112235

Files:
  clang/lib/Sema/UsedDeclVisitor.h
  clang/test/OpenMP/deferred-diags.cpp


Index: clang/test/OpenMP/deferred-diags.cpp
===================================================================
--- clang/test/OpenMP/deferred-diags.cpp
+++ clang/test/OpenMP/deferred-diags.cpp
@@ -6,8 +6,6 @@
 // RUN:            -verify-ignore-unexpected=note \
 // RUN:            -fopenmp -o - %s
 
-// expected-no-diagnostics
-
 // Test no infinite recursion in DeferredDiagnosticEmitter.
 constexpr int foo(int *x) {
   return 0;
@@ -37,3 +35,15 @@
      }
   }
 };
+
+// Test deleting object with incomplete class definition does not causing
+// assertion.
+namespace TestDeleteIncompleteClassDefinition {
+struct a;
+struct b {
+  b() {
+    delete c;
+  } // expected-warning {{deleting pointer to incomplete type 'TestDeleteIncompleteClassDefinition::a' may cause undefined behavior}}
+  a *c;
+};
+} // namespace TestDeleteIncompleteClassDefinition
Index: clang/lib/Sema/UsedDeclVisitor.h
===================================================================
--- clang/lib/Sema/UsedDeclVisitor.h
+++ clang/lib/Sema/UsedDeclVisitor.h
@@ -72,7 +72,8 @@
       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));
+        if (Record->getDefinition())
+          asImpl().visitUsedDecl(E->getBeginLoc(), S.LookupDestructor(Record));
       }
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112235.381307.patch
Type: text/x-patch
Size: 1507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211021/eebd388c/attachment.bin>


More information about the cfe-commits mailing list