[PATCH] D49951: [AST] [NFC] Add a convenient getter from QualType to RecordDecl
George Karpenkov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 27 19:16:44 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338187: [AST] Add a convenient getter from QualType to RecordDecl (authored by george.karpenkov, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D49951?vs=157827&id=157828#toc
Repository:
rL LLVM
https://reviews.llvm.org/D49951
Files:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Analysis/BodyFarm.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
Index: cfe/trunk/lib/CodeGen/CGExprConstant.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGExprConstant.cpp
+++ cfe/trunk/lib/CodeGen/CGExprConstant.cpp
@@ -2064,8 +2064,7 @@
if (record->isUnion()) {
if (Field->getIdentifier())
break;
- if (const auto *FieldRD =
- dyn_cast_or_null<RecordDecl>(Field->getType()->getAsTagDecl()))
+ if (const auto *FieldRD = Field->getType()->getAsRecordDecl())
if (FieldRD->findFirstNamedDataMember())
break;
}
Index: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
===================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
@@ -313,9 +313,8 @@
if (!SeenNamedMember) {
SeenNamedMember = Field->getIdentifier();
if (!SeenNamedMember)
- if (const auto *FieldRD =
- dyn_cast_or_null<RecordDecl>(Field->getType()->getAsTagDecl()))
- SeenNamedMember = FieldRD->findFirstNamedDataMember();
+ if (const auto *FieldRD = Field->getType()->getAsRecordDecl())
+ SeenNamedMember = FieldRD->findFirstNamedDataMember();
if (SeenNamedMember && !isZeroInitializable(Field)) {
IsZeroInitializable = IsZeroInitializableAsBase = false;
StorageType = FieldType;
Index: cfe/trunk/lib/AST/Decl.cpp
===================================================================
--- cfe/trunk/lib/AST/Decl.cpp
+++ cfe/trunk/lib/AST/Decl.cpp
@@ -3149,12 +3149,9 @@
const Attr *FunctionDecl::getUnusedResultAttr() const {
QualType RetType = getReturnType();
- if (RetType->isRecordType()) {
- if (const auto *Ret =
- dyn_cast_or_null<RecordDecl>(RetType->getAsTagDecl())) {
- if (const auto *R = Ret->getAttr<WarnUnusedResultAttr>())
- return R;
- }
+ if (const auto *Ret = RetType->getAsRecordDecl()) {
+ if (const auto *R = Ret->getAttr<WarnUnusedResultAttr>())
+ return R;
} else if (const auto *ET = RetType->getAs<EnumType>()) {
if (const EnumDecl *ED = ET->getDecl()) {
if (const auto *R = ED->getAttr<WarnUnusedResultAttr>())
Index: cfe/trunk/lib/AST/Type.cpp
===================================================================
--- cfe/trunk/lib/AST/Type.cpp
+++ cfe/trunk/lib/AST/Type.cpp
@@ -1628,6 +1628,10 @@
return dyn_cast_or_null<CXXRecordDecl>(getAsTagDecl());
}
+RecordDecl *Type::getAsRecordDecl() const {
+ return dyn_cast_or_null<RecordDecl>(getAsTagDecl());
+}
+
TagDecl *Type::getAsTagDecl() const {
if (const auto *TT = getAs<TagType>())
return TT->getDecl();
Index: cfe/trunk/lib/Analysis/BodyFarm.cpp
===================================================================
--- cfe/trunk/lib/Analysis/BodyFarm.cpp
+++ cfe/trunk/lib/Analysis/BodyFarm.cpp
@@ -342,7 +342,7 @@
// Nullable pointer, non-null iff function is a CXXRecordDecl.
CXXRecordDecl *CallbackRecordDecl = CallbackType->getAsCXXRecordDecl();
QualType FlagType = Flag->getType().getNonReferenceType();
- auto *FlagRecordDecl = dyn_cast_or_null<RecordDecl>(FlagType->getAsTagDecl());
+ auto *FlagRecordDecl = FlagType->getAsRecordDecl();
if (!FlagRecordDecl) {
LLVM_DEBUG(llvm::dbgs() << "Flag field is not a record: "
Index: cfe/trunk/include/clang/AST/Type.h
===================================================================
--- cfe/trunk/include/clang/AST/Type.h
+++ cfe/trunk/include/clang/AST/Type.h
@@ -2017,6 +2017,9 @@
/// type of a class template or class template partial specialization.
CXXRecordDecl *getAsCXXRecordDecl() const;
+ /// Retrieves the RecordDecl this type refers to.
+ RecordDecl *getAsRecordDecl() const;
+
/// Retrieves the TagDecl that this type refers to, either
/// because the type is a TagType or because it is the injected-class-name
/// type of a class template or class template partial specialization.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49951.157828.patch
Type: text/x-patch
Size: 3961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180728/f9cbefcb/attachment.bin>
More information about the llvm-commits
mailing list