Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewriter does not recognize typedef multi-decls #651

Closed
mattmccutchen-cci opened this issue Jul 16, 2021 · 0 comments · Fixed by #657
Closed

Rewriter does not recognize typedef multi-decls #651

mattmccutchen-cci opened this issue Jul 16, 2021 · 0 comments · Fixed by #657

Comments

@mattmccutchen-cci
Copy link
Member

Typedefs can have multi-decls like typedef int *A, *B;, and Clang reports two TypedefDecls with source ranges that both start at the beginning of the statement and end at the respective names, just as Clang does for variable multi-decls like int *a, *b;. For variables, 3C recognizes that the overlapping source ranges indicate a multi-decl, and DeclRewriter::rewriteMultiDecl rewrites it properly. But the analogous behavior is not implemented for typedefs, so 3C may try to replace each TypedefDecl in a multi-decl independently and produce invalid output. For example, the following:

typedef int *A, *B;

void foo(A a, B b) {}

typedef int *C, *D;

void bar(C c, D d) {
  d = (D)1;
}

converts to:

typedef _Ptr<int> B;  // A is missing!

void foo(A a, B b) {}

typedef _Ptr<int> C, *D;  // D became a double pointer!

void bar(C c, D d) {
  d = (D)1;
}

This problem currently rarely comes up because the common use case for a typedef multi-decl is something like typedef struct { ... } FOO, *PFOO;, and 3C sees that the type of each TypedefDecl is an inline struct and refuses to modify the TypedefDecl at all. But ideally we should remove this limitation on rewriting typedefs containing inline structs (I assume I'll do it along with #542 and won't bother to file a separate issue for it), and then the multi-decl will become a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant