[clang] f7c96d5 - [Interp] Record::getBase - merge isRecordType/getAs<RecordType>() checks. NFC.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 08:55:57 PDT 2024


Author: Simon Pilgrim
Date: 2024-06-19T16:55:33+01:00
New Revision: f7c96d5733915c4ea30dbd7852faffc9cef4aca9

URL: https://github.com/llvm/llvm-project/commit/f7c96d5733915c4ea30dbd7852faffc9cef4aca9
DIFF: https://github.com/llvm/llvm-project/commit/f7c96d5733915c4ea30dbd7852faffc9cef4aca9.diff

LOG: [Interp] Record::getBase - merge isRecordType/getAs<RecordType>() checks. NFC.

Noticed because static analyzer doesn't understand that isRecordType is just a wrapper to isa<> and was warning about a potential null dereference

Added: 
    

Modified: 
    clang/lib/AST/Interp/Record.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Record.cpp b/clang/lib/AST/Interp/Record.cpp
index 8ded765fc1c41..ac01524e1caf0 100644
--- a/clang/lib/AST/Interp/Record.cpp
+++ b/clang/lib/AST/Interp/Record.cpp
@@ -49,11 +49,11 @@ const Record::Base *Record::getBase(const RecordDecl *FD) const {
 }
 
 const Record::Base *Record::getBase(QualType T) const {
-  if (!T->isRecordType())
-    return nullptr;
-
-  const RecordDecl *RD = T->getAs<RecordType>()->getDecl();
-  return BaseMap.lookup(RD);
+  if (auto *RT = T->getAs<RecordType>()) {
+    const RecordDecl *RD = RT->getDecl();
+    return BaseMap.lookup(RD);
+  }
+  return nullptr;
 }
 
 const Record::Base *Record::getVirtualBase(const RecordDecl *FD) const {


        


More information about the cfe-commits mailing list