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 <fd...@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 -----------------------
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 -----------------------
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits