forked from OSchip/llvm-project
PR31587: Fix handling of __FUNCSIG__ in C.
Fix crash if __FUNCSIG__ is used in a function without a prototype, and use "(void)" as parameter list instead of "()" for a function with a no-parameters prototype, matching MSVC's observed behavior. llvm-svn: 291484
This commit is contained in:
parent
ba7d95d425
commit
2f63d4612f
|
@ -562,8 +562,7 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) {
|
|||
FT = dyn_cast<FunctionProtoType>(AFT);
|
||||
|
||||
if (IT == FuncSig) {
|
||||
assert(FT && "We must have a written prototype in this case.");
|
||||
switch (FT->getCallConv()) {
|
||||
switch (AFT->getCallConv()) {
|
||||
case CC_C: POut << "__cdecl "; break;
|
||||
case CC_X86StdCall: POut << "__stdcall "; break;
|
||||
case CC_X86FastCall: POut << "__fastcall "; break;
|
||||
|
@ -583,6 +582,8 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) {
|
|||
if (i) POut << ", ";
|
||||
POut << Decl->getParamDecl(i)->getType().stream(Policy);
|
||||
}
|
||||
if (!Context.getLangOpts().CPlusPlus && !Decl->getNumParams())
|
||||
POut << "void";
|
||||
|
||||
if (FT->isVariadic()) {
|
||||
if (FD->getNumParams()) POut << ", ";
|
||||
|
@ -592,7 +593,7 @@ std::string PredefinedExpr::ComputeName(IdentType IT, const Decl *CurrentDecl) {
|
|||
POut << ")";
|
||||
|
||||
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
|
||||
const FunctionType *FT = MD->getType()->castAs<FunctionType>();
|
||||
assert(FT && "We must have a written prototype in this case.");
|
||||
if (FT->isConst())
|
||||
POut << " const";
|
||||
if (FT->isVolatile())
|
||||
|
|
|
@ -1,22 +1,39 @@
|
|||
// RUN: %clang_cc1 -std=c++11 -triple i686-pc-win32 %s -fms-extensions -fno-rtti -emit-llvm -o - | FileCheck %s
|
||||
// RUN: %clang_cc1 -std=c++11 -triple i686-pc-win32 %s -fms-extensions -fno-rtti -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX
|
||||
// RUN: %clang_cc1 -x c -triple i686-pc-win32 %s -fms-extensions -fno-rtti -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-C
|
||||
|
||||
// Similar to predefined-expr.cpp, but not as exhaustive, since it's basically
|
||||
// equivalent to __PRETTY_FUNCTION__.
|
||||
|
||||
extern "C" int printf(const char *, ...);
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int printf(const char *, ...);
|
||||
|
||||
void freeFunc(int *, char) {
|
||||
void funcNoProto() {
|
||||
printf("__FUNCSIG__ %s\n\n", __FUNCSIG__);
|
||||
}
|
||||
// CHECK-C: @"\01??_C@_0BL@IHLLLCAO@void?5__cdecl?5funcNoProto?$CI?$CJ?$AA@" = linkonce_odr unnamed_addr constant [27 x i8] c"void __cdecl funcNoProto()\00"
|
||||
// CHECK-CXX: @"\01??_C@_0BL@IHLLLCAO@void?5__cdecl?5funcNoProto?$CI?$CJ?$AA@" = linkonce_odr unnamed_addr constant [27 x i8] c"void __cdecl funcNoProto()\00"
|
||||
|
||||
void funcNoParams(void) {
|
||||
printf("__FUNCSIG__ %s\n\n", __FUNCSIG__);
|
||||
}
|
||||
// CHECK-C: @"\01??_C@_0CA@GBIDFNBN@void?5__cdecl?5funcNoParams?$CIvoid?$CJ?$AA@" = linkonce_odr unnamed_addr constant [32 x i8] c"void __cdecl funcNoParams(void)\00"
|
||||
// CHECK-CXX: @"\01??_C@_0BM@GDFBOAEE@void?5__cdecl?5funcNoParams?$CI?$CJ?$AA@" = linkonce_odr unnamed_addr constant [28 x i8] c"void __cdecl funcNoParams()\00"
|
||||
|
||||
void freeFunc(int *p, char c) {
|
||||
printf("__FUNCSIG__ %s\n\n", __FUNCSIG__);
|
||||
}
|
||||
// CHECK: @"\01??_C@_0CD@KLGMNNL@void?5__cdecl?5freeFunc?$CIint?5?$CK?0?5cha@" = linkonce_odr unnamed_addr constant [{{.*}} x i8] c"void __cdecl freeFunc(int *, char)\00"
|
||||
|
||||
#ifdef __cplusplus
|
||||
struct TopLevelClass {
|
||||
void topLevelMethod(int *, char);
|
||||
};
|
||||
void TopLevelClass::topLevelMethod(int *, char) {
|
||||
printf("__FUNCSIG__ %s\n\n", __FUNCSIG__);
|
||||
}
|
||||
// CHECK: @"\01??_C@_0DL@OBHNMDP@void?5__thiscall?5TopLevelClass?3?3t@" = linkonce_odr unnamed_addr constant [{{.*}} x i8] c"void __thiscall TopLevelClass::topLevelMethod(int *, char)\00"
|
||||
// CHECK-CXX: @"\01??_C@_0DL@OBHNMDP@void?5__thiscall?5TopLevelClass?3?3t@" = linkonce_odr unnamed_addr constant [{{.*}} x i8] c"void __thiscall TopLevelClass::topLevelMethod(int *, char)\00"
|
||||
|
||||
namespace NS {
|
||||
struct NamespacedClass {
|
||||
|
@ -25,5 +42,6 @@ struct NamespacedClass {
|
|||
void NamespacedClass::namespacedMethod(int *, char) {
|
||||
printf("__FUNCSIG__ %s\n\n", __FUNCSIG__);
|
||||
}
|
||||
// CHECK: @"\01??_C@_0ED@PFDKIEBA@void?5__thiscall?5NS?3?3NamespacedCl@" = linkonce_odr unnamed_addr constant [{{.*}} x i8] c"void __thiscall NS::NamespacedClass::namespacedMethod(int *, char)\00"
|
||||
// CHECK-CXX: @"\01??_C@_0ED@PFDKIEBA@void?5__thiscall?5NS?3?3NamespacedCl@" = linkonce_odr unnamed_addr constant [{{.*}} x i8] c"void __thiscall NS::NamespacedClass::namespacedMethod(int *, char)\00"
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue