(this patch is already uploaded to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86690 ) If a struct contains an anonymous union and both have a field with the same name, detect_field_duplicates_hash() will replace one of them with NULL. If compilation doesn't stop immediately, it may later call lookup_field() on the union, which falsely assumes the union's LANG_SPECIFIC array is sorted, and may loop indefinitely because of this. Reproduced on amd64 since gcc-5, on ubuntu-18.04 and gentoo. The patch falls back to iterating via DECL_CHAIN if there was an error earlier during compilation. I ran the gcc testsuite with the result (the FAIL seems unrelated to the patch): FAIL: gcc.dg/cpp/_Pragma3.c (test for excess errors) === gcc Summary === # of expected passes 135094 # of unexpected failures 1 # of expected failures 398 # of unsupported tests 2140 gcc-build/gcc/xgcc version 8.0.1 20180424 (experimental) (GCC)