https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129257
Bug ID: 129257
Summary: [s390] explicit -mhtm is accepted with -march=z10 and
emits tbegin
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: accepts-invalid
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: lzy20000419 at outlook dot com
Target Milestone: ---
Host: x86_64-pc-linux-gnu
Target: s390x-linux-gnu
Fails with an s390x-linux-gnu cross trunk (gcc 17.0.0 20261203, 799c1184b136)
and with 11.2.0, 12.5.0, 13.4.0, 14.4.0, 15.3.0 and 16.2.0. Target:
s390x-linux-gnu.
The transactional execution facility was introduced with zEC12. With
-march=z10, an explicit -mhtm is accepted without any diagnostic and the
compiler emits tbegin. The sibling options -mvx and -mhard-dfp are diagnosed
when the selected architecture lacks the facility.
int f(void *p) { return __builtin_tbegin(p); }
s390x-linux-gnu-gcc -O2 -march=z10 -mhtm -S t.c
This compiles without a diagnostic, and the assembly contains:
tbegin 0(%r2),65292
For comparison:
s390x-linux-gnu-gcc -O2 -march=z10 -mvx -S t.c
cc1: error: hardware vector support not available on z10
s390x-linux-gnu-gcc -O2 -march=z900 -mhard-dfp -S t.c
cc1: error: hardware decimal floating-point instructions not available on
z900
Without -mhtm, -march=z10 correctly rejects the builtin: error: builtin
'__builtin_tbegin' is not supported without '-mhtm' (default with
'-march=zEC12' and higher).
Expected: an error for -mhtm with an architecture that does not have the
facility, like the -mvx case.
In s390_option_override_internal, HTM is only enabled or disabled automatically
when -mhtm was not given explicitly (the !TARGET_OPT_HTM_P
(opts_set->x_target_flags) branch). The explicit case has no check against
TARGET_CPU_HTM_P, whereas the -mvx case just below it does. A check next to the
-mvx one might be the natural place for a fix, but I have not tried it.
This is not a regression: every version tested accepts it.
Godbolt (s390x gcc 16.2.0, with the -mvx error for comparison):
https://godbolt.org/z/jxqqqjr55
Disclaimer: This test case was found with LLM-assisted targeted testing, and
the report was written with LLM assistance.