[cfe-commits] r59799 - /cfe/trunk/lib/Sema/SemaExpr.cpp
Chris Lattner
sabre at nondot.org
Thu Nov 20 23:05:49 PST 2008
Author: lattner
Date: Fri Nov 21 01:05:48 2008
New Revision: 59799
URL: http://llvm.org/viewvc/llvm-project?rev=59799&view=rev
Log:
Change CheckIncrementDecrementOperand to test for common cases first
and fall through better.
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=59799&r1=59798&r2=59799&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Nov 21 01:05:48 2008
@@ -2634,36 +2634,39 @@
/// CheckIncrementDecrementOperand - unlike most "Check" methods, this routine
/// doesn't need to call UsualUnaryConversions or UsualArithmeticConversions.
-QualType Sema::CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc) {
- QualType resType = op->getType();
- assert(!resType.isNull() && "no type for increment/decrement expression");
+QualType Sema::CheckIncrementDecrementOperand(Expr *Op, SourceLocation OpLoc) {
+ QualType ResType = Op->getType();
+ assert(!ResType.isNull() && "no type for increment/decrement expression");
// C99 6.5.2.4p1: We allow complex as a GCC extension.
- if (const PointerType *pt = resType->getAsPointerType()) {
- if (pt->getPointeeType()->isVoidType()) {
- Diag(OpLoc, diag::ext_gnu_void_ptr) << op->getSourceRange();
- } else if (!pt->getPointeeType()->isObjectType()) {
- // C99 6.5.2.4p2, 6.5.6p2
+ if (ResType->isRealType()) {
+ // OK!
+ } else if (const PointerType *PT = ResType->getAsPointerType()) {
+ // C99 6.5.2.4p2, 6.5.6p2
+ if (PT->getPointeeType()->isObjectType()) {
+ // Pointer to object is ok!
+ } else if (PT->getPointeeType()->isVoidType()) {
+ // Pointer to void is extension.
+ Diag(OpLoc, diag::ext_gnu_void_ptr) << Op->getSourceRange();
+ } else {
Diag(OpLoc, diag::err_typecheck_arithmetic_incomplete_type)
- << resType.getAsString() << op->getSourceRange();
- return QualType();
- }
- } else if (!resType->isRealType()) {
- if (resType->isComplexType())
- // C99 does not support ++/-- on complex types.
- Diag(OpLoc, diag::ext_integer_increment_complex)
- << resType.getAsString() << op->getSourceRange();
- else {
- Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
- << resType.getAsString() << op->getSourceRange();
+ << ResType.getAsString() << Op->getSourceRange();
return QualType();
}
+ } else if (ResType->isComplexType()) {
+ // C99 does not support ++/-- on complex types, we allow as an extension.
+ Diag(OpLoc, diag::ext_integer_increment_complex)
+ << ResType.getAsString() << Op->getSourceRange();
+ } else {
+ Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement)
+ << ResType.getAsString() << Op->getSourceRange();
+ return QualType();
}
// At this point, we know we have a real, complex or pointer type.
// Now make sure the operand is a modifiable lvalue.
- if (CheckForModifiableLvalue(op, OpLoc, *this))
+ if (CheckForModifiableLvalue(Op, OpLoc, *this))
return QualType();
- return resType;
+ return ResType;
}
/// getPrimaryDecl - Helper function for CheckAddressOfOperand().
More information about the cfe-commits
mailing list