Skip to content

Rewriter does not recognize typedef multi-decls #651

Closed
@mattmccutchen-cci

Description

@mattmccutchen-cci

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions