summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-01-02 21:54:09 +0000
committerChris Lattner <sabre@nondot.org>2008-01-02 21:54:09 +0000
commit7977cca8e823c5a3ee5fb39fd15e3908f24e68fc (patch)
treed45a57f99b5c2c84249c401855505f0f99eddbae /clang
parent266a2ff3acf67e2cea2830b285b5f3253ec06493 (diff)
downloadbcm5719-llvm-7977cca8e823c5a3ee5fb39fd15e3908f24e68fc.tar.gz
bcm5719-llvm-7977cca8e823c5a3ee5fb39fd15e3908f24e68fc.zip
Fix PR1895: a crash on an ugly gcc extension.
llvm-svn: 45505
Diffstat (limited to 'clang')
-rw-r--r--clang/AST/Expr.cpp10
-rw-r--r--clang/test/CodeGen/exprs.c8
2 files changed, 16 insertions, 2 deletions
diff --git a/clang/AST/Expr.cpp b/clang/AST/Expr.cpp
index 88ba6a6eff8..ed6255924b7 100644
--- a/clang/AST/Expr.cpp
+++ b/clang/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<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/clang/test/CodeGen/exprs.c b/clang/test/CodeGen/exprs.c
new file mode 100644
index 00000000000..c57817d7f4e
--- /dev/null
+++ b/clang/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);
+
OpenPOWER on IntegriCloud