[cfe-commits] r102464 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/attr-regparm.c
Eli Friedman
eli.friedman at gmail.com
Tue Apr 27 14:07:06 PDT 2010
Author: efriedma
Date: Tue Apr 27 16:07:06 2010
New Revision: 102464
URL: http://llvm.org/viewvc/llvm-project?rev=102464&view=rev
Log:
Fix for PR6953: per gcc, regparm and noreturn affect the compatibility of
function types.
This could potentially have unexpected side-effects, so look here if there are
new regressions.
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/Sema/attr-regparm.c
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=102464&r1=102463&r2=102464&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Apr 27 16:07:06 2010
@@ -4311,21 +4311,16 @@
allLTypes = false;
if (getCanonicalType(retType) != getCanonicalType(rbase->getResultType()))
allRTypes = false;
- // FIXME: double check this
- // FIXME: should we error if lbase->getRegParmAttr() != 0 &&
- // rbase->getRegParmAttr() != 0 &&
- // lbase->getRegParmAttr() != rbase->getRegParmAttr()?
+
+ // Check misc function attributes
FunctionType::ExtInfo lbaseInfo = lbase->getExtInfo();
FunctionType::ExtInfo rbaseInfo = rbase->getExtInfo();
- unsigned RegParm = lbaseInfo.getRegParm() == 0 ? rbaseInfo.getRegParm() :
- lbaseInfo.getRegParm();
- bool NoReturn = lbaseInfo.getNoReturn() || rbaseInfo.getNoReturn();
- if (NoReturn != lbaseInfo.getNoReturn() ||
- RegParm != lbaseInfo.getRegParm())
- allLTypes = false;
- if (NoReturn != rbaseInfo.getNoReturn() ||
- RegParm != rbaseInfo.getRegParm())
- allRTypes = false;
+ // Per gcc, compatible functions must have compatible regparm and noreturn
+ // attributes.
+ unsigned RegParm = lbaseInfo.getRegParm();
+ bool NoReturn = lbaseInfo.getNoReturn();
+ if (NoReturn != rbaseInfo.getNoReturn() || RegParm != rbaseInfo.getRegParm())
+ return QualType();
CallingConv lcc = lbaseInfo.getCC();
CallingConv rcc = rbaseInfo.getCC();
// Compatible functions must have compatible calling conventions
Modified: cfe/trunk/test/Sema/attr-regparm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-regparm.c?rev=102464&r1=102463&r2=102464&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-regparm.c (original)
+++ cfe/trunk/test/Sema/attr-regparm.c Tue Apr 27 16:07:06 2010
@@ -1,7 +1,11 @@
// RUN: %clang_cc1 -triple i386-apple-darwin9 -fsyntax-only -verify %s
-__attribute((regparm(2))) int x(void);
-__attribute((regparm(1.0))) int x(void); // expected-error{{'regparm' attribute requires integer constant}}
-__attribute((regparm(-1))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
-__attribute((regparm(5))) int x(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
-__attribute((regparm(5,3))) int x(void); // expected-error{{attribute requires 1 argument(s)}}
+__attribute((regparm(2))) int a(void);
+__attribute((regparm(1.0))) int b(void); // expected-error{{'regparm' attribute requires integer constant}}
+__attribute((regparm(-1))) int c(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5))) int d(void); // expected-error{{'regparm' parameter must be between 0 and 3 inclusive}}
+__attribute((regparm(5,3))) int e(void); // expected-error{{attribute requires 1 argument(s)}}
+int f(void);
+__attribute((regparm(0))) int f(void);
+__attribute((regparm(1))) int g(void); // expected-note{{previous declaration is here}}
+__attribute((regparm(2))) int g(void); // expected-error{{conflicting types for 'g'}}
More information about the cfe-commits
mailing list