Skip to content

Commit c1bd688

Browse files
committed
[clang][Interp] Fix some dummy-related FIXME comments
1 parent 5865482 commit c1bd688

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,9 +1569,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
15691569
APSInt NewIndex =
15701570
(Op == ArithOp::Add) ? (APIndex + APOffset) : (APIndex - APOffset);
15711571
S.CCEDiag(S.Current->getSource(OpPC), diag::note_constexpr_array_index)
1572-
<< NewIndex
1573-
<< /*array*/ static_cast<int>(!Ptr.inArray())
1574-
<< static_cast<unsigned>(MaxIndex);
1572+
<< NewIndex << /*array*/ static_cast<int>(!Ptr.inArray()) << MaxIndex;
15751573
Invalid = true;
15761574
};
15771575

@@ -1598,7 +1596,7 @@ bool OffsetHelper(InterpState &S, CodePtr OpPC, const T &Offset,
15981596
}
15991597
}
16001598

1601-
if (Invalid && !Ptr.isDummy() && S.getLangOpts().CPlusPlus)
1599+
if (Invalid && S.getLangOpts().CPlusPlus)
16021600
return false;
16031601

16041602
// Offset is valid - compute it on unsigned.
@@ -2110,6 +2108,9 @@ inline bool ArrayDecay(InterpState &S, CodePtr OpPC) {
21102108
return true;
21112109
}
21122110

2111+
if (!CheckRange(S, OpPC, Ptr, CSK_ArrayToPointer))
2112+
return false;
2113+
21132114
if (!Ptr.isUnknownSizeArray() || Ptr.isDummy()) {
21142115
S.Stk.push<Pointer>(Ptr.atIndex(0));
21152116
return true;

clang/lib/AST/Interp/Pointer.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -384,11 +384,6 @@ class Pointer {
384384
bool isUnknownSizeArray() const {
385385
if (!isBlockPointer())
386386
return false;
387-
// If this points inside a dummy block, return true.
388-
// FIXME: This might change in the future. If it does, we need
389-
// to set the proper Ctor/Dtor functions for dummy Descriptors.
390-
if (!isRoot() && isDummy())
391-
return true;
392387
return getFieldDesc()->isUnknownSizeArray();
393388
}
394389
/// Checks if the pointer points to an array.
@@ -560,8 +555,6 @@ class Pointer {
560555

561556
if (!asBlockPointer().Pointee)
562557
return false;
563-
if (isDummy())
564-
return false;
565558

566559
return isElementPastEnd() || getSize() == getOffset();
567560
}

clang/lib/AST/Interp/Program.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,12 @@ std::optional<unsigned> Program::getOrCreateDummy(const ValueDecl *VD) {
144144
if (auto It = DummyVariables.find(VD); It != DummyVariables.end())
145145
return It->second;
146146

147+
QualType QT = VD->getType();
148+
if (const auto *RT = QT->getAs<ReferenceType>())
149+
QT = RT->getPointeeType();
150+
147151
Descriptor *Desc;
148-
if (std::optional<PrimType> T = Ctx.classify(VD->getType()))
152+
if (std::optional<PrimType> T = Ctx.classify(QT))
149153
Desc = createDescriptor(VD, *T, std::nullopt, true, false);
150154
else
151155
Desc = createDescriptor(VD, VD->getType().getTypePtr(), std::nullopt, true,

clang/test/AST/Interp/arrays.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,18 @@ constexpr ptrdiff_t d3 = &melchizedek[0] - &melchizedek[1]; // ok
580580
/// GH#88018
581581
const int SZA[] = {};
582582
void testZeroSizedArrayAccess() { unsigned c = SZA[4]; }
583+
584+
#if __cplusplus >= 202002L
585+
constexpr int test_multiarray2() { // both-error {{never produces a constant expression}}
586+
int multi2[2][1]; // both-note {{declared here}}
587+
return multi2[2][0]; // both-note {{cannot access array element of pointer past the end of object}} \
588+
// both-warning {{array index 2 is past the end of the array (that has type 'int[2][1]')}}
589+
}
590+
591+
/// Same but with a dummy pointer.
592+
int multi22[2][2]; // both-note {{declared here}}
593+
int test_multiarray22() {
594+
return multi22[2][0]; // both-warning {{array index 2 is past the end of the array (that has type 'int[2][2]')}}
595+
}
596+
597+
#endif

0 commit comments

Comments
 (0)