Skip to content

Commit 379b777

Browse files
committed
[clang][Interp] Use pointee metadata size in isRoot()
Previously, isRoot() would return true for pointers with a base of sizeof(InlineDescriptor), even if the actual metadata size of the pointee was 0.
1 parent 1337622 commit 379b777

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

clang/lib/AST/Interp/Pointer.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,7 @@ class Pointer {
226226
return *this;
227227

228228
// If at base, point to an array of base types.
229-
if (asBlockPointer().Base == 0 ||
230-
asBlockPointer().Base == sizeof(InlineDescriptor))
229+
if (isRoot())
231230
return Pointer(asBlockPointer().Pointee, RootPtrMark, 0);
232231

233232
// Step into the containing array, if inside one.
@@ -306,10 +305,8 @@ class Pointer {
306305
const Descriptor *getFieldDesc() const {
307306
if (isIntegralPointer())
308307
return asIntPointer().Desc;
309-
if (isBlockPointer() &&
310-
(asBlockPointer().Base == 0 ||
311-
asBlockPointer().Base == sizeof(InlineDescriptor) ||
312-
asBlockPointer().Base == RootPtrMark))
308+
309+
if (isRoot())
313310
return getDeclDesc();
314311
return getInlineDesc()->Desc;
315312
}
@@ -390,8 +387,7 @@ class Pointer {
390387
// If this points inside a dummy block, return true.
391388
// FIXME: This might change in the future. If it does, we need
392389
// to set the proper Ctor/Dtor functions for dummy Descriptors.
393-
if (asBlockPointer().Base != 0 &&
394-
asBlockPointer().Base != sizeof(InlineDescriptor) && isDummy())
390+
if (!isRoot() && isDummy())
395391
return true;
396392
return getFieldDesc()->isUnknownSizeArray();
397393
}
@@ -403,9 +399,11 @@ class Pointer {
403399
}
404400
/// Pointer points directly to a block.
405401
bool isRoot() const {
406-
return (asBlockPointer().Base == 0 ||
407-
asBlockPointer().Base == RootPtrMark) &&
408-
Offset == 0;
402+
if (isZero() || isIntegralPointer())
403+
return true;
404+
return (asBlockPointer().Base ==
405+
asBlockPointer().Pointee->getDescriptor()->getMetadataSize() ||
406+
asBlockPointer().Base == 0);
409407
}
410408
/// If this pointer has an InlineDescriptor we can use to initialize.
411409
bool canBeInitialized() const {
@@ -487,9 +485,7 @@ class Pointer {
487485
bool isActive() const {
488486
if (!isBlockPointer())
489487
return true;
490-
return asBlockPointer().Base == 0 ||
491-
asBlockPointer().Base == sizeof(InlineDescriptor) ||
492-
getInlineDesc()->IsActive;
488+
return isRoot() || getInlineDesc()->IsActive;
493489
}
494490
/// Checks if a structure is a base class.
495491
bool isBaseClass() const { return isField() && getInlineDesc()->IsBase; }
@@ -508,10 +504,7 @@ class Pointer {
508504
bool isConst() const {
509505
if (isIntegralPointer())
510506
return true;
511-
return (asBlockPointer().Base == 0 ||
512-
asBlockPointer().Base == sizeof(InlineDescriptor))
513-
? getDeclDesc()->IsConst
514-
: getInlineDesc()->IsConst;
507+
return isRoot() ? getDeclDesc()->IsConst : getInlineDesc()->IsConst;
515508
}
516509

517510
/// Returns the declaration ID.
@@ -567,6 +560,9 @@ class Pointer {
567560

568561
if (!asBlockPointer().Pointee)
569562
return false;
563+
if (isDummy())
564+
return false;
565+
570566
return isElementPastEnd() || getSize() == getOffset();
571567
}
572568

clang/unittests/AST/Interp/Descriptor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST(Descriptor, Primitives) {
115115

116116
// Check pointer stuff.
117117
// Global variables have an inline descriptor.
118-
ASSERT_FALSE(GlobalPtr.isRoot());
118+
ASSERT_TRUE(GlobalPtr.isRoot());
119119
ASSERT_TRUE(GlobalPtr.isLive());
120120
ASSERT_FALSE(GlobalPtr.isZero());
121121
ASSERT_FALSE(GlobalPtr.isField());

0 commit comments

Comments
 (0)