-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang codegen] fix crash emitting __array_rank #113186
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
@llvm/pr-subscribers-clang Author: Congcong Cai (HerrCai0907) ChangesFixed: #113044 Full diff: https://github.com/llvm/llvm-project/pull/113186.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35c31452cef411..550c5f1b2c2126 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -374,6 +374,7 @@ Bug Fixes in This Version
- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
- Fixed a crash when diagnosing format strings and encountering an empty
delimited escape sequence (e.g., ``"\o{}"``). #GH102218
+- Fixed a crash when the result of ``__array_rank`` is used as operand for bit operation. (#GH113044).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index b7f5b932c56b6f..0ea757fc0befdb 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -718,7 +718,7 @@ class ScalarExprEmitter
}
Value *VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
- return llvm::ConstantInt::get(Builder.getInt32Ty(), E->getValue());
+ return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
}
Value *VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
diff --git a/clang/test/CodeGen/builtins-array-rank.cpp b/clang/test/CodeGen/builtins-array-rank.cpp
new file mode 100644
index 00000000000000..e6f0a55245aad9
--- /dev/null
+++ b/clang/test/CodeGen/builtins-array-rank.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+unsigned long array_rank_binary_operator(void) {
+ // CHECK: ret i64 3
+ return __array_rank(int[10]) | 2;
+}
|
@llvm/pr-subscribers-clang-codegen Author: Congcong Cai (HerrCai0907) ChangesFixed: #113044 Full diff: https://github.com/llvm/llvm-project/pull/113186.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 35c31452cef411..550c5f1b2c2126 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -374,6 +374,7 @@ Bug Fixes in This Version
- Fixed a crash when trying to transform a dependent address space type. Fixes #GH101685.
- Fixed a crash when diagnosing format strings and encountering an empty
delimited escape sequence (e.g., ``"\o{}"``). #GH102218
+- Fixed a crash when the result of ``__array_rank`` is used as operand for bit operation. (#GH113044).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index b7f5b932c56b6f..0ea757fc0befdb 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -718,7 +718,7 @@ class ScalarExprEmitter
}
Value *VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {
- return llvm::ConstantInt::get(Builder.getInt32Ty(), E->getValue());
+ return llvm::ConstantInt::get(ConvertType(E->getType()), E->getValue());
}
Value *VisitExpressionTraitExpr(const ExpressionTraitExpr *E) {
diff --git a/clang/test/CodeGen/builtins-array-rank.cpp b/clang/test/CodeGen/builtins-array-rank.cpp
new file mode 100644
index 00000000000000..e6f0a55245aad9
--- /dev/null
+++ b/clang/test/CodeGen/builtins-array-rank.cpp
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple aarch64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+unsigned long array_rank_binary_operator(void) {
+ // CHECK: ret i64 3
+ return __array_rank(int[10]) | 2;
+}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make the title of the pull request something more useful, like "[clang codegen] fix crash emitting __array_rank". The current title is utterly useless for someone looking through the commit history.
LGTM with comments addressed.
Co-authored-by: Eli Friedman <[email protected]>
Fixed: #113044
the type of
ArrayTypeTraitExpr
can be changed, use i32 directly is incorrect.