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()));
       
diff --git a/test/CodeGen/exprs.c b/test/CodeGen/exprs.c
new file mode 100644
index 0000000..c57817d
--- /dev/null
+++ b/test/CodeGen/exprs.c
@@ -0,0 +1,8 @@
+// RUN: clang %s -emit-llvm
+
+// PR1895
+// sizeof function
+int zxcv(void);
+int x=sizeof(zxcv);
+int y=__alignof__(zxcv);
+