r214408 - Delay check for prototype on __fastcall functions until after MergeFunctionDecl.
Nico Weber
nicolasweber at gmx.de
Thu Jul 31 10:19:18 PDT 2014
Author: nico
Date: Thu Jul 31 12:19:18 2014
New Revision: 214408
URL: http://llvm.org/viewvc/llvm-project?rev=214408&view=rev
Log:
Delay check for prototype on __fastcall functions until after MergeFunctionDecl.
In C, it is only known after merging decls if a function with 0 arguments has
a prototype. Fixes PR20386, see that for more notes.
Added:
cfe/trunk/test/Sema/decl-microsoft-call-conv.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=214408&r1=214407&r2=214408&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jul 31 12:19:18 2014
@@ -7821,6 +7821,18 @@ bool Sema::CheckFunctionDeclaration(Scop
}
// Semantic checking for this function declaration (in isolation).
+
+ // Diagnose the use of X86 fastcall on unprototyped functions.
+ QualType NewQType = Context.getCanonicalType(NewFD->getType());
+ const FunctionType *NewType = cast<FunctionType>(NewQType);
+ if (isa<FunctionNoProtoType>(NewType)) {
+ FunctionType::ExtInfo NewTypeInfo = NewType->getExtInfo();
+ if (NewTypeInfo.getCC() == CC_X86FastCall)
+ Diag(NewFD->getLocation(), diag::err_cconv_knr)
+ << FunctionType::getNameForCallConv(CC_X86FastCall);
+ // TODO: Also diagnose unprototyped stdcall functions?
+ }
+
if (getLangOpts().CPlusPlus) {
// C++-specific checks.
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(NewFD)) {
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=214408&r1=214407&r2=214408&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Jul 31 12:19:18 2014
@@ -4564,23 +4564,12 @@ static bool handleFunctionTypeAttr(TypeP
}
}
- // Diagnose the use of X86 fastcall on unprototyped functions.
- if (CC == CC_X86FastCall) {
- if (isa<FunctionNoProtoType>(fn)) {
- S.Diag(attr.getLoc(), diag::err_cconv_knr)
- << FunctionType::getNameForCallConv(CC);
- attr.setInvalid();
- return true;
- }
-
- // Also diagnose fastcall with regparm.
- if (fn->getHasRegParm()) {
- S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible)
- << "regparm"
- << FunctionType::getNameForCallConv(CC);
- attr.setInvalid();
- return true;
- }
+ // Also diagnose fastcall with regparm.
+ if (CC == CC_X86FastCall && fn->getHasRegParm()) {
+ S.Diag(attr.getLoc(), diag::err_attributes_are_not_compatible)
+ << "regparm" << FunctionType::getNameForCallConv(CC_X86FastCall);
+ attr.setInvalid();
+ return true;
}
// Modify the CC from the wrapped function type, wrap it all back, and then
Added: cfe/trunk/test/Sema/decl-microsoft-call-conv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/decl-microsoft-call-conv.c?rev=214408&view=auto
==============================================================================
--- cfe/trunk/test/Sema/decl-microsoft-call-conv.c (added)
+++ cfe/trunk/test/Sema/decl-microsoft-call-conv.c Thu Jul 31 12:19:18 2014
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple i686-pc-win32 -verify %s
+
+// It's important that this is a .c file.
+
+// This is fine, as CrcGenerateTable() has a prototype.
+void __fastcall CrcGenerateTable(void);
+void __fastcall CrcGenerateTable() {}
+
+void __fastcall CrcGenerateTableNoProto() {} // expected-error{{function with no prototype cannot use fastcall calling convention}}
More information about the cfe-commits
mailing list