GOLD: RFA: Fixing a coverty error for aarch64.cc
Pedro Alves
palves@redhat.com
Fri Jan 20 11:50:00 GMT 2017
I would suggest letting the compiler handle computing
array sizes. Something like the below. (Build tested
only, feel free to run with it). If you restore the
pointer with something like:
+ const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
+
[...]
- // ST_E_835769 has the same stub template as ST_E_843419.
- install_insn_template_insns(ST_E_835769, ST_E_843419);
+ install_insn_template(ST_E_835769);
Then the compiler catches the problem:
src/gold/aarch64.cc:798:65: error: no matching function for call to â{anonymous}::Stub_template<false>::Stub_template(const Insntype*&)â
const static Stub_template<big_endian> template_##T (I##_INSNS); \
^
src/gold/aarch64.cc:802:3: note: in expansion of macro âinstall_insn_template_insnsâ
install_insn_template_insns(T, T)
^
src/gold/aarch64.cc:808:3: note: in expansion of macro âinstall_insn_templateâ
install_insn_template(ST_E_835769);
^
src/gold/aarch64.cc:711:3: note: candidate: template<long unsigned int insn_num_>{anonymous}::Stub_template<big_endian>::Stub_template(const typename {anonymous}::AArch64_insn_utilities<big_endian>::Insntype(&)[insn_num_])
Stub_template
^
src/gold/aarch64.cc:711:3: note: template argument deduction/substitution failed:
src/gold/aarch64.cc:798:65: note: mismatched types âconst Insntype [insn_num_]â and âconst Insntype* {aka const unsigned int*}â
const static Stub_template<big_endian> template_##T (I##_INSNS); \
(ST_NONE_INSNS is removed because (const-expression) arrays of 0
length are not valid C++, and compilers reject them / SFINAE them
out when deciding which constructor to call.)
>From c7cd91832535b3989ec8f41a3d1eb51c7acc0ee4 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Fri, 20 Jan 2017 10:52:05 +0000
Subject: [PATCH]
---
gold/aarch64.cc | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/gold/aarch64.cc b/gold/aarch64.cc
index facbbd8..ab80472 100644
--- a/gold/aarch64.cc
+++ b/gold/aarch64.cc
@@ -703,6 +703,16 @@ enum
template<bool big_endian>
struct Stub_template
{
+ Stub_template ()
+ : insns(NULL), insn_num(0)
+ { }
+
+ template<size_t insn_num_>
+ Stub_template
+ (const typename AArch64_insn_utilities<big_endian>::Insntype (&insns_)[insn_num_])
+ : insns(insns_), insn_num(insn_num_)
+ { }
+
const typename AArch64_insn_utilities<big_endian>::Insntype* insns;
const int insn_num;
};
@@ -746,8 +756,6 @@ template<bool big_endian>
Stub_template_repertoire<big_endian>::Stub_template_repertoire()
{
// Insn array definitions.
- const static Insntype ST_NONE_INSNS[] = {};
-
const static Insntype ST_ADRP_BRANCH_INSNS[] =
{
0x90000010, /* adrp ip0, X */
@@ -784,20 +792,19 @@ Stub_template_repertoire<big_endian>::Stub_template_repertoire()
0x14000000, /* b <label> */
};
- // ST_E_835769 has the same stub template as ST_E_843419.
- const static Insntype* ST_E_835769_INSNS = ST_E_843419_INSNS;
-
-#define install_insn_template(T) \
- const static Stub_template<big_endian> template_##T = { \
- T##_INSNS, sizeof(T##_INSNS) / sizeof(T##_INSNS[0]) }; \
+#define install_insn_template_insns(T, I) \
+ const static Stub_template<big_endian> template_##T (I##_INSNS); \
this->stub_templates_[T] = &template_##T
- install_insn_template(ST_NONE);
+#define install_insn_template(T) \
+ install_insn_template_insns(T, T)
+
install_insn_template(ST_ADRP_BRANCH);
install_insn_template(ST_LONG_BRANCH_ABS);
install_insn_template(ST_LONG_BRANCH_PCREL);
install_insn_template(ST_E_843419);
- install_insn_template(ST_E_835769);
+ // ST_E_835769 has the same stub template as ST_E_843419.
+ install_insn_template_insns(ST_E_835769, ST_E_843419);
#undef install_insn_template
}
--
2.5.5
More information about the Binutils
mailing list