Skip to content

Commit

Permalink
[clang] Add serialization support for the DynamicAllocLValue variant …
Browse files Browse the repository at this point in the history
…of APValue::LValueBase::Ptr

Differential Revision: https://reviews.llvm.org/D154471
  • Loading branch information
HighCommander4 committed Jul 22, 2023
1 parent b2f7b5d commit 2e7d711
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
23 changes: 20 additions & 3 deletions clang/include/clang/AST/PropertiesBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,13 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
lvalueBase ? lvalueBase.dyn_cast<const Expr *>() : nullptr;
bool lvalueBaseIsExpr = (bool) expr;
bool lvalueBaseIsTypeInfo = lvalueBase.is<TypeInfoLValue>();
bool lvalueBaseIsDynamicAlloc = lvalueBase.is<DynamicAllocLValue>();
QualType elemTy;
if (lvalueBase) {
if (lvalueBaseIsTypeInfo) {
elemTy = lvalueBase.getTypeInfoType();
} else if (lvalueBaseIsDynamicAlloc) {
elemTy = lvalueBase.getDynamicAllocType();
} else if (lvalueBaseIsExpr) {
elemTy = expr->getType();
} else {
Expand All @@ -473,6 +476,9 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
def : Property<"isTypeInfo", Bool> {
let Read = [{ lvalueBaseIsTypeInfo }];
}
def : Property<"isDynamicAlloc", Bool> {
let Read = [{ lvalueBaseIsDynamicAlloc }];
}
def : Property<"hasBase", Bool> {
let Read = [{ static_cast<bool>(lvalueBase) }];
}
Expand All @@ -485,9 +491,17 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
QualType(node.getLValueBase().get<TypeInfoLValue>().getType(), 0)
}];
}
def : Property<"dynamicAlloc", UInt32> {
let Conditional = [{ hasBase && isDynamicAlloc }];
let Read = [{ node.getLValueBase().get<DynamicAllocLValue>().getIndex() }];
}
def : Property<"type", QualType> {
let Conditional = [{ hasBase && isTypeInfo }];
let Read = [{ node.getLValueBase().getTypeInfoType() }];
let Conditional = [{ hasBase && (isTypeInfo || isDynamicAlloc) }];
let Read = [{
isTypeInfo
? node.getLValueBase().getTypeInfoType()
: node.getLValueBase().getDynamicAllocType()
}];
}
def : Property<"callIndex", UInt32> {
let Conditional = [{ hasBase && !isTypeInfo }];
Expand All @@ -502,7 +516,7 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
let Read = [{ const_cast<Expr *>(expr) }];
}
def : Property<"decl", DeclRef> {
let Conditional = [{ hasBase && !isTypeInfo && !isExpr }];
let Conditional = [{ hasBase && !isTypeInfo && !isDynamicAlloc && !isExpr }];
let Read = [{ lvalueBase.get<const ValueDecl *>() }];
}
def : Property<"offsetQuantity", UInt32> {
Expand All @@ -521,6 +535,9 @@ let Class = PropertyTypeCase<APValue, "LValue"> in {
if (isTypeInfo) {
base = APValue::LValueBase::getTypeInfo(
TypeInfoLValue(typeInfo->getTypePtr()), *type);
} else if (isDynamicAlloc) {
base = APValue::LValueBase::getDynamicAlloc(
DynamicAllocLValue(*dynamicAlloc), *type);
} else if (isExpr) {
base = APValue::LValueBase(cast<Expr>(*stmt),
*callIndex, *version);
Expand Down
12 changes: 12 additions & 0 deletions clang/test/AST/dynamic-alloc-lvalue.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %clang_cc1 -emit-pch -o %t %s

// Test that serialization/deserialization of a DynamicAllocLValue
// variant of APValue does not crash.

#ifndef HEADER
#define HEADER

struct A { int *p; };
const A &w = A{ new int(10) };

#endif

0 comments on commit 2e7d711

Please sign in to comment.