Builtin `bswap` and `bitreverse` functions improve error recovery.
GCC now includes better error recovery for `__builtin_bswapg` and `__builtin_bitreverseg` when passed invalid arguments, preventing internal compiler errors.
GCC has improved its error handling for the __builtin_bswapg and __builtin_bitreverseg functions by preventing an Internal Compiler Error (ICE) when these builtins are invoked with error_mark_node as an argument. The fix ensures that the compiler now explicitly checks for error_operand_p before attempting to access the argument’s type, providing more robust error recovery in C and C++ front ends and making the compiler more stable when dealing with malformed input.
In Details
This commit refines error recovery within the C and C++ front ends for the __builtin_bswapg and __builtin_bitreverseg builtins. Previously, passing an error_mark_node to these builtins would result in an Internal Compiler Error (ICE) due to an invalid access to TYPE_MAIN_VARIANT after TREE_TYPE on error_mark_node. The patch introduces an explicit check for error_operand_p in c_parser.cc (for parsing) and typeck.cc (for type checking) before attempting to operate on the argument's type. This ensures that the front end correctly propagates errors instead of crashing, improving…
For Context
When you write C or C++ code, you might sometimes use special functions built directly into the compiler, called 'builtins,' which allow for highly optimized operations that are often faster than what you could write yourself. Two such builtins are __builtin_bswapg and __builtin_bitreverseg, which are used to reverse the byte order or bit order of a number, respectively. If you accidentally pass an invalid or malformed input to these builtins, the compiler should ideally report an error to you. However, a bug in GCC could cause the compiler itself to crash (an 'Internal Compiler Error' or ICE) when it encountered these specific invalid inputs. This update addresses that issue: the compiler now correctly identifies the bad input to these builtins and reports a proper error message, instead of crashing, making GCC more stable and user-friendly when dealing with certain types of programming mistakes.