]> granicus.if.org Git - clang/commitdiff
Fix PR1895: a crash on an ugly gcc extension.
authorChris Lattner <sabre@nondot.org>
Wed, 2 Jan 2008 21:54:09 +0000 (21:54 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 2 Jan 2008 21:54:09 +0000 (21:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45505 91177308-0d34-0410-b5e6-96231b3b80d8

AST/Expr.cpp
test/CodeGen/exprs.c [new file with mode: 0644]

index 88ba6a6eff83ae8d75aa789f693393de23a3f352..ed6255924b7c5d229c9e29e10b57ace49da5e8e5 100644 (file)
@@ -657,7 +657,10 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
                                               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 @@ bool Expr::isIntegerConstantExpr(llvm::APSInt &Result, ASTContext &Ctx,
       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 (file)
index 0000000..c57817d
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang %s -emit-llvm
+
+// PR1895
+// sizeof function
+int zxcv(void);
+int x=sizeof(zxcv);
+int y=__alignof__(zxcv);
+