r325633 - [NFC] In Multiversion Check function, switch to return Diag

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 14:25:28 PST 2018


Author: erichkeane
Date: Tue Feb 20 14:25:28 2018
New Revision: 325633

URL: http://llvm.org/viewvc/llvm-project?rev=325633&view=rev
Log:
[NFC] In Multiversion Check function, switch to return Diag

This function did a lot of 'Diag, return true' stuff.  This resulted in needing
to introduce scopes in quite a few places.  This patch replaces useages of a
single "S.Diag" followed by return true with simply "return S.Diag".

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=325633&r1=325632&r2=325633&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb 20 14:25:28 2018
@@ -9225,62 +9225,49 @@ static bool CheckMultiVersionAdditionalR
     return true;
   }
 
-  if (std::distance(NewFD->attr_begin(), NewFD->attr_end()) != 1) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_no_other_attrs);
-    return true;
-  }
-
-  if (NewFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
-        << FuncTemplates;
-    return true;
-  }
+  if (std::distance(NewFD->attr_begin(), NewFD->attr_end()) != 1)
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_no_other_attrs);
 
+  if (NewFD->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate)
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
+           << FuncTemplates;
 
   if (const auto *NewCXXFD = dyn_cast<CXXMethodDecl>(NewFD)) {
-    if (NewCXXFD->isVirtual()) {
-      S.Diag(NewCXXFD->getLocation(), diag::err_multiversion_doesnt_support)
-          << VirtFuncs;
-      return true;
-    }
-
-    if (const auto *NewCXXCtor = dyn_cast<CXXConstructorDecl>(NewFD)) {
-      S.Diag(NewCXXCtor->getLocation(), diag::err_multiversion_doesnt_support)
-          << Constructors;
-      return true;
-    }
-
-    if (const auto *NewCXXDtor = dyn_cast<CXXDestructorDecl>(NewFD)) {
-      S.Diag(NewCXXDtor->getLocation(), diag::err_multiversion_doesnt_support)
-          << Destructors;
-      return true;
-    }
-  }
-
-  if (NewFD->isDeleted()) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
-      << DeletedFuncs;
-  }
-  if (NewFD->isDefaulted()) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
-      << DefaultedFuncs;
-  }
+    if (NewCXXFD->isVirtual())
+      return S.Diag(NewCXXFD->getLocation(),
+                    diag::err_multiversion_doesnt_support)
+             << VirtFuncs;
+
+    if (const auto *NewCXXCtor = dyn_cast<CXXConstructorDecl>(NewFD))
+      return S.Diag(NewCXXCtor->getLocation(),
+                    diag::err_multiversion_doesnt_support)
+             << Constructors;
+
+    if (const auto *NewCXXDtor = dyn_cast<CXXDestructorDecl>(NewFD))
+      return S.Diag(NewCXXDtor->getLocation(),
+                    diag::err_multiversion_doesnt_support)
+             << Destructors;
+  }
+
+  if (NewFD->isDeleted())
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
+           << DeletedFuncs;
+
+  if (NewFD->isDefaulted())
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
+           << DefaultedFuncs;
 
   QualType NewQType = S.getASTContext().getCanonicalType(NewFD->getType());
   const auto *NewType = cast<FunctionType>(NewQType);
   QualType NewReturnType = NewType->getReturnType();
 
-  if (NewReturnType->isUndeducedType()) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
-        << DeducedReturn;
-    return true;
-  }
+  if (NewReturnType->isUndeducedType())
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_doesnt_support)
+           << DeducedReturn;
 
   // Only allow transition to MultiVersion if it hasn't been used.
-  if (OldFD && CausesMV && OldFD->isUsed(false)) {
-    S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
-    return true;
-  }
+  if (OldFD && CausesMV && OldFD->isUsed(false))
+    return S.Diag(NewFD->getLocation(), diag::err_multiversion_after_used);
 
   // Ensure the return type is identical.
   if (OldFD) {
@@ -9289,38 +9276,31 @@ static bool CheckMultiVersionAdditionalR
     FunctionType::ExtInfo OldTypeInfo = OldType->getExtInfo();
     FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo();
 
-    if (OldTypeInfo.getCC() != NewTypeInfo.getCC()) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff) << CallingConv;
-      return true;
-    }
+    if (OldTypeInfo.getCC() != NewTypeInfo.getCC())
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << CallingConv;
 
     QualType OldReturnType = OldType->getReturnType();
 
-    if (OldReturnType != NewReturnType) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff) << ReturnType;
-      return true;
-    }
-
-    if (OldFD->isConstexpr() != NewFD->isConstexpr()) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
-          << ConstexprSpec;
-      return true;
-    }
-
-    if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified()) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff) << InlineSpec;
-      return true;
-    }
-
-    if (OldFD->getStorageClass() != NewFD->getStorageClass()) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff) << StorageClass;
-      return true;
-    }
-
-    if (OldFD->isExternC() != NewFD->isExternC()) {
-      S.Diag(NewFD->getLocation(), diag::err_multiversion_diff) << Linkage;
-      return true;
-    }
+    if (OldReturnType != NewReturnType)
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << ReturnType;
+
+    if (OldFD->isConstexpr() != NewFD->isConstexpr())
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << ConstexprSpec;
+
+    if (OldFD->isInlineSpecified() != NewFD->isInlineSpecified())
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << InlineSpec;
+
+    if (OldFD->getStorageClass() != NewFD->getStorageClass())
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << StorageClass;
+
+    if (OldFD->isExternC() != NewFD->isExternC())
+      return S.Diag(NewFD->getLocation(), diag::err_multiversion_diff)
+             << Linkage;
 
     if (S.CheckEquivalentExceptionSpec(
             OldFD->getType()->getAs<FunctionProtoType>(), OldFD->getLocation(),




More information about the cfe-commits mailing list