[cfe-commits] r54066 - in /cfe/trunk/lib/Sema: Sema.h SemaExpr.cpp

Chris Lattner sabre at nondot.org
Fri Jul 25 14:45:38 PDT 2008


Author: lattner
Date: Fri Jul 25 16:45:37 2008
New Revision: 54066

URL: http://llvm.org/viewvc/llvm-project?rev=54066&view=rev
Log:
make sizeof/alignof diagnostics highlight their operand with a sourcerange.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=54066&r1=54065&r2=54066&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Jul 25 16:45:37 2008
@@ -846,8 +846,8 @@
   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.

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=54066&r1=54065&r2=54066&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jul 25 16:45:37 2008
@@ -587,17 +587,20 @@
 /// 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 @@
   // 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 @@
     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:





More information about the cfe-commits mailing list