From: Nicolas Lesser Date: Fri, 3 Aug 2018 01:24:52 +0000 (+0000) Subject: Fold two cast plus a cast in a loop into a variable. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7133123731b658bd5b55b9c1cca4088b49a268f;p=clang Fold two cast plus a cast in a loop into a variable. This avoids to recast `Record` multiple times. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338801 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b92d76ad42..c49125edcc 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -15602,6 +15602,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, } RecordDecl *Record = dyn_cast(EnclosingDecl); + CXXRecordDecl *CXXRecord = dyn_cast(EnclosingDecl); // Start counting up the number of named members; make sure to include // members of anonymous structs and unions in the total. @@ -15691,9 +15692,8 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, // virtual bases after the derived members. This would make a flexible // array member declared at the end of an object not adjacent to the end // of the type. - if (CXXRecordDecl *RD = dyn_cast(Record)) - if (RD->getNumVBases() != 0) - Diag(FD->getLocation(), diag::err_flexible_array_virtual_base) + if (CXXRecord && CXXRecord->getNumVBases() != 0) + Diag(FD->getLocation(), diag::err_flexible_array_virtual_base) << FD->getDeclName() << Record->getTagKind(); if (!getLangOpts().C99) Diag(FD->getLocation(), diag::ext_c99_flexible_array_member) @@ -15831,7 +15831,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, // Okay, we successfully defined 'Record'. if (Record) { bool Completed = false; - if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { + if (CXXRecord) { if (!CXXRecord->isInvalidDecl()) { // Set access bits correctly on the directly-declared conversions. for (CXXRecordDecl::conversion_iterator @@ -15902,7 +15902,7 @@ void Sema::ActOnFields(Scope *S, SourceLocation RecLoc, Decl *EnclosingDecl, ProcessDeclAttributeList(S, Record, Attrs); // We may have deferred checking for a deleted destructor. Check now. - if (CXXRecordDecl *CXXRecord = dyn_cast(Record)) { + if (CXXRecord) { auto *Dtor = CXXRecord->getDestructor(); if (Dtor && Dtor->isImplicit() && ShouldDeleteSpecialMember(Dtor, CXXDestructor)) {