]> granicus.if.org Git - clang/commitdiff
Function types are compatible (in the C sense) if their regparms are identical.
authorJohn McCall <rjmccall@apple.com>
Wed, 15 Dec 2010 01:06:38 +0000 (01:06 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 15 Dec 2010 01:06:38 +0000 (01:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121821 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ASTContext.cpp

index a6b0861f02142558f56f4d572c60768e98116f90..b51ad2ba8e37900cf66d42e8ba976791ee188a0c 100644 (file)
@@ -4806,8 +4806,8 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
     retType = mergeTypes(rbase->getResultType(), lbase->getResultType(), true,
                          Unqualified);
   else
-   retType = mergeTypes(lbase->getResultType(), rbase->getResultType(),
-                        false, Unqualified);
+    retType = mergeTypes(lbase->getResultType(), rbase->getResultType(), false,
+                         Unqualified);
   if (retType.isNull()) return QualType();
   
   if (Unqualified)
@@ -4824,28 +4824,33 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
     allLTypes = false;
   if (getCanonicalType(retType) != RRetType)
     allRTypes = false;
+
   // FIXME: double check this
   // FIXME: should we error if lbase->getRegParmAttr() != 0 &&
   //                           rbase->getRegParmAttr() != 0 &&
   //                           lbase->getRegParmAttr() != rbase->getRegParmAttr()?
   FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo();
   FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo();
-  unsigned RegParm = lbaseInfo.getRegParm() == 0 ? rbaseInfo.getRegParm() :
-      lbaseInfo.getRegParm();
+
+  // Compatible functions must have compatible calling conventions
+  if (!isSameCallConv(lbaseInfo.getCC(), rbaseInfo.getCC()))
+    return QualType();
+
+  // Regparm is part of the calling convention.
+  if (lbaseInfo.getRegParm() != rbaseInfo.getRegParm())
+    return QualType();
+
+  // It's noreturn if either type is.
+  // FIXME: some uses, e.g. conditional exprs, really want this to be 'both'.
   bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn();
-  if (NoReturn != lbaseInfo.getNoReturn() ||
-      RegParm != lbaseInfo.getRegParm())
+  if (NoReturn != lbaseInfo.getNoReturn())
     allLTypes = false;
-  if (NoReturn != rbaseInfo.getNoReturn() ||
-      RegParm != rbaseInfo.getRegParm())
+  if (NoReturn != rbaseInfo.getNoReturn())
     allRTypes = false;
-  CallingConv lcc = lbaseInfo.getCC();
-  CallingConv rcc = rbaseInfo.getCC();
-  // Compatible functions must have compatible calling conventions
-  if (!isSameCallConv(lcc, rcc))
-    return QualType();
 
-  FunctionType::ExtInfo einfo = FunctionType::ExtInfo(NoReturn, RegParm, lcc);
+  FunctionType::ExtInfo einfo(NoReturn,
+                              lbaseInfo.getRegParm(),
+                              lbaseInfo.getCC());
 
   if (lproto && rproto) { // two C99 style function prototypes
     assert(!lproto->hasExceptionSpec() && !rproto->hasExceptionSpec() &&
@@ -4933,8 +4938,7 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs,
 
   if (allLTypes) return lhs;
   if (allRTypes) return rhs;
-  FunctionType::ExtInfo Info(NoReturn, RegParm, lcc);
-  return getFunctionNoProtoType(retType, Info);
+  return getFunctionNoProtoType(retType, einfo);
 }
 
 QualType ASTContext::mergeTypes(QualType LHS, QualType RHS,