-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang][CodeGen] Fix crash when using bool vector in compound assignment #75435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Chenyang Gao (cygao90) ChangesFixes: #72468. Full diff: https://github.com/llvm/llvm-project/pull/75435.diff 3 Files Affected:
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@47 {{invalid operands to binary expression ('EightBools' (vector of 8 'bool' values) and 'EightBools')}}
|
|
Ping |
|
Could you please test that your patch still fixes the issue when applied on top of current git trunk? |
|
@cygao90 Do you still intend to get this PR merged? |
|
Hi, sorry for the late response. I haven't tested this yet, but this pr is old, I will close it. Feel free to submit a new PR to fix this issue. |
Fixes: #72468.
The left side bool vector
vec[i]did not perform a specific conversion(CodeGenFunction::emitBoolVecConversion) in compound assignment.