]> granicus.if.org Git - clang/commitdiff
Added an assert to IntegerLiteral to ensure that the integer type passed in has the...
authorRichard Trieu <rtrieu@google.com>
Mon, 2 May 2011 23:00:27 +0000 (23:00 +0000)
committerRichard Trieu <rtrieu@google.com>
Mon, 2 May 2011 23:00:27 +0000 (23:00 +0000)
Changed the integer type that range-based for-loops used.  Switched to pointer difference type, which satisfies the new assert in IntegerLiteral.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130739 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/Expr.h
lib/Sema/SemaStmt.cpp

index 5f2d144eb544e6a7f9e3cba5ba5a06e87062b1ca..b7458df15c33af06085dff71e9938370433ba774 100644 (file)
@@ -1018,13 +1018,18 @@ public:
            false),
       Loc(l) {
     assert(type->isIntegerType() && "Illegal type in IntegerLiteral");
+    assert(V.getBitWidth() == C.getIntWidth(type) &&
+           "Integer type is not the correct size for constant.");
     setValue(C, V);
   }
 
-  // type should be IntTy, LongTy, LongLongTy, UnsignedIntTy, UnsignedLongTy,
-  // or UnsignedLongLongTy
+  /// \brief Returns a new integer literal with value 'V' and type 'type'.
+  /// \param type - either IntTy, LongTy, LongLongTy, UnsignedIntTy,
+  /// UnsignedLongTy, or UnsignedLongLongTy which should match the size of V
+  /// \param V - the value that the returned integer literal contains.
   static IntegerLiteral *Create(ASTContext &C, const llvm::APInt &V,
                                 QualType type, SourceLocation l);
+  /// \brief Returns a new empty integer literal.
   static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);
 
   llvm::APInt getValue() const { return Num.getValue(); }
index 65cea7a69d61a66b030363cef255225c0af4bd89..a60fcb7097c2bbc987a6fe3d90ebdb6d27092093 100644 (file)
@@ -1252,7 +1252,8 @@ Sema::BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation ColonLoc,
       ExprResult BoundExpr;
       if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(UnqAT))
         BoundExpr = Owned(IntegerLiteral::Create(Context, CAT->getSize(),
-                                                 Context.IntTy, RangeLoc));
+                                                 Context.getPointerDiffType(),
+                                                 RangeLoc));
       else if (const VariableArrayType *VAT =
                dyn_cast<VariableArrayType>(UnqAT))
         BoundExpr = VAT->getSizeExpr();