The 02/09/2026 20:02, Yangyu Chen wrote:
> Implement TARGET_CHECK_TARGET_CLONE_VERSION for x86 by reusing target
> attribute parsing with optional diagnostics and location overrides.
>
> This allows us to check the validity of target_clones versions and emit
> warnings for invalid or empty versions instead of errors, which is
> especially useful for next-generation targets like x86-64-v5 that may be
> annotated in software but current compilers do not support them yet,
> allowing for smoother transitions and better user experience.
>
> Add an i386 warning test for invalid target_clones versions and update
> existing i386 tests to expect warnings for invalid/empty versions.
>
> Signed-off-by: Yangyu Chen <[email protected]>
>
> gcc/ChangeLog:
>
>       * config/i386/i386-builtins.cc (get_builtin_code_for_version):
>       Update ix86_valid_target_attribute_tree call signature.
>       * config/i386/i386-c.cc (ix86_pragma_target_parse):
>       Ditto.
>       * config/i386/i386-options.cc (ix86_valid_target_attribute_inner_p):
>       Accept location and reporting control, and gate diagnostics.
>       (ix86_valid_target_attribute_tree):
>       Thread location into target attribute validation.
>       (ix86_valid_target_attribute_p):
>       Adjust for updated helper signature.
>       (ix86_check_target_clone_version):
>       New target_clones validation with warning-based diagnostics.
>       * config/i386/i386-protos.h (ix86_check_target_clone_version):
>       Declare new hook and update helper signature.
>       * config/i386/i386.cc (TARGET_CHECK_TARGET_CLONE_VERSION):
>       Wire x86 hook implementation.
>
> gcc/testsuite/ChangeLog:
>
>       * gcc.target/i386/mvc12.c:
>       Adjust target_clones empty-string diagnostic to a warning.
>       * gcc.target/i386/pr78419.c:
>       Expect warning for invalid target_clones version.
>       * gcc.target/i386/mvc-warning1.c: New test.
>       Add warning coverage for invalid target_clones version.
> ---
> Note: I think this patch would make our software system make use of new
> extensions like x86-APX by annotating with target_clones. But when such code
> was added to the codebase, it would be compiled by older compilers that do not
> understand the new target_clones versions, and without this patch, that would
> cause hard errors and break the build. With this patch, we can instead emit
> warnings for unrecognized versions, allowing the code to compile successfully
> while still alerting developers to the fact that their target_clones version 
> is
> not recognized by the current compiler, which is a much smoother experience
> during transitions to new architectures.

FWIW this looks good to me, and I agree it could make sense to commit for
GCC 16 as the sooner the better for backwards compatibility.

Obviously thats up to the x86 maintainers though.

(resending this as something went wrong with my email client)

KR,
Alfie

Reply via email to