From 2e7d711a106170185e9bbbf15115613d9a5854c5 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Fri, 21 Jul 2023 04:05:14 -0400 Subject: [PATCH] [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr Differential Revision: https://reviews.llvm.org/D154471 --- clang/include/clang/AST/PropertiesBase.td | 23 ++++++++++++++++++++--- clang/test/AST/dynamic-alloc-lvalue.cpp | 12 ++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 clang/test/AST/dynamic-alloc-lvalue.cpp diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index f289c95..cd8b95b 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -450,10 +450,13 @@ let Class = PropertyTypeCase in { lvalueBase ? lvalueBase.dyn_cast() : nullptr; bool lvalueBaseIsExpr = (bool) expr; bool lvalueBaseIsTypeInfo = lvalueBase.is(); + bool lvalueBaseIsDynamicAlloc = lvalueBase.is(); QualType elemTy; if (lvalueBase) { if (lvalueBaseIsTypeInfo) { elemTy = lvalueBase.getTypeInfoType(); + } else if (lvalueBaseIsDynamicAlloc) { + elemTy = lvalueBase.getDynamicAllocType(); } else if (lvalueBaseIsExpr) { elemTy = expr->getType(); } else { @@ -473,6 +476,9 @@ let Class = PropertyTypeCase in { def : Property<"isTypeInfo", Bool> { let Read = [{ lvalueBaseIsTypeInfo }]; } + def : Property<"isDynamicAlloc", Bool> { + let Read = [{ lvalueBaseIsDynamicAlloc }]; + } def : Property<"hasBase", Bool> { let Read = [{ static_cast(lvalueBase) }]; } @@ -485,9 +491,17 @@ let Class = PropertyTypeCase in { QualType(node.getLValueBase().get().getType(), 0) }]; } + def : Property<"dynamicAlloc", UInt32> { + let Conditional = [{ hasBase && isDynamicAlloc }]; + let Read = [{ node.getLValueBase().get().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 }]; @@ -502,7 +516,7 @@ let Class = PropertyTypeCase in { let Read = [{ const_cast(expr) }]; } def : Property<"decl", DeclRef> { - let Conditional = [{ hasBase && !isTypeInfo && !isExpr }]; + let Conditional = [{ hasBase && !isTypeInfo && !isDynamicAlloc && !isExpr }]; let Read = [{ lvalueBase.get() }]; } def : Property<"offsetQuantity", UInt32> { @@ -521,6 +535,9 @@ let Class = PropertyTypeCase 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(*stmt), *callIndex, *version); diff --git a/clang/test/AST/dynamic-alloc-lvalue.cpp b/clang/test/AST/dynamic-alloc-lvalue.cpp new file mode 100644 index 0000000..2a42663 --- /dev/null +++ b/clang/test/AST/dynamic-alloc-lvalue.cpp @@ -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 -- 2.7.4