Skip to content

Commit

Permalink
Fix crash when checking templated base class for client_layout attribute
Browse files Browse the repository at this point in the history
When checking a client namespace class for the client_layout attribute,
we assumed that base classes are of type `CXXRecordDecl`. This is not
always the case. For example, we would get a crash when the base class
is templated:
```
namespace client {
	template<class T>
	class [[cheerp::client_layout]] Base {};
	template<class T>
	class Derived : public Base<T> {};
}
```

The client_layout check is updated to also handle templated base
classes, and to return false for other unhandled types. So we get the
normal missing client layout diagnostic for unhandled types instead of a
segmentation fault.
  • Loading branch information
DutChen18 authored and yuri91 committed Feb 26, 2024
1 parent c245c83 commit 33b8bb5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17545,7 +17545,14 @@ static bool hasClientLayout(CXXRecordDecl* RD)
return true;
if (RD->bases_begin() == RD->bases_end())
return false;
return hasClientLayout(RD->bases_begin()->getType()->getAsCXXRecordDecl());
QualType type = RD->bases_begin()->getType();
if (auto* decl = type->getAsCXXRecordDecl())
return hasClientLayout(decl);
if (auto* templateType = type->getAs<TemplateSpecializationType>())
if (auto* templateDecl = templateType->getTemplateName().getAsTemplateDecl())
if (auto* decl = dyn_cast<CXXRecordDecl>(templateDecl->getTemplatedDecl()))
return hasClientLayout(decl);
return false;
}
void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
SourceRange BraceRange) {
Expand Down

0 comments on commit 33b8bb5

Please sign in to comment.