Skip to content

Commit 3ef14f5

Browse files
aarch64: Fix FMV array iteration bounds
There was an assumption in some places that the aarch64_fmv_feature_data array contained FEAT_MAX elements. While this assumption held up till now, it is safer and more flexible to use the array size directly. Also fix the lower bound in compare_feature_masks to use ">=0" instead of ">0", and add a test using the features at index 0 and 1. However, the test already passed, because the earlier popcount check makes it impossible to reach the loop if the masks differ in exactly one location. gcc/ChangeLog: * config/aarch64/aarch64.cc (compare_feature_masks): Use ARRAY_SIZE and >=0 for iteration bounds. (aarch64_mangle_decl_assembler_name): Use ARRAY_SIZE. gcc/testsuite/ChangeLog: * g++.target/aarch64/mv-1.C: New test.
1 parent e33fc84 commit 3ef14f5

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

gcc/config/aarch64/aarch64.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19738,7 +19738,7 @@ aarch64_parse_fmv_features (const char *str, aarch64_feature_flags *isa_flags,
1973819738
if (len == 0)
1973919739
return AARCH_PARSE_MISSING_ARG;
1974019740

19741-
static const int num_features = ARRAY_SIZE (aarch64_fmv_feature_data);
19741+
int num_features = ARRAY_SIZE (aarch64_fmv_feature_data);
1974219742
int i;
1974319743
for (i = 0; i < num_features; i++)
1974419744
{
@@ -19937,7 +19937,8 @@ compare_feature_masks (aarch64_fmv_feature_mask mask1,
1993719937
auto diff_mask = mask1 ^ mask2;
1993819938
if (diff_mask == 0ULL)
1993919939
return 0;
19940-
for (int i = FEAT_MAX - 1; i > 0; i--)
19940+
int num_features = ARRAY_SIZE (aarch64_fmv_feature_data);
19941+
for (int i = num_features - 1; i >= 0; i--)
1994119942
{
1994219943
auto bit_mask = aarch64_fmv_feature_data[i].feature_mask;
1994319944
if (diff_mask & bit_mask)
@@ -20020,7 +20021,8 @@ aarch64_mangle_decl_assembler_name (tree decl, tree id)
2002020021

2002120022
name += "._";
2002220023

20023-
for (int i = 0; i < FEAT_MAX; i++)
20024+
int num_features = ARRAY_SIZE (aarch64_fmv_feature_data);
20025+
for (int i = 0; i < num_features; i++)
2002420026
{
2002520027
if (feature_mask & aarch64_fmv_feature_data[i].feature_mask)
2002620028
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* { dg-do compile } */
2+
/* { dg-require-ifunc "" } */
3+
/* { dg-options "-O0" } */
4+
5+
__attribute__((target_version("default")))
6+
int foo ()
7+
{
8+
return 1;
9+
}
10+
11+
__attribute__((target_version("rng")))
12+
int foo ()
13+
{
14+
return 1;
15+
}
16+
17+
__attribute__((target_version("flagm")))
18+
int foo ()
19+
{
20+
return 1;
21+
}
22+
23+
__attribute__((target_version("rng+flagm")))
24+
int foo ()
25+
{
26+
return 1;
27+
}
28+
29+
int bar()
30+
{
31+
return foo ();
32+
}
33+
34+
/* Check usage of the first two FMV features, in case of off-by-one errors. */
35+
/* { dg-final { scan-assembler-times "\n_Z3foov\.default:\n" 1 } } */
36+
/* { dg-final { scan-assembler-times "\n_Z3foov\._Mrng:\n" 1 } } */
37+
/* { dg-final { scan-assembler-times "\n_Z3foov\._MrngMflagm:\n" 1 } } */
38+
/* { dg-final { scan-assembler-times "\n_Z3foov\._Mflagm:\n" 1 } } */

0 commit comments

Comments
 (0)