r192308 - Tighten diagnostics for calling conventions on variadic functions
Hans Wennborg
hans at hanshq.net
Wed Oct 9 11:10:25 PDT 2013
Author: hans
Date: Wed Oct 9 13:10:25 2013
New Revision: 192308
URL: http://llvm.org/viewvc/llvm-project?rev=192308&view=rev
Log:
Tighten diagnostics for calling conventions on variadic functions
Follow-up from r192240.
This makes it an error to use callee-cleanup conventions on variadic
functions, except for __fastcall and __stdcall, which we ignore with
a warning for GCC and MSVC compatibility.
Differential Revision: http://llvm-reviews.chandlerc.com/D1870
Modified:
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/CodeGen/microsoft-call-conv.c
cfe/trunk/test/Sema/callingconv.c
cfe/trunk/test/Sema/mrtd.c
cfe/trunk/test/SemaCXX/calling-conv-compat.cpp
Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Wed Oct 9 13:10:25 2013
@@ -220,6 +220,19 @@ namespace clang {
CC_IntelOclBicc // __attribute__((intel_ocl_bicc))
};
+ /// \brief Checks whether the given calling convention is callee-cleanup.
+ inline bool isCalleeCleanup(CallingConv CC) {
+ switch (CC) {
+ case CC_X86StdCall:
+ case CC_X86FastCall:
+ case CC_X86ThisCall:
+ case CC_X86Pascal:
+ return true;
+ default:
+ return false;
+ }
+ }
+
/// \brief The storage duration for an object (per C++ [basic.stc]).
enum StorageDuration {
SD_FullExpression, ///< Full-expression storage duration (for temporaries).
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Oct 9 13:10:25 2013
@@ -4542,22 +4542,26 @@ static bool handleFunctionTypeAttr(TypeP
}
}
- // Diagnose the use of X86 fastcall on varargs or unprototyped functions.
- if (CC == CC_X86FastCall) {
- if (isa<FunctionNoProtoType>(fn)) {
- S.Diag(attr.getLoc(), diag::err_cconv_knr)
- << FunctionType::getNameForCallConv(CC);
+ // Diagnose use of callee-cleanup calling convention on variadic functions.
+ if (isCalleeCleanup(CC)) {
+ const FunctionProtoType *FnP = dyn_cast<FunctionProtoType>(fn);
+ if (FnP && FnP->isVariadic()) {
+ unsigned DiagID = diag::err_cconv_varargs;
+ // stdcall and fastcall are ignored with a warning for GCC and MS
+ // compatibility.
+ if (CC == CC_X86StdCall || CC == CC_X86FastCall)
+ DiagID = diag::warn_cconv_varargs;
+
+ S.Diag(attr.getLoc(), DiagID) << FunctionType::getNameForCallConv(CC);
attr.setInvalid();
return true;
}
+ }
- const FunctionProtoType *FnP = cast<FunctionProtoType>(fn);
- if (FnP->isVariadic()) {
- // In MS compatibility mode, this is just a warning.
- const LangOptions &L = S.getLangOpts();
- unsigned DiagID = L.MicrosoftMode ? diag::warn_cconv_varargs
- : diag::err_cconv_varargs;
- S.Diag(attr.getLoc(), DiagID)
+ // 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;
Modified: cfe/trunk/test/CodeGen/microsoft-call-conv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/microsoft-call-conv.c?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/microsoft-call-conv.c (original)
+++ cfe/trunk/test/CodeGen/microsoft-call-conv.c Wed Oct 9 13:10:25 2013
@@ -1,5 +1,6 @@
// RUN: %clang_cc1 -triple i386-pc-linux -emit-llvm < %s | FileCheck %s
-// RUN: %clang_cc1 -triple i386-pc-linux -emit-llvm -fms-compatibility -DWIN < %s | FileCheck --check-prefix=WIN %s
+// RUN: %clang_cc1 -triple i386-pc-linux -emit-llvm -mrtd < %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-pc-linux -emit-llvm -fms-compatibility < %s
void __fastcall f1(void);
void __stdcall f2(void);
@@ -51,9 +52,9 @@ void f8(void) {
}
// PR12535
-#ifdef WIN
void __fastcall f9(int x, int y) {};
// WIN: define x86_fastcallcc void @f9({{.*}})
void __fastcall f10(int x, ...) {};
// WIN: define void @f10({{.*}})
-#endif
+void __stdcall f11(int x, ...) {};
+// WIN: define void @f11({{.*}})
Modified: cfe/trunk/test/Sema/callingconv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/callingconv.c?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/test/Sema/callingconv.c (original)
+++ cfe/trunk/test/Sema/callingconv.c Wed Oct 9 13:10:25 2013
@@ -16,13 +16,12 @@ void __attribute__((fastcall)) test0() {
void __attribute__((fastcall)) test1(void) {
}
-#ifdef WIN
void __attribute__((fastcall)) test2(int a, ...) { // expected-warning {{fastcall calling convention ignored on variadic function}}
}
-#else
-void __attribute__((fastcall)) test2(int a, ...) { // expected-error {{variadic function cannot use fastcall calling convention}}
+void __attribute__((stdcall)) test3(int a, ...) { // expected-warning {{stdcall calling convention ignored on variadic function}}
+}
+void __attribute__((thiscall)) test4(int a, ...) { // expected-error {{variadic function cannot use thiscall calling convention}}
}
-#endif
void __attribute__((cdecl)) ctest0() {}
Modified: cfe/trunk/test/Sema/mrtd.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/mrtd.c?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/test/Sema/mrtd.c (original)
+++ cfe/trunk/test/Sema/mrtd.c Wed Oct 9 13:10:25 2013
@@ -12,8 +12,7 @@ void __attribute__((stdcall)) nonvariadi
void nonvariadic2(int a, int b, int c);
void __attribute__((stdcall)) nonvariadic2(int a, int b, int c) { }
-// expected-note at +2 {{previous declaration is here}}
-// expected-error at +2 {{function declared 'stdcall' here was previously declared without calling convention}}
+// expected-warning at +2 {{stdcall calling convention ignored on variadic function}}
void variadic(int a, ...);
void __attribute__((stdcall)) variadic(int a, ...);
@@ -34,7 +33,6 @@ __attribute__((cdecl)) extern void (*b)(
extern void (*c)(int, int);
__attribute__((stdcall)) extern void (*c)(int, int);
-// expected-note at +2 {{previous definition is here}}
-// expected-error at +2 {{redefinition of 'd' with a different type: 'void ((*))(int, ...) __attribute__((stdcall))' vs 'void (*)(int, ...)'}}
+// expected-warning at +2 {{stdcall calling convention ignored on variadic function}}
extern void (*d)(int, ...);
__attribute__((stdcall)) extern void (*d)(int, ...);
Modified: cfe/trunk/test/SemaCXX/calling-conv-compat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/calling-conv-compat.cpp?rev=192308&r1=192307&r2=192308&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/calling-conv-compat.cpp (original)
+++ cfe/trunk/test/SemaCXX/calling-conv-compat.cpp Wed Oct 9 13:10:25 2013
@@ -248,7 +248,7 @@ namespace Variadic {
struct A {
void member_default(int, ...);
void __cdecl member_cdecl(int, ...);
- void __thiscall member_thiscall(int, ...);
+ void __thiscall member_thiscall(int, ...); // expected-error {{variadic function cannot use thiscall calling convention}}
};
struct B : public A {
More information about the cfe-commits
mailing list