[clang] c0c36aa - [clang codegen] fix crash emitting __array_rank (#113186)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 22 02:03:55 PDT 2024
Author: Congcong Cai
Date: 2024-10-22T17:03:51+08:00
New Revision: c0c36aa0189de217d7a312829ba40e838090294d
URL: https://github.com/llvm/llvm-project/commit/c0c36aa0189de217d7a312829ba40e838090294d
DIFF: https://github.com/llvm/llvm-project/commit/c0c36aa0189de217d7a312829ba40e838090294d.diff
LOG: [clang codegen] fix crash emitting __array_rank (#113186)
Fixed: #113044
the type of `ArrayTypeTraitExpr` can be changed, use i32 directly is
incorrect.
---------
Co-authored-by: Eli Friedman <efriedma at quicinc.com>
Added:
clang/test/CodeGen/builtins-array-rank.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/CGExprScalar.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2870103f5fc7ee..6f44ff5c1efa96 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -439,6 +439,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 using ``__array_rank`` on 64-bit targets. (#GH113044).
- The warning emitted for an unsupported register variable type now points to
the unsupported type instead of the ``register`` keyword (#GH109776).
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 7529d4465f2c34..9e2c2ad5e0250e 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -722,7 +722,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;
+}
More information about the cfe-commits
mailing list