On 2/3/2026 11:42 PM, Yangyu Chen wrote:
When parsing target attributes, if an invalid architecture string is
provided, the function parse_single_ext may return nullptr. The existing
code does not check for this case, leading to a nullptr dereference when
attempting to access the returned pointer. This patch adds a check to
ensure that the returned pointer is not nullptr before dereferencing it.
If it is nullptr, an appropriate error message is generated.

Fixes: aa8e2de78cae ("RISC-V: Rewrite target attribute handling")
Signed-off-by: Yangyu Chen <[email protected]>

gcc/ChangeLog:

        * 
config/riscv/riscv-target-attr.cc(riscv_target_attr_parser::parse_arch): Fix 
nullptr dereference when parsing invalid arch string.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/target-attr-bad-11.c: New test.
---
Note: This patch need to be backported to GCC 14 and 15 branches as well.
I've pushed this to the trunk.  We're not generally backporting risc-v bits to gcc-14.  But I'd support a backport to gcc-15 once it's been on the trunk for a few days to ensure no unexpected fallout.
Jeff

Reply via email to