From 8cc246c9a68c783a5b90d2e8b8927521cb3a49b7 Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 15 Dec 2010 01:06:38 +0000 Subject: [PATCH] Function types are compatible (in the C sense) if their regparms are identical. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121821 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index a6b0861f02..b51ad2ba8e 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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, -- 2.40.0