Skip to content

Commit 741d7fa

Browse files
authored
[Clang][Sema] Add special handling of mfloat8 in initializer lists (#125097)
This patch fixes assertion failures in clang, caused by unique properties of _mfp8 type, namely it not being either scalar or vector type and it not being either integer or float type.
1 parent f6262fa commit 741d7fa

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11172,6 +11172,11 @@ VectorExprEvaluator::VisitInitListExpr(const InitListExpr *E) {
1117211172
QualType EltTy = VT->getElementType();
1117311173
SmallVector<APValue, 4> Elements;
1117411174

11175+
// MFloat8 type doesn't have constants and thus constant folding
11176+
// is impossible.
11177+
if (EltTy->isMFloat8Type())
11178+
return false;
11179+
1117511180
// The number of initializers can be less than the number of
1117611181
// vector elements. For OpenCL, this can be due to nested vector
1117711182
// initialization. For GCC compatibility, missing trailing elements

clang/lib/Sema/SemaInit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,8 @@ void InitListChecker::CheckSubElementType(const InitializedEntity &Entity,
15901590

15911591
} else {
15921592
assert((ElemType->isRecordType() || ElemType->isVectorType() ||
1593-
ElemType->isOpenCLSpecificType()) && "Unexpected type");
1593+
ElemType->isOpenCLSpecificType() || ElemType->isMFloat8Type()) &&
1594+
"Unexpected type");
15941595

15951596
// C99 6.7.8p13:
15961597
//
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
2+
3+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s
4+
// RUN: %clang_cc1 -x c++ -triple aarch64-none-linux-gnu -target-feature +neon -O2 -Werror -Wall -emit-llvm -o - %s | FileCheck %s -check-prefix CHECK-CXX
5+
6+
// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +neon -O2 -Werror -Wall -S -o /dev/null %s
7+
8+
// REQUIRES: aarch64-registered-target
9+
10+
#include <arm_neon.h>
11+
12+
// CHECK-LABEL: define dso_local <8 x i8> @vector_init_test(
13+
// CHECK-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
14+
// CHECK-NEXT: [[ENTRY:.*:]]
15+
// CHECK-NEXT: [[VECINIT14:%.*]] = shufflevector <1 x i8> [[X]], <1 x i8> poison, <8 x i32> zeroinitializer
16+
// CHECK-NEXT: ret <8 x i8> [[VECINIT14]]
17+
//
18+
// CHECK-CXX-LABEL: define dso_local <8 x i8> @_Z16vector_init_testu6__mfp8(
19+
// CHECK-CXX-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
20+
// CHECK-CXX-NEXT: [[ENTRY:.*:]]
21+
// CHECK-CXX-NEXT: [[VECINIT14:%.*]] = shufflevector <1 x i8> [[X]], <1 x i8> poison, <8 x i32> zeroinitializer
22+
// CHECK-CXX-NEXT: ret <8 x i8> [[VECINIT14]]
23+
//
24+
mfloat8x8_t vector_init_test(__mfp8 x) {
25+
return (mfloat8x8_t) {x, x, x, x, x, x, x, x};
26+
}
27+
28+
struct S {
29+
__mfp8 x;
30+
};
31+
32+
struct S s;
33+
34+
// CHECK-LABEL: define dso_local void @f(
35+
// CHECK-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
36+
// CHECK-NEXT: [[ENTRY:.*:]]
37+
// CHECK-NEXT: store <1 x i8> [[X]], ptr @s, align 1, !tbaa [[TBAA2:![0-9]+]]
38+
// CHECK-NEXT: ret void
39+
//
40+
// CHECK-CXX-LABEL: define dso_local void @_Z1fu6__mfp8(
41+
// CHECK-CXX-SAME: <1 x i8> [[X:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
42+
// CHECK-CXX-NEXT: [[ENTRY:.*:]]
43+
// CHECK-CXX-NEXT: store <1 x i8> [[X]], ptr @s, align 1, !tbaa [[TBAA2:![0-9]+]]
44+
// CHECK-CXX-NEXT: ret void
45+
//
46+
void f(__mfp8 x) {
47+
s = (struct S){x};
48+
}
49+
//.
50+
// CHECK: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0}
51+
// CHECK: [[META3]] = !{!"__mfp8", [[META4:![0-9]+]], i64 0}
52+
// CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
53+
// CHECK: [[META5]] = !{!"Simple C/C++ TBAA"}
54+
//.
55+
// CHECK-CXX: [[TBAA2]] = !{[[META3:![0-9]+]], [[META3]], i64 0}
56+
// CHECK-CXX: [[META3]] = !{!"__mfp8", [[META4:![0-9]+]], i64 0}
57+
// CHECK-CXX: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
58+
// CHECK-CXX: [[META5]] = !{!"Simple C++ TBAA"}
59+
//.

0 commit comments

Comments
 (0)