[cfe-commits] r138993 - /cfe/trunk/lib/Sema/SemaExpr.cpp
Richard Trieu
rtrieu at google.com
Thu Sep 1 19:15:37 PDT 2011
Author: rtrieu
Date: Thu Sep 1 21:15:37 2011
New Revision: 138993
URL: http://llvm.org/viewvc/llvm-project?rev=138993&view=rev
Log:
Pull out incomplete pointer type checking code, used from arithmetic checking functions, into its own function.
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=138993&r1=138992&r2=138993&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 1 21:15:37 2011
@@ -5793,6 +5793,24 @@
<< Pointer->getSourceRange();
}
+/// \brief Warn if Operand is incomplete pointer type
+///
+/// \returns True if pointer has incomplete type
+static bool checkArithmeticIncompletePointerType(Sema &S, SourceLocation Loc,
+ Expr *Operand) {
+ if ((Operand->getType()->isPointerType() &&
+ !Operand->getType()->isDependentType()) ||
+ Operand->getType()->isObjCObjectPointerType()) {
+ QualType PointeeTy = Operand->getType()->getPointeeType();
+ if (S.RequireCompleteType(
+ Loc, PointeeTy,
+ S.PDiag(diag::err_typecheck_arithmetic_incomplete_type)
+ << PointeeTy << Operand->getSourceRange()))
+ return true;
+ }
+ return false;
+}
+
/// \brief Check the validity of an arithmetic pointer operand.
///
/// If the operand has pointer type, this code will check for pointer types
@@ -5815,16 +5833,7 @@
return !S.getLangOptions().CPlusPlus;
}
- if ((Operand->getType()->isPointerType() &&
- !Operand->getType()->isDependentType()) ||
- Operand->getType()->isObjCObjectPointerType()) {
- QualType PointeeTy = Operand->getType()->getPointeeType();
- if (S.RequireCompleteType(
- Loc, PointeeTy,
- S.PDiag(diag::err_typecheck_arithmetic_incomplete_type)
- << PointeeTy << Operand->getSourceRange()))
- return false;
- }
+ if (checkArithmeticIncompletePointerType(S, Loc, Operand)) return false;
return true;
}
@@ -5869,20 +5878,9 @@
return !S.getLangOptions().CPlusPlus;
}
- Expr *Operands[] = { LHS, RHS };
- for (unsigned i = 0; i < 2; ++i) {
- Expr *Operand = Operands[i];
- if ((Operand->getType()->isPointerType() &&
- !Operand->getType()->isDependentType()) ||
- Operand->getType()->isObjCObjectPointerType()) {
- QualType PointeeTy = Operand->getType()->getPointeeType();
- if (S.RequireCompleteType(
- Loc, PointeeTy,
- S.PDiag(diag::err_typecheck_arithmetic_incomplete_type)
- << PointeeTy << Operand->getSourceRange()))
- return false;
- }
- }
+ if (checkArithmeticIncompletePointerType(S, Loc, LHS)) return false;
+ if (checkArithmeticIncompletePointerType(S, Loc, RHS)) return false;
+
return true;
}
More information about the cfe-commits
mailing list