[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] RISC-V: Fix the warning of temporary object dangling references.
Jeff Law
law@gcc.gnu.org
Sat Sep 6 14:38:08 GMT 2025
https://gcc.gnu.org/g:540a1db4f44f18f867163b557dcd685957b35cd3
commit 540a1db4f44f18f867163b557dcd685957b35cd3
Author: Dongyan Chen <chendongyan@isrc.iscas.ac.cn>
Date: Mon May 19 15:17:12 2025 +0800
RISC-V: Fix the warning of temporary object dangling references.
During the GCC compilation, some warnings about temporary object dangling
references emerged. They appeared in these code lines in riscv-common.cc:
const riscv_ext_info_t &implied_ext_info, const riscv_ext_info_t &ext_info = get_riscv_ext_info (ext) and auto &ext_info = get_riscv_ext_info (search_ext).
The issue arose because the local variable types were not used in a standardized
way, causing their references to dangle once the function ended.
To fix this, the patch changes the argument type of get_riscv_ext_info to
`const char *`, thereby eliminating the warnings.
Changes for v2:
- Change the argument type of get_riscv_ext_info to `const char *` to eliminate the warnings.
gcc/ChangeLog:
* common/config/riscv/riscv-common.cc (get_riscv_ext_info): Fix argument type.
(riscv_subset_list::check_implied_ext): Type conversion.
(cherry picked from commit 7fabbf3562812f648bb49d0a7ea6b74e88defd4b)
Diff:
---
gcc/common/config/riscv/riscv-common.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 53ca03910b38..c843393998cb 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -215,7 +215,7 @@ static const std::unordered_map<std::string, riscv_ext_info_t> riscv_ext_infos
};
static const riscv_ext_info_t &
-get_riscv_ext_info (const std::string &ext)
+get_riscv_ext_info (const char * ext)
{
auto itr = riscv_ext_infos.find (ext);
if (itr == riscv_ext_infos.end ())
@@ -1112,7 +1112,7 @@ riscv_subset_list::check_implied_ext ()
for (itr = m_head; itr != NULL; itr = itr->next)
{
auto &ext = *itr;
- auto &ext_info = get_riscv_ext_info (ext.name);
+ auto &ext_info = get_riscv_ext_info (ext.name.c_str ());
for (auto &implied_ext : ext_info.implied_exts ())
{
if (!implied_ext.match (this))
More information about the Gcc-cvs
mailing list