On 11/26/20 10:09 AM, Jakub Jelinek wrote: Sorry, thought I had replied to this before.
The following patch removes the mask from the new native_interpret_aggregate moved to fold-const.c altogether. Instead, the code uses the __builtin_clear_padding infrastructure (new entrypoint in there). If native_interpret_aggregate succeeds (returns non-NULL), then what we have in mask from the earlier native_encode_initializer call is 0 bits if they are well defined in argument and 1 bits for indeterminate bits. The new clear_type_padding_in_mask function then clears all bits which are padding in the given type (the destination type), so if any bits remain in the mask, it means we are using indeterminate bits and C++ FE can diagnose it. The bit-cast* tests didn't change at all.
Great, thanks.
+ if (can_native_interpret_type_p (TREE_TYPE (t))) + if (tree r = native_interpret_expr (TREE_TYPE (t), ptr, len)) + { + for (int i = 0; i < len; i++) + if (mask[i]) + { + if (!ctx->quiet) + error_at (loc, "%qs accessing uninitialized byte at offset %d", + "__builtin_bit_cast", i); + *non_constant_p = true; + r = t; + break; + } + if (ptr != buf) + XDELETE (ptr); + return r; + } + + if (TREE_CODE (TREE_TYPE (t)) == RECORD_TYPE) + { + tree r = native_interpret_aggregate (TREE_TYPE (t), ptr, 0, len); + if (r != NULL_TREE) + { + clear_type_padding_in_mask (TREE_TYPE (t), mask); + for (int i = 0; i < len; i++) + if (mask[i]) + { + if (!ctx->quiet) + error_at (loc, "%qs accessing uninitialized byte at offset " + "%d", "__builtin_bit_cast", i); + *non_constant_p = true; + r = t; + break; + } + if (ptr != buf) + XDELETE (ptr); + return r; + } + }
There's a lot of code that can be shared between these two cases now. The C++ bits are OK with that change.
Jason