Skip to content

Commit 04e97b1

Browse files
committed
[Clang][CodeGen] Fix crash when using bool vector in compound assignment
1 parent 4f1ddf7 commit 04e97b1

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,10 +2085,15 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, SourceLocation Loc) {
20852085
}
20862086

20872087
if (LV.isVectorElt()) {
2088-
llvm::LoadInst *Load = Builder.CreateLoad(LV.getVectorAddress(),
2089-
LV.isVolatileQualified());
2090-
return RValue::get(Builder.CreateExtractElement(Load, LV.getVectorIdx(),
2091-
"vecext"));
2088+
llvm::Value *Load = nullptr;
2089+
if (LV.getType()->isExtVectorBoolType())
2090+
Load = EmitLoadOfScalar(LV.getVectorAddress(), LV.isVolatileQualified(),
2091+
LV.getType(), Loc);
2092+
else
2093+
Load =
2094+
Builder.CreateLoad(LV.getVectorAddress(), LV.isVolatileQualified());
2095+
return RValue::get(
2096+
Builder.CreateExtractElement(Load, LV.getVectorIdx(), "vecext"));
20922097
}
20932098

20942099
// If this is a reference to a subset of the elements of a vector, either

clang/test/CodeGen/gh72468.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -S -emit-llvm -o - %s
2+
3+
typedef __attribute__((__ext_vector_type__(4))) _Bool BoolVector;
4+
5+
BoolVector vec;
6+
7+
void f(int i, int j) {
8+
vec[i] |= vec[j];
9+
}

clang/test/SemaCXX/vector-bool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ void Operations() {
3838
// (void)(eight_bools > other_eight_bools);
3939
// (void)(eight_bools >= other_eight_bools);
4040

41-
// // Legal assignments
42-
// (void)(eight_bools |= other_eight_bools);
43-
// (void)(eight_bools &= other_eight_bools);
44-
// (void)(eight_bools ^= other_eight_bools);
41+
// Legal assignments
42+
(void)(eight_bools |= other_eight_bools);
43+
(void)(eight_bools &= other_eight_bools);
44+
(void)(eight_bools ^= other_eight_bools);
4545

4646
// Illegal operators
4747
(void)(eight_bools || other_eight_bools); // expected-error@47 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}

0 commit comments

Comments
 (0)