[clang] [Clang][CodeGen] Fix crash when using bool vector in compound assignment (PR #75435)
Chenyang Gao via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 13 23:22:47 PST 2023
https://github.com/cygao90 created https://github.com/llvm/llvm-project/pull/75435
Fixes: #72468.
The left side bool vector did not perform a specific conversion(`CodeGenFunction::emitBoolVecConversion`) in compound assignment
>From 04e97b13e274a10bf199cc143c758d6d3889db31 Mon Sep 17 00:00:00 2001
From: Chenyang Gao <cygao09 at gmail.com>
Date: Thu, 14 Dec 2023 15:16:30 +0800
Subject: [PATCH] [Clang][CodeGen] Fix crash when using bool vector in compound
assignment
---
clang/lib/CodeGen/CGExpr.cpp | 13 +++++++++----
clang/test/CodeGen/gh72468.c | 9 +++++++++
clang/test/SemaCXX/vector-bool.cpp | 8 ++++----
3 files changed, 22 insertions(+), 8 deletions(-)
create mode 100644 clang/test/CodeGen/gh72468.c
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')}}
More information about the cfe-commits
mailing list