Skip to content

Commit

Permalink
Add validation for cheerp::client_transparent attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DutChen18 authored and yuri91 committed Feb 12, 2024
1 parent 79848b1 commit 2a65996
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -11763,12 +11763,18 @@ def err_cheerp_invalid_plament_new : Error<
"Cheerp: Placement new is only valid on memory of the same type. If this is a custom allocator, disable it">;
def err_cheerp_invalid_static : Error<
"Cheerp: Only static member might be tagged with the legacy [[cheerp::static]] attribute">;
def err_cheerp_attribute_not_on_constructor : Error<
"Cheerp: This attribute can only be used on constructors">;
def err_cheerp_attribute_not_on_function : Error<
"Cheerp: This attribute can only be used on functions">;
def err_cheerp_attribute_on_virtual_class : Error<
"Cheerp: A virtual class cannot have the %0 attribute">;
def err_cheerp_interface_name_non_client : Error<
"Cheerp: Interface name should only be added to namespace client declarations">;
def err_cheerp_client_transparent_non_client : Error<
"Cheerp: [[cheerp::client_transparent]] should only be added to namespace client declarations">;
def err_cheerp_client_transparent_bad_parameter_count : Error<
"Cheerp: A [[cheerp::client_transparent]] constructor must have exactly one parameter">;
def err_cheerp_jsexport_TODO : Error<
"Cheerp: Unknown [[cheerp::jsexport]] related problem">;
def err_cheerp_jsexport_only_static : Error<
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8500,6 +8500,16 @@ static void handleClientLayoutAttr(Sema &S, Decl *D, const ParsedAttr &Attr) {

static void handleClientTransparentAttr(Sema &S, Decl *D, const ParsedAttr &Attr) {
D->addAttr(::new (S.Context) ClientTransparentAttr(S.Context, Attr));
// Can only be used on client conversion constructors
if (!D->getDeclContext()->isClientNamespace())
S.Diag(Attr.getLoc(), diag::err_cheerp_client_transparent_non_client);
if (auto* CD = dyn_cast<CXXConstructorDecl>(D))
{
if (CD->getNumParams() != 1)
S.Diag(Attr.getLoc(), diag::err_cheerp_client_transparent_bad_parameter_count);
}
else
S.Diag(Attr.getLoc(), diag::err_cheerp_attribute_not_on_constructor);
}

//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit 2a65996

Please sign in to comment.