Skip to content

Commit bc6d0f1

Browse files
PiJouleststellar
authored andcommitted
[Sema] Add MacroQualified case for FunctionTypeUnwrapper
This is a fix for PR43315. An assertion error is hit for this minimal example: ``` //clang -cc1 -triple x86_64-- -S tstVMStructRC-min.cpp int (a b)(); // Assertion `Chunk.Kind == DeclaratorChunk::Function' failed. ``` This is because we do not cover the case in the FunctionTypeUnwrapper where it receives a MacroQualifiedType. We have not run into this earlier because this is a unique case where the __attribute__ contains both __cdecl__ and __regparm__ (in that order), and we are compiling for x86_64. Changing the architecture or the order of __cdecl__ and __regparm__ does not raise the assertion. Differential Revision: https://reviews.llvm.org/D67992 (cherry picked from commit e278c13)
1 parent 2cec4d0 commit bc6d0f1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6325,7 +6325,8 @@ namespace {
63256325
Pointer,
63266326
BlockPointer,
63276327
Reference,
6328-
MemberPointer
6328+
MemberPointer,
6329+
MacroQualified,
63296330
};
63306331

63316332
QualType Original;
@@ -6356,6 +6357,9 @@ namespace {
63566357
} else if (isa<AttributedType>(Ty)) {
63576358
T = cast<AttributedType>(Ty)->getEquivalentType();
63586359
Stack.push_back(Attributed);
6360+
} else if (isa<MacroQualifiedType>(Ty)) {
6361+
T = cast<MacroQualifiedType>(Ty)->getUnderlyingType();
6362+
Stack.push_back(MacroQualified);
63596363
} else {
63606364
const Type *DTy = Ty->getUnqualifiedDesugaredType();
63616365
if (Ty == DTy) {
@@ -6412,6 +6416,9 @@ namespace {
64126416
return C.getParenType(New);
64136417
}
64146418

6419+
case MacroQualified:
6420+
return wrap(C, cast<MacroQualifiedType>(Old)->getUnderlyingType(), I);
6421+
64156422
case Pointer: {
64166423
QualType New = wrap(C, cast<PointerType>(Old)->getPointeeType(), I);
64176424
return C.getPointerType(New);

clang/test/Frontend/macro_defined_type.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ void Func() {
1919
struct A {
2020
_LIBCPP_FLOAT_ABI int operator()() throw(); // expected-warning{{'pcs' calling convention is not supported for this target}}
2121
};
22+
23+
// Added test for fix for PR43315
24+
#define a __attribute__((__cdecl__, __regparm__(0)))
25+
int(a b)();

0 commit comments

Comments
 (0)