Skip to content

Commit 2e7d711

Browse files
[clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr
Differential Revision: https://reviews.llvm.org/D154471
1 parent b2f7b5d commit 2e7d711

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

clang/include/clang/AST/PropertiesBase.td

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,13 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
450450
lvalueBase ? lvalueBase.dyn_cast<const Expr *>() : nullptr;
451451
bool lvalueBaseIsExpr = (bool) expr;
452452
bool lvalueBaseIsTypeInfo = lvalueBase.is<TypeInfoLValue>();
453+
bool lvalueBaseIsDynamicAlloc = lvalueBase.is<DynamicAllocLValue>();
453454
QualType elemTy;
454455
if (lvalueBase) {
455456
if (lvalueBaseIsTypeInfo) {
456457
elemTy = lvalueBase.getTypeInfoType();
458+
} else if (lvalueBaseIsDynamicAlloc) {
459+
elemTy = lvalueBase.getDynamicAllocType();
457460
} else if (lvalueBaseIsExpr) {
458461
elemTy = expr->getType();
459462
} else {
@@ -473,6 +476,9 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
473476
def : Property<"isTypeInfo", Bool> {
474477
let Read = [{ lvalueBaseIsTypeInfo }];
475478
}
479+
def : Property<"isDynamicAlloc", Bool> {
480+
let Read = [{ lvalueBaseIsDynamicAlloc }];
481+
}
476482
def : Property<"hasBase", Bool> {
477483
let Read = [{ static_cast<bool>(lvalueBase) }];
478484
}
@@ -485,9 +491,17 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
485491
QualType(node.getLValueBase().get<TypeInfoLValue>().getType(), 0)
486492
}];
487493
}
494+
def : Property<"dynamicAlloc", UInt32> {
495+
let Conditional = [{ hasBase && isDynamicAlloc }];
496+
let Read = [{ node.getLValueBase().get<DynamicAllocLValue>().getIndex() }];
497+
}
488498
def : Property<"type", QualType> {
489-
let Conditional = [{ hasBase && isTypeInfo }];
490-
let Read = [{ node.getLValueBase().getTypeInfoType() }];
499+
let Conditional = [{ hasBase && (isTypeInfo || isDynamicAlloc) }];
500+
let Read = [{
501+
isTypeInfo
502+
? node.getLValueBase().getTypeInfoType()
503+
: node.getLValueBase().getDynamicAllocType()
504+
}];
491505
}
492506
def : Property<"callIndex", UInt32> {
493507
let Conditional = [{ hasBase && !isTypeInfo }];
@@ -502,7 +516,7 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
502516
let Read = [{ const_cast<Expr *>(expr) }];
503517
}
504518
def : Property<"decl", DeclRef> {
505-
let Conditional = [{ hasBase && !isTypeInfo && !isExpr }];
519+
let Conditional = [{ hasBase && !isTypeInfo && !isDynamicAlloc && !isExpr }];
506520
let Read = [{ lvalueBase.get<const ValueDecl *>() }];
507521
}
508522
def : Property<"offsetQuantity", UInt32> {
@@ -521,6 +535,9 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
521535
if (isTypeInfo) {
522536
base = APValue::LValueBase::getTypeInfo(
523537
TypeInfoLValue(typeInfo->getTypePtr()), *type);
538+
} else if (isDynamicAlloc) {
539+
base = APValue::LValueBase::getDynamicAlloc(
540+
DynamicAllocLValue(*dynamicAlloc), *type);
524541
} else if (isExpr) {
525542
base = APValue::LValueBase(cast<Expr>(*stmt),
526543
*callIndex, *version);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -emit-pch -o %t %s
2+
3+
// Test that serialization/deserialization of a DynamicAllocLValue
4+
// variant of APValue does not crash.
5+
6+
#ifndef HEADER
7+
#define HEADER
8+
9+
struct A { int *p; };
10+
const A &w = A{ new int(10) };
11+
12+
#endif

0 commit comments

Comments
 (0)