Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb18fe7

Browse files
authored
[AArch64] Guard against vector invalidation in EmitAArch64CpuSupports. (#196909)
This prevents the Vector from being invalidated whilst iterator over it. As far as I can tell we were adding elements twice. Fixes #196789
1 parent 9f3d304 commit fb18fe7

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

clang/lib/CodeGen/TargetBuiltins/ARM.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7306,9 +7306,10 @@ Value *CodeGenFunction::EmitAArch64CpuInit() {
73067306
Value *CodeGenFunction::EmitAArch64CpuSupports(const CallExpr *E) {
73077307
const Expr *ArgExpr = E->getArg(0)->IgnoreParenCasts();
73087308
StringRef ArgStr = cast<StringLiteral>(ArgExpr)->getString();
7309+
llvm::SmallVector<StringRef, 8> OrigFeatures;
7310+
ArgStr.split(OrigFeatures, "+");
73097311
llvm::SmallVector<StringRef, 8> Features;
7310-
ArgStr.split(Features, "+");
7311-
for (auto &Feature : Features) {
7312+
for (StringRef Feature : OrigFeatures) {
73127313
Feature = Feature.trim();
73137314
if (!llvm::AArch64::parseFMVExtension(Feature))
73147315
return Builder.getFalse();

clang/test/CodeGen/AArch64/cpu-supports-target.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@ int test_versions() {
217217
return code();
218218
}
219219

220+
// CHECK: Function Attrs: noinline nounwind optnone
221+
// CHECK-LABEL: define dso_local i32 @test_long(
222+
// CHECK-SAME: ) #[[ATTR0]] {
223+
// CHECK-NEXT: [[ENTRY:.*:]]
224+
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
225+
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 577586773744664575
226+
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 577586773744664575
227+
// CHECK-NEXT: [[TMP3:%.*]] = and i1 true, [[TMP2]]
228+
// CHECK-NEXT: [[CONV:%.*]] = zext i1 [[TMP3]] to i32
229+
// CHECK-NEXT: ret i32 [[CONV]]
230+
//
231+
int test_long(void) {
232+
return __builtin_cpu_supports("rng+flagm+flagm2+fp16fml+dotprod+sm4+rdm+lse+fp+simd+aes+bf16+bti+crc+cssc+dit+dotprod+f32mm+f64mm+flagm+fp16fml+fp16+i8mm+mops+sha2+sha3+sm4+sve2");
233+
}
234+
220235
//.
221236
// CHECK: attributes #[[ATTR0]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
222237
// CHECK: attributes #[[ATTR1]] = { noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+neon" }

0 commit comments

Comments
 (0)