[cfe-commits] r45505 - in /cfe/trunk: AST/Expr.cpp test/CodeGen/exprs.c

Chris Lattner sabre at nondot.org
Wed Jan 2 13:54:09 PST 2008


Author: lattner
Date: Wed Jan  2 15:54:09 2008
New Revision: 45505

URL: http://llvm.org/viewvc/llvm-project?rev=45505&view=rev
Log:
Fix PR1895: a crash on an ugly gcc extension.

Added:
    cfe/trunk/test/CodeGen/exprs.c
Modified:
    cfe/trunk/AST/Expr.cpp

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=45505&r1=45504&r2=45505&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Wed Jan  2 15:54:09 2008
@@ -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()));
       

Added: cfe/trunk/test/CodeGen/exprs.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/exprs.c?rev=45505&view=auto

==============================================================================
--- cfe/trunk/test/CodeGen/exprs.c (added)
+++ cfe/trunk/test/CodeGen/exprs.c Wed Jan  2 15:54:09 2008
@@ -0,0 +1,8 @@
+// RUN: clang %s -emit-llvm
+
+// PR1895
+// sizeof function
+int zxcv(void);
+int x=sizeof(zxcv);
+int y=__alignof__(zxcv);
+





More information about the cfe-commits mailing list