[clang] [Clang][CodeGen] Fix crash when using bool vector in compound assignment (PR #75435)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 13 23:23:34 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-codegen
Author: Chenyang Gao (cygao90)
<details>
<summary>Changes</summary>
Fixes: #<!-- -->72468.
The left side bool vector did not perform a specific conversion(`CodeGenFunction::emitBoolVecConversion`) in compound assignment
---
Full diff: https://github.com/llvm/llvm-project/pull/75435.diff
3 Files Affected:
- (modified) clang/lib/CodeGen/CGExpr.cpp (+9-4)
- (added) clang/test/CodeGen/gh72468.c (+9)
- (modified) clang/test/SemaCXX/vector-bool.cpp (+4-4)
``````````diff
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index ed9aaa28c25733..5a024761d83e3c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2085,10 +2085,15 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, SourceLocation Loc) {
}
if (LV.isVectorElt()) {
- llvm::LoadInst *Load = Builder.CreateLoad(LV.getVectorAddress(),
- LV.isVolatileQualified());
- return RValue::get(Builder.CreateExtractElement(Load, LV.getVectorIdx(),
- "vecext"));
+ llvm::Value *Load = nullptr;
+ if (LV.getType()->isExtVectorBoolType())
+ Load = EmitLoadOfScalar(LV.getVectorAddress(), LV.isVolatileQualified(),
+ LV.getType(), Loc);
+ else
+ Load =
+ Builder.CreateLoad(LV.getVectorAddress(), LV.isVolatileQualified());
+ return RValue::get(
+ Builder.CreateExtractElement(Load, LV.getVectorIdx(), "vecext"));
}
// If this is a reference to a subset of the elements of a vector, either
diff --git a/clang/test/CodeGen/gh72468.c b/clang/test/CodeGen/gh72468.c
new file mode 100644
index 00000000000000..7a602d4982803e
--- /dev/null
+++ b/clang/test/CodeGen/gh72468.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -S -emit-llvm -o - %s
+
+typedef __attribute__((__ext_vector_type__(4))) _Bool BoolVector;
+
+BoolVector vec;
+
+void f(int i, int j) {
+ vec[i] |= vec[j];
+}
\ No newline at end of file
diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp
index e99d420e73fab2..5ec87beb4ed055 100644
--- a/clang/test/SemaCXX/vector-bool.cpp
+++ b/clang/test/SemaCXX/vector-bool.cpp
@@ -38,10 +38,10 @@ void Operations() {
// (void)(eight_bools > other_eight_bools);
// (void)(eight_bools >= other_eight_bools);
- // // Legal assignments
- // (void)(eight_bools |= other_eight_bools);
- // (void)(eight_bools &= other_eight_bools);
- // (void)(eight_bools ^= other_eight_bools);
+ // Legal assignments
+ (void)(eight_bools |= other_eight_bools);
+ (void)(eight_bools &= other_eight_bools);
+ (void)(eight_bools ^= other_eight_bools);
// Illegal operators
(void)(eight_bools || other_eight_bools); // expected-error at 47 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/75435
More information about the cfe-commits
mailing list