Skip to content

Commit

Permalink
[Sema] Add MacroQualified case for FunctionTypeUnwrapper
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
PiJoules authored and tstellar committed Nov 13, 2019
1 parent 2cec4d0 commit bc6d0f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion clang/lib/Sema/SemaType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6325,7 +6325,8 @@ namespace {
Pointer,
BlockPointer,
Reference,
MemberPointer
MemberPointer,
MacroQualified,
};

QualType Original;
Expand Down Expand Up @@ -6356,6 +6357,9 @@ namespace {
} else if (isa<AttributedType>(Ty)) {
T = cast<AttributedType>(Ty)->getEquivalentType();
Stack.push_back(Attributed);
} else if (isa<MacroQualifiedType>(Ty)) {
T = cast<MacroQualifiedType>(Ty)->getUnderlyingType();
Stack.push_back(MacroQualified);
} else {
const Type *DTy = Ty->getUnqualifiedDesugaredType();
if (Ty == DTy) {
Expand Down Expand Up @@ -6412,6 +6416,9 @@ namespace {
return C.getParenType(New);
}

case MacroQualified:
return wrap(C, cast<MacroQualifiedType>(Old)->getUnderlyingType(), I);

case Pointer: {
QualType New = wrap(C, cast<PointerType>(Old)->getPointeeType(), I);
return C.getPointerType(New);
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Frontend/macro_defined_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ void Func() {
struct A {
_LIBCPP_FLOAT_ABI int operator()() throw(); // expected-warning{{'pcs' calling convention is not supported for this target}}
};

// Added test for fix for PR43315
#define a __attribute__((__cdecl__, __regparm__(0)))
int(a b)();

0 comments on commit bc6d0f1

Please sign in to comment.