Fix PR1895: a crash on an ugly gcc extension.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45505 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Expr.cpp b/AST/Expr.cpp
index 88ba6a6..ed62559 100644
--- a/AST/Expr.cpp
+++ b/AST/Expr.cpp
@@ -657,7 +657,10 @@
Exp->getOperatorLoc())));
// Get information about the size or align.
- if (Exp->getOpcode() == UnaryOperator::AlignOf) {
+ if (Exp->getSubExpr()->getType()->isFunctionType()) {
+ // GCC extension: sizeof(function) = 1.
+ Result = Exp->getOpcode() == UnaryOperator::AlignOf ? 4 : 1;
+ } else if (Exp->getOpcode() == UnaryOperator::AlignOf) {
Result = Ctx.getTypeAlign(Exp->getSubExpr()->getType(),
Exp->getOperatorLoc());
} else {
@@ -700,7 +703,10 @@
static_cast<uint32_t>(Ctx.getTypeSize(getType(), Exp->getOperatorLoc())));
// Get information about the size or align.
- if (Exp->isSizeOf()) {
+ if (Exp->getArgumentType()->isFunctionType()) {
+ // GCC extension: sizeof(function) = 1.
+ Result = Exp->isSizeOf() ? 1 : 4;
+ } else if (Exp->isSizeOf()) {
unsigned CharSize =
Ctx.Target.getCharWidth(Ctx.getFullLoc(Exp->getOperatorLoc()));