1/* Reduced test case from PR53703. Used to ICE. */ 2 3/* { dg-do compile } */ 4/* { dg-options "-w" } */ 5 6typedef long unsigned int size_t; 7typedef unsigned short int sa_family_t; 8struct sockaddr {}; 9typedef unsigned char __u8; 10typedef unsigned short __u16; 11typedef unsigned int __u32; 12struct nlmsghdr { 13 __u32 nlmsg_len; 14 __u16 nlmsg_type; 15}; 16struct ifaddrmsg { 17 __u8 ifa_family; 18}; 19enum { 20 IFA_ADDRESS, 21 IFA_LOCAL, 22}; 23enum { 24 RTM_NEWLINK = 16, 25 RTM_NEWADDR = 20, 26}; 27struct rtattr { 28 unsigned short rta_len; 29 unsigned short rta_type; 30}; 31struct ifaddrs { 32 struct ifaddrs *ifa_next; 33 unsigned short ifa_flags; 34}; 35typedef unsigned short int uint16_t; 36typedef unsigned int uint32_t; 37struct nlmsg_list { 38 struct nlmsg_list *nlm_next; 39 int size; 40}; 41struct rtmaddr_ifamap { 42 void *address; 43 void *local; 44 int address_len; 45 int local_len; 46}; 47int usagi_getifaddrs (struct ifaddrs **ifap) 48{ 49 struct nlmsg_list *nlmsg_list, *nlmsg_end, *nlm; 50 size_t dlen, xlen, nlen; 51 int build; 52 for (build = 0; build <= 1; build++) 53 { 54 struct ifaddrs *ifl = ((void *)0), *ifa = ((void *)0); 55 struct nlmsghdr *nlh, *nlh0; 56 uint16_t *ifflist = ((void *)0); 57 struct rtmaddr_ifamap ifamap; 58 for (nlm = nlmsg_list; nlm; nlm = nlm->nlm_next) 59 { 60 int nlmlen = nlm->size; 61 for (nlh = nlh0; 62 ((nlmlen) >= (int)sizeof(struct nlmsghdr) 63 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) 64 && (nlh)->nlmsg_len <= (nlmlen)); 65 nlh = ((nlmlen) -= ( (((nlh)->nlmsg_len)+4U -1) & ~(4U -1) ), 66 (struct nlmsghdr*)(((char*)(nlh)) 67 + ( (((nlh)->nlmsg_len)+4U -1) 68 & ~(4U -1) )))) 69 { 70 struct ifinfomsg *ifim = ((void *)0); 71 struct ifaddrmsg *ifam = ((void *)0); 72 struct rtattr *rta; 73 sa_family_t nlm_family = 0; 74 uint32_t nlm_scope = 0, nlm_index = 0; 75 memset (&ifamap, 0, sizeof (ifamap)); 76 switch (nlh->nlmsg_type) 77 { 78 case RTM_NEWLINK: 79 ifim = (struct ifinfomsg *) 80 ((void*)(((char*)nlh) 81 + ((0)+( ((((int) 82 ( ((sizeof(struct nlmsghdr))+4U -1) 83 & ~(4U -1) )))+4U -1) 84 & ~(4U -1) )))); 85 case RTM_NEWADDR: 86 ifam = (struct ifaddrmsg *) 87 ((void*)(((char*)nlh) 88 + ((0)+( ((((int) 89 ( ((sizeof(struct nlmsghdr))+4U -1) 90 & ~(4U -1) )))+4U -1) 91 & ~(4U -1) )))); 92 nlm_family = ifam->ifa_family; 93 if (build) 94 ifa->ifa_flags = ifflist[nlm_index]; 95 break; 96 default: 97 continue; 98 } 99 if (!build) 100 { 101 void *rtadata = ((void*)(((char*)(rta)) 102 + (( ((sizeof(struct rtattr))+4 -1) 103 & ~(4 -1) ) + (0)))); 104 size_t rtapayload = ((int)((rta)->rta_len) 105 - (( ((sizeof(struct rtattr))+4 -1) 106 & ~(4 -1) ) + (0))); 107 switch (nlh->nlmsg_type) 108 { 109 case RTM_NEWLINK: 110 break; 111 case RTM_NEWADDR: 112 if (nlm_family == 17) 113 break; 114 switch (rta->rta_type) 115 { 116 case IFA_ADDRESS: 117 ifamap.address = rtadata; 118 ifamap.address_len = rtapayload; 119 case IFA_LOCAL: 120 ifamap.local = rtadata; 121 } 122 } 123 } 124 if (nlh->nlmsg_type == RTM_NEWADDR && nlm_family != 17) 125 { 126 if (!ifamap.local) 127 { 128 ifamap.local = ifamap.address; 129 ifamap.local_len = ifamap.address_len; 130 } 131 if (!ifamap.address) 132 { 133 ifamap.address = ifamap.local; 134 } 135 if (ifamap.address_len != ifamap.local_len 136 || (ifamap.address != ((void *)0) 137 && memcmp (ifamap.address, ifamap.local, 138 ifamap.address_len))) 139 { 140 if (!build) 141 dlen += (((ifa_sa_len (nlm_family, 142 ifamap.address_len))+4U -1) 143 & ~(4U -1) ); 144 } 145 } 146 } 147 } 148 } 149} 150