[PATCH] D157584: [clang][Sema] Skip access check on arrays of zero-length element
Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 11 07:07:56 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f73a2406a16: [clang][Sema] Skip access check on arrays of zero-length element (authored by dingfei <fding at feysh.com>).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157584/new/
https://reviews.llvm.org/D157584
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/array-bounds-zero-length-elem-gh64564.c
Index: clang/test/Sema/array-bounds-zero-length-elem-gh64564.c
===================================================================
--- /dev/null
+++ clang/test/Sema/array-bounds-zero-length-elem-gh64564.c
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple i686-apple-darwin -verify %s
+
+int a[][0]; // expected-warning {{tentative array definition assumed to have one element}}
+void gh64564_1(void) {
+ int b = a[0x100000000][0];
+}
+
+typedef struct {} S;
+S s[]; // expected-warning {{tentative array definition assumed to have one element}}
+void gh64564_2(void) {
+ S t = s[0x100000000];
+}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -17146,7 +17146,7 @@
ASTC.getTypeSizeInCharsIfKnown(EffectiveType);
// PR50741 - If EffectiveType has unknown size (e.g., if it's a void
// pointer) bounds-checking isn't meaningful.
- if (!ElemCharUnits)
+ if (!ElemCharUnits || ElemCharUnits->isZero())
return;
llvm::APInt ElemBytes(index.getBitWidth(), ElemCharUnits->getQuantity());
// If index has more active bits than address space, we already know
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -185,6 +185,8 @@
terminated. Clang should now also recover better when an @end is missing
between blocks.
`Issue 64065 <https://github.com/llvm/llvm-project/issues/64065>`_
+- Fixed a crash when check array access on zero-length element.
+ `Issue 64564 <https://github.com/llvm/llvm-project/issues/64564>`_
Target Specific Changes
-----------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157584.549381.patch
Type: text/x-patch
Size: 1777 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230811/e027525f/attachment.bin>
More information about the cfe-commits
mailing list