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

Check the TagDecl in TypedefNameDecl for extra attributes #69

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions libcextract/PrettyPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,19 @@ SourceLocation PrettyPrint::Get_Expanded_Loc(Decl *decl)
}
}
}

/* In case this decl is a TypedefNameDecl, we also need to check for the
struct definition for extra attributes. See small/attr-10.c testscase
for an example where this happens. */
if (TypedefNameDecl *typedecl = dyn_cast<TypedefNameDecl>(decl)) {
if (TagDecl *tag = typedecl->getAnonDeclWithTypedefName()) {
SourceLocation tag_furthest = PrettyPrint::Get_Expanded_Loc(tag);
if (Is_Before(furthest, tag_furthest)) {
furthest = tag_furthest;
}
}
}

return furthest;
}

Expand Down
29 changes: 29 additions & 0 deletions testsuite/small/attr-10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* { dg-options "-DCE_EXTRACT_FUNCTIONS=main -DCE_NO_EXTERNALIZATION" }*/

typedef unsigned short int sa_family_t;
typedef unsigned int __socklen_t;
typedef __socklen_t socklen_t;
typedef int ares_socket_t;
typedef socklen_t ares_socklen_t;

struct sockaddr {
sa_family_t sa_family;
char sa_data[14];
};

typedef union {
struct sockaddr *__restrict __sockaddr__;
} __SOCKADDR_ARG __attribute__((__transparent_union__));

extern int getsockname(int __fd, __SOCKADDR_ARG __addr,
socklen_t *__restrict __len)
__attribute__((__nothrow__));

int main(void) {
struct sockaddr *src_addr;
ares_socket_t sock;
ares_socklen_t len;
getsockname(sock, src_addr, &len);
}

/* { dg-final { scan-tree-dump "__attribute__\(\(__transparent_union__\)\)" } } */
Loading