Author: Timm Bäder Date: 2024-05-14T12:55:45+02:00 New Revision: c1bd68867497cf6e2f2afdba1a3a2993a47b5856
URL: https://github.com/llvm/llvm-project/commit/c1bd68867497cf6e2f2afdba1a3a2993a47b5856 DIFF: https://github.com/llvm/llvm-project/commit/c1bd68867497cf6e2f2afdba1a3a2993a47b5856.diff LOG: [clang][Interp] Fix some dummy-related FIXME comments Added: Modified: clang/lib/AST/Interp/Interp.h clang/lib/AST/Interp/Pointer.h clang/lib/AST/Interp/Program.cpp clang/test/AST/Interp/arrays.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index a0bf874300120..d9f23a4b8c965 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -1569,9 +1569,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, APSInt NewIndex = (Op == ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset); S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index) - << NewIndex - << /*array*/ static_cast<int>(!Ptr.inArray()) - << static_cast<unsigned>(MaxIndex); + << NewIndex << /*array*/ static_cast<int>(!Ptr.inArray()) << MaxIndex; Invalid = true; }; @@ -1598,7 +1596,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset, } } - if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus) + if (Invalid && S.getLangOpts().CPlusPlus) return false; // Offset is valid - compute it on unsigned. @@ -2110,6 +2108,9 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) { return true; } + if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer)) + return false; + if (!Ptr.isUnknownSizeArray() || Ptr.isDummy()) { S.Stk.push<Pointer>(Ptr.atIndex(0)); return true; diff --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h index 79fab05670e96..9900f37e60d4e 100644 --- a/clang/lib/AST/Interp/Pointer.h +++ b/clang/lib/AST/Interp/Pointer.h @@ -384,11 +384,6 @@ class Pointer { bool isUnknownSizeArray() const { if (!isBlockPointer()) return false; - // If this points inside a dummy block, return true. - // FIXME: This might change in the future. If it does, we need - // to set the proper Ctor/Dtor functions for dummy Descriptors. - if (!isRoot() && isDummy()) - return true; return getFieldDesc()->isUnknownSizeArray(); } /// Checks if the pointer points to an array. @@ -560,8 +555,6 @@ class Pointer { if (!asBlockPointer().Pointee) return false; - if (isDummy()) - return false; return isElementPastEnd() || getSize() == getOffset(); } diff --git a/clang/lib/AST/Interp/Program.cpp b/clang/lib/AST/Interp/Program.cpp index 0b95db8492695..31a64e13d2b15 100644 --- a/clang/lib/AST/Interp/Program.cpp +++ b/clang/lib/AST/Interp/Program.cpp @@ -144,8 +144,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const ValueDecl *VD) { if (auto It = DummyVariables.find(VD); It != DummyVariables.end()) return It->second; + QualType QT = VD->getType(); + if (const auto *RT = QT->getAs<ReferenceType>()) + QT = RT->getPointeeType(); + Descriptor *Desc; - if (std::optional<PrimType> T = Ctx.classify(VD->getType())) + if (std::optional<PrimType> T = Ctx.classify(QT)) Desc = createDescriptor(VD, *T, std::nullopt, true, false); else Desc = createDescriptor(VD, VD->getType().getTypePtr(), std::nullopt, true, diff --git a/clang/test/AST/Interp/arrays.cpp b/clang/test/AST/Interp/arrays.cpp index f6d265d4b3d10..929f25b95fa1f 100644 --- a/clang/test/AST/Interp/arrays.cpp +++ b/clang/test/AST/Interp/arrays.cpp @@ -580,3 +580,18 @@ constexpr ptr diff _t d3 = &melchizedek[0] - &melchizedek[1]; // ok /// GH#88018 const int SZA[] = {}; void testZeroSizedArrayAccess() { unsigned c = SZA[4]; } + +#if __cplusplus >= 202002L +constexpr int test_multiarray2() { // both-error {{never produces a constant expression}} + int multi2[2][1]; // both-note {{declared here}} + return multi2[2][0]; // both-note {{cannot access array element of pointer past the end of object}} \ + // both-warning {{array index 2 is past the end of the array (that has type 'int[2][1]')}} +} + +/// Same but with a dummy pointer. +int multi22[2][2]; // both-note {{declared here}} +int test_multiarray22() { + return multi22[2][0]; // both-warning {{array index 2 is past the end of the array (that has type 'int[2][2]')}} +} + +#endif _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits