[cfe-commits] Patch - Fix range-based for-loop so that it forms proper integer literals

Richard Smith richard at metafoo.co.uk
Mon May 2 13:17:31 PDT 2011


Hi Richard,

On Thu, April 28, 2011 23:37, Richard Trieu wrote:
> Okay, I fixed the concerns you raised.  Is this better?

Yes, thanks! A couple of things inline:

Index: include/clang/AST/Expr.h
===================================================================
--- include/clang/AST/Expr.h        (revision 129825)
+++ include/clang/AST/Expr.h        (working copy)
@@ -977,13 +977,18 @@
            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 interger literal.


Typo.


   static IntegerLiteral *Create(ASTContext &C, EmptyShell Empty);

   llvm::APInt getValue() const { return Num.getValue(); }
Index: lib/Sema/SemaStmt.cpp
===================================================================
--- lib/Sema/SemaStmt.cpp        (revision 129825)
+++ lib/Sema/SemaStmt.cpp        (working copy)
@@ -1257,7 +1257,8 @@
       ExprResult BoundExpr;
       if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(UnqAT))
         BoundExpr = Owned(IntegerLiteral::Create(Context, CAT->getSize(),
-                                                 Context.IntTy, RangeLoc));
+                                                
Context.getPointerDiffType(),
+                                                 RangeLoc));


This should be the pointer difference type for the right address space.
You could add an accessor to ASTContext to get the corresponding type for
the array's address space from the target info (perhaps
ASTContext::getArrayBoundType(QualType ArrayType)).


       else if (const VariableArrayType *VAT =
                dyn_cast<VariableArrayType>(UnqAT))
         BoundExpr = VAT->getSizeExpr();


Thanks again for looking into this!
Richard





More information about the cfe-commits mailing list