]> granicus.if.org Git - clang/commitdiff
make sizeof/alignof diagnostics highlight their operand with a sourcerange.
authorChris Lattner <sabre@nondot.org>
Fri, 25 Jul 2008 21:45:37 +0000 (21:45 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 25 Jul 2008 21:45:37 +0000 (21:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54066 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaExpr.cpp

index b87008256acb5e0afcedf777296a5d86a1cc4adb..25120acc7a9f210f3ba581e82771fc15a4f43f64 100644 (file)
@@ -846,8 +846,8 @@ private:
   QualType CheckIncrementDecrementOperand(Expr *op, SourceLocation OpLoc);   
   QualType CheckAddressOfOperand(Expr *op, SourceLocation OpLoc);
   QualType CheckIndirectionOperand(Expr *op, SourceLocation OpLoc);
-  QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation loc, 
-                                     bool isSizeof);
+  QualType CheckSizeOfAlignOfOperand(QualType type, SourceLocation OpLoc, 
+                                     const SourceRange &R, bool isSizeof);
   QualType CheckRealImagOperand(Expr *&Op, SourceLocation OpLoc);
   
   /// type checking primary expressions.
index 9ffca0870c82cdd8a92b85d08e5164f48eab13df..27e4027e68ac91b1f6977518f42ce4d0e7a70b9e 100644 (file)
@@ -587,17 +587,20 @@ Action::ExprResult Sema::ActOnParenExpr(SourceLocation L, SourceLocation R,
 /// The UsualUnaryConversions() function is *not* called by this routine.
 /// See C99 6.3.2.1p[2-4] for more details.
 QualType Sema::CheckSizeOfAlignOfOperand(QualType exprType, 
-                                         SourceLocation OpLoc, bool isSizeof) {
+                                         SourceLocation OpLoc,
+                                         const SourceRange &ExprRange,
+                                         bool isSizeof) {
   // C99 6.5.3.4p1:
   if (isa<FunctionType>(exprType) && isSizeof)
     // alignof(function) is allowed.
-    Diag(OpLoc, diag::ext_sizeof_function_type);
+    Diag(OpLoc, diag::ext_sizeof_function_type, ExprRange);
   else if (exprType->isVoidType())
-    Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof");
+    Diag(OpLoc, diag::ext_sizeof_void_type, isSizeof ? "sizeof" : "__alignof",
+         ExprRange);
   else if (exprType->isIncompleteType()) {
     Diag(OpLoc, isSizeof ? diag::err_sizeof_incomplete_type : 
                            diag::err_alignof_incomplete_type,
-         exprType.getAsString());
+         exprType.getAsString(), ExprRange);
     return QualType(); // error
   }
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
@@ -614,7 +617,8 @@ ActOnSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
   // Verify that this is a valid expression.
   QualType ArgTy = QualType::getFromOpaquePtr(Ty);
   
-  QualType resultType = CheckSizeOfAlignOfOperand(ArgTy, OpLoc, isSizeof);
+  QualType resultType =
+    CheckSizeOfAlignOfOperand(ArgTy, OpLoc, SourceRange(LPLoc, RPLoc),isSizeof);
 
   if (resultType.isNull())
     return true;
@@ -2278,10 +2282,12 @@ Action::ExprResult Sema::ActOnUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
     resultType = Context.IntTy;
     break;
   case UnaryOperator::SizeOf:
-    resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc, true);
+    resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc,
+                                           Input->getSourceRange(), true);
     break;
   case UnaryOperator::AlignOf:
-    resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc, false);
+    resultType = CheckSizeOfAlignOfOperand(Input->getType(), OpLoc,
+                                           Input->getSourceRange(), false);
     break;
   case UnaryOperator::Real:
   case UnaryOperator::Imag: