1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2019, Joyent, Inc. 14 */ 15 16 /* 17 * Check qualifier encoding. Note that the needed_qualifier() workaround applies 18 * to most of these. 19 */ 20 21 #include "check-common.h" 22 23 static check_descent_t check_descent_const_union_array_gcc4[] = { 24 { "const union const_union [5]", CTF_K_CONST }, 25 { "union const_union [5]", CTF_K_ARRAY, "union const_union", 5 }, 26 { "union const_union", CTF_K_UNION }, 27 { NULL } 28 }; 29 30 static check_descent_t check_descent_const_union_array_gcc7[] = { 31 { "const union const_union [5]", CTF_K_ARRAY, 32 "const union const_union", 5 }, 33 { "const union const_union", CTF_K_CONST }, 34 { "union const_union", CTF_K_UNION }, 35 { NULL } 36 }; 37 38 static check_descent_test_t alt_descents_const_union_array[] = { 39 { "const_union_array", check_descent_const_union_array_gcc4 }, 40 { "const_union_array", check_descent_const_union_array_gcc7 }, 41 { NULL } 42 }; 43 44 static check_descent_t check_descent_const_struct_array_gcc4[] = { 45 { "const struct const_struct [7]", CTF_K_CONST }, 46 { "struct const_struct [7]", CTF_K_ARRAY, "struct const_struct", 7 }, 47 { "struct const_struct", CTF_K_STRUCT }, 48 { NULL } 49 }; 50 51 static check_descent_t check_descent_const_struct_array_gcc7[] = { 52 { "const struct const_struct [7]", CTF_K_ARRAY, 53 "const struct const_struct", 7 }, 54 { "const struct const_struct", CTF_K_CONST }, 55 { "struct const_struct", CTF_K_STRUCT }, 56 { NULL } 57 }; 58 59 static check_descent_test_t alt_descents_const_struct_array[] = { 60 { "const_struct_array", check_descent_const_struct_array_gcc4 }, 61 { "const_struct_array", check_descent_const_struct_array_gcc7 }, 62 { NULL } 63 }; 64 65 static check_descent_t check_descent_volatile_struct_array_gcc4[] = { 66 { "volatile struct volatile_struct [9]", CTF_K_VOLATILE }, 67 { "struct volatile_struct [9]", CTF_K_ARRAY, 68 "struct volatile_struct", 9 }, 69 { "struct volatile_struct", CTF_K_STRUCT }, 70 { NULL } 71 }; 72 73 static check_descent_t check_descent_volatile_struct_array_gcc7[] = { 74 { "volatile struct volatile_struct [9]", CTF_K_ARRAY, 75 "volatile struct volatile_struct", 9 }, 76 { "volatile struct volatile_struct", CTF_K_VOLATILE }, 77 { "struct volatile_struct", CTF_K_STRUCT }, 78 { NULL } 79 }; 80 81 static check_descent_test_t alt_descents_volatile_struct_array[] = { 82 { "volatile_struct_array", check_descent_volatile_struct_array_gcc4 }, 83 { "volatile_struct_array", check_descent_volatile_struct_array_gcc7 }, 84 { NULL } 85 }; 86 87 static check_descent_t check_descent_c_int_array_gcc4[] = { 88 { "const int [11]", CTF_K_CONST }, 89 { "int [11]", CTF_K_ARRAY, "int", 11 }, 90 { "int", CTF_K_INTEGER }, 91 { NULL } 92 }; 93 94 static check_descent_t check_descent_c_int_array_gcc7[] = { 95 { "const int [11]", CTF_K_ARRAY, "const int", 11 }, 96 { "const int", CTF_K_CONST }, 97 { "int", CTF_K_INTEGER }, 98 { NULL } 99 }; 100 101 static check_descent_test_t alt_descents_c_int_array[] = { 102 { "c_int_array", check_descent_c_int_array_gcc4 }, 103 { "c_int_array", check_descent_c_int_array_gcc7 }, 104 { NULL } 105 }; 106 107 static check_descent_t check_descent_cv_int_array_gcc4[] = { 108 { "const volatile int [13]", CTF_K_CONST }, 109 { "volatile int [13]", CTF_K_VOLATILE }, 110 { "int [13]", CTF_K_ARRAY, "int", 13 }, 111 { "int", CTF_K_INTEGER }, 112 { NULL } 113 }; 114 115 static check_descent_t check_descent_cv_int_array_gcc7[] = { 116 { "volatile const int [13]", CTF_K_ARRAY, "volatile const int", 13 }, 117 { "volatile const int", CTF_K_VOLATILE }, 118 { "const int", CTF_K_CONST }, 119 { "int", CTF_K_INTEGER }, 120 { NULL } 121 }; 122 123 static check_descent_t check_descent_cv_int_array_clang9[] = { 124 { "const volatile int [13]", CTF_K_ARRAY, "const volatile int", 13 }, 125 { "const volatile int", CTF_K_CONST }, 126 { "volatile int", CTF_K_VOLATILE }, 127 { "int", CTF_K_INTEGER }, 128 { NULL } 129 }; 130 131 static check_descent_test_t alt_descents_cv_int_array[] = { 132 { "cv_int_array", check_descent_cv_int_array_gcc4 }, 133 { "cv_int_array", check_descent_cv_int_array_gcc7 }, 134 { "cv_int_array", check_descent_cv_int_array_clang9 }, 135 { NULL } 136 }; 137 138 static check_descent_t check_descent_vc_int_array_gcc4[] = { 139 { "const volatile int [15]", CTF_K_CONST }, 140 { "volatile int [15]", CTF_K_VOLATILE }, 141 { "int [15]", CTF_K_ARRAY, "int", 15 }, 142 { "int", CTF_K_INTEGER }, 143 { NULL } 144 }; 145 146 static check_descent_t check_descent_vc_int_array_gcc7[] = { 147 { "volatile const int [15]", CTF_K_ARRAY, "volatile const int", 15 }, 148 { "volatile const int", CTF_K_VOLATILE }, 149 { "const int", CTF_K_CONST }, 150 { "int", CTF_K_INTEGER }, 151 { NULL } 152 }; 153 154 static check_descent_t check_descent_vc_int_array_clang9[] = { 155 { "const volatile int [15]", CTF_K_ARRAY, "const volatile int", 15 }, 156 { "const volatile int", CTF_K_CONST }, 157 { "volatile int", CTF_K_VOLATILE }, 158 { "int", CTF_K_INTEGER }, 159 { NULL } 160 }; 161 162 static check_descent_test_t alt_descents_vc_int_array[] = { 163 { "vc_int_array", check_descent_vc_int_array_gcc4 }, 164 { "vc_int_array", check_descent_vc_int_array_gcc7 }, 165 { "vc_int_array", check_descent_vc_int_array_clang9 }, 166 { NULL } 167 }; 168 169 static check_descent_t check_descent_vc_int_array2_gcc4[] = { 170 { "const volatile int [17]", CTF_K_CONST }, 171 { "volatile int [17]", CTF_K_VOLATILE }, 172 { "int [17]", CTF_K_ARRAY, "int", 17 }, 173 { "int", CTF_K_INTEGER }, 174 { NULL } 175 }; 176 177 static check_descent_t check_descent_vc_int_array2_gcc7[] = { 178 { "volatile const int [17]", CTF_K_ARRAY, "volatile const int", 17 }, 179 { "volatile const int", CTF_K_VOLATILE }, 180 { "const int", CTF_K_CONST }, 181 { "int", CTF_K_INTEGER }, 182 { NULL } 183 }; 184 185 static check_descent_t check_descent_vc_int_array2_clang9[] = { 186 { "const volatile int [17]", CTF_K_ARRAY, "const volatile int", 17 }, 187 { "const volatile int", CTF_K_CONST }, 188 { "volatile int", CTF_K_VOLATILE }, 189 { "int", CTF_K_INTEGER }, 190 { NULL } 191 }; 192 193 194 static check_descent_test_t alt_descents_vc_int_array2[] = { 195 { "vc_int_array2", check_descent_vc_int_array2_gcc4 }, 196 { "vc_int_array2", check_descent_vc_int_array2_gcc7 }, 197 { "vc_int_array2", check_descent_vc_int_array2_clang9 }, 198 { NULL } 199 }; 200 201 static check_descent_t check_descent_c_2d_array_gcc4[] = { 202 { "const int [4][2]", CTF_K_CONST }, 203 { "int [4][2]", CTF_K_ARRAY, "int [2]", 4 }, 204 { "int [2]", CTF_K_ARRAY, "int", 2 }, 205 { "int", CTF_K_INTEGER }, 206 { NULL } 207 }; 208 209 static check_descent_t check_descent_c_2d_array_gcc7[] = { 210 { "const int [4][2]", CTF_K_ARRAY, "const int [2]", 4 }, 211 { "const int [2]", CTF_K_ARRAY, "const int", 2 }, 212 { "const int", CTF_K_CONST }, 213 { "int", CTF_K_INTEGER }, 214 { NULL } 215 }; 216 217 static check_descent_test_t alt_descents_c_2d_array[] = { 218 { "c_2d_array", check_descent_c_2d_array_gcc4 }, 219 { "c_2d_array", check_descent_c_2d_array_gcc7 }, 220 { NULL } 221 }; 222 223 static check_descent_t check_descent_cv_3d_array_gcc4[] = { 224 { "const volatile int [3][2][1]", CTF_K_CONST }, 225 { "volatile int [3][2][1]", CTF_K_VOLATILE }, 226 { "int [3][2][1]", CTF_K_ARRAY, "int [2][1]", 3 }, 227 { "int [2][1]", CTF_K_ARRAY, "int [1]", 2 }, 228 { "int [1]", CTF_K_ARRAY, "int", 1 }, 229 { "int", CTF_K_INTEGER }, 230 { NULL } 231 }; 232 233 static check_descent_t check_descent_cv_3d_array_gcc7[] = { 234 { "volatile const int [3][2][1]", CTF_K_ARRAY, 235 "volatile const int [2][1]", 3 }, 236 { "volatile const int [2][1]", CTF_K_ARRAY, 237 "volatile const int [1]", 2 }, 238 { "volatile const int [1]", CTF_K_ARRAY, "volatile const int", 1 }, 239 { "volatile const int", CTF_K_VOLATILE }, 240 { "const int", CTF_K_CONST }, 241 { "int", CTF_K_INTEGER }, 242 { NULL } 243 }; 244 245 static check_descent_t check_descent_cv_3d_array_clang9[] = { 246 { "const volatile int [3][2][1]", CTF_K_ARRAY, 247 "const volatile int [2][1]", 3 }, 248 { "const volatile int [2][1]", CTF_K_ARRAY, 249 "const volatile int [1]", 2 }, 250 { "const volatile int [1]", CTF_K_ARRAY, 251 "const volatile int", 1 }, 252 { "const volatile int", CTF_K_CONST }, 253 { "volatile int", CTF_K_VOLATILE }, 254 { "int", CTF_K_INTEGER }, 255 { NULL } 256 }; 257 258 259 static check_descent_test_t alt_descents_cv_3d_array[] = { 260 { "cv_3d_array", check_descent_cv_3d_array_gcc4 }, 261 { "cv_3d_array", check_descent_cv_3d_array_gcc7 }, 262 { "cv_3d_array", check_descent_cv_3d_array_clang9 }, 263 { NULL } 264 }; 265 266 static check_descent_t check_descent_ptr_to_const_int[] = { 267 { "const int *", CTF_K_POINTER }, 268 { "const int", CTF_K_CONST }, 269 { "int", CTF_K_INTEGER }, 270 { NULL } 271 }; 272 273 static check_descent_test_t alt_descents_ptr_to_const_int[] = { 274 { "ptr_to_const_int", check_descent_ptr_to_const_int }, 275 { NULL } 276 }; 277 278 static check_descent_t check_descent_const_ptr_to_int[] = { 279 { "int *const", CTF_K_CONST }, 280 { "int *", CTF_K_POINTER }, 281 { "int", CTF_K_INTEGER }, 282 { NULL } 283 }; 284 285 static check_descent_test_t alt_descents_const_ptr_to_int[] = { 286 { "const_ptr_to_int", check_descent_const_ptr_to_int }, 287 { NULL } 288 }; 289 290 static check_descent_t check_descent_const_ptr_to_const_int[] = { 291 { "const int *const", CTF_K_CONST }, 292 { "const int *", CTF_K_POINTER }, 293 { "const int", CTF_K_CONST }, 294 { "int", CTF_K_INTEGER }, 295 { NULL } 296 }; 297 298 static check_descent_test_t alt_descents_const_ptr_to_const_int[] = { 299 { "const_ptr_to_const_int", check_descent_const_ptr_to_const_int }, 300 { NULL } 301 }; 302 303 static check_descent_test_t *alt_descents[] = { 304 alt_descents_const_union_array, 305 alt_descents_const_struct_array, 306 alt_descents_volatile_struct_array, 307 alt_descents_c_int_array, 308 alt_descents_cv_int_array, 309 alt_descents_vc_int_array, 310 alt_descents_vc_int_array2, 311 alt_descents_c_2d_array, 312 alt_descents_cv_3d_array, 313 alt_descents_ptr_to_const_int, 314 alt_descents_const_ptr_to_int, 315 alt_descents_const_ptr_to_const_int, 316 NULL 317 }; 318 319 int 320 main(int argc, char *argv[]) 321 { 322 int i, ret = 0; 323 324 if (argc < 2) { 325 errx(EXIT_FAILURE, "missing test files"); 326 } 327 328 for (i = 1; i < argc; i++) { 329 ctf_file_t *fp; 330 331 if ((fp = ctf_open(argv[i], &ret)) == NULL) { 332 warnx("failed to open %s: %s", argv[i], 333 ctf_errmsg(ret)); 334 ret = EXIT_FAILURE; 335 continue; 336 } 337 338 for (uint_t j = 0; alt_descents[j] != NULL; j++) { 339 check_descent_test_t *descents = alt_descents[j]; 340 int alt_ok = 0; 341 342 for (uint_t k = 0; descents[k].cdt_sym != NULL; k++) { 343 if (ctftest_check_descent(descents[k].cdt_sym, 344 fp, descents[k].cdt_tests, B_TRUE)) { 345 alt_ok = 1; 346 break; 347 } 348 } 349 350 if (!alt_ok) { 351 warnx("all descents failed for %s", 352 descents[0].cdt_sym); 353 ret = EXIT_FAILURE; 354 } 355 } 356 357 ctf_close(fp); 358 } 359 360 return (ret); 361 } 362