Fix PR1895: a crash on an ugly gcc extension.

llvm-svn: 45505
This commit is contained in:
Chris Lattner 2008-01-02 21:54:09 +00:00
parent 266a2ff3ac
commit 7977cca8e8
2 changed files with 16 additions and 2 deletions

View 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()));

View File

@ -0,0 +1,8 @@
// RUN: clang %s -emit-llvm
// PR1895
// sizeof function
int zxcv(void);
int x=sizeof(zxcv);
int y=__alignof__(zxcv);