Skip to content

Commit

Permalink
[HIP][OpenMP] Fix assertion in deferred diag
Browse files Browse the repository at this point in the history
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

Reviewed by: Artem Belevich, John McCall

Differential Revision: https://reviews.llvm.org/D112235
  • Loading branch information
yxsamliu committed Oct 25, 2021
1 parent 5c46986 commit a543584
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion clang/lib/Sema/UsedDeclVisitor.h
Expand Up @@ -72,7 +72,8 @@ class UsedDeclVisitor : public EvaluatedExprVisitor<Derived> {
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));
}
}

Expand Down
13 changes: 11 additions & 2 deletions clang/test/OpenMP/deferred-diags.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -37,3 +35,14 @@ class A : public B {
}
}
};

// Test that deleting an incomplete class type doesn't cause an 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

0 comments on commit a543584

Please sign in to comment.