From efdd1574e3cca00ef0410aee8b7ee36eda5a2f71 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 2 Jan 2008 21:54:09 +0000 Subject: [PATCH] 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 --- AST/Expr.cpp | 10 ++++++++-- test/CodeGen/exprs.c | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/exprs.c diff --git a/AST/Expr.cpp b/AST/Expr.cpp index 88ba6a6eff..ed6255924b 100644 --- a/AST/Expr.cpp +++ b/AST/Expr.cpp @@ -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(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 0000000000..c57817d7f4 --- /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); + -- 2.50.1