[cfe-commits] r125773 - in /cfe/trunk: include/clang/Sema/Sema.h lib/Sema/SemaChecking.cpp

Chandler Carruth chandlerc at gmail.com
Thu Feb 17 12:55:08 PST 2011


Author: chandlerc
Date: Thu Feb 17 14:55:08 2011
New Revision: 125773

URL: http://llvm.org/viewvc/llvm-project?rev=125773&view=rev
Log:
Clean up the style of this function to match the conventions in the rest
of Clang, and reflows the code a bit to make it easier to read.

Modified:
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=125773&r1=125772&r2=125773&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Feb 17 14:55:08 2011
@@ -5063,7 +5063,7 @@
                                                 unsigned ByteNo) const;
 
 private:  
-  void CheckArrayAccess(const ArraySubscriptExpr *ae);
+  void CheckArrayAccess(const ArraySubscriptExpr *E);
   bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall);
   bool CheckBlockCall(NamedDecl *NDecl, CallExpr *TheCall);
 

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=125773&r1=125772&r2=125773&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu Feb 17 14:55:08 2011
@@ -3094,41 +3094,40 @@
     << TRange << Op->getSourceRange();
 }
 
-void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *ae) {
-  const DeclRefExpr *dr =
-    dyn_cast<DeclRefExpr>(ae->getBase()->IgnoreParenImpCasts());
-  if (!dr)
+void Sema::CheckArrayAccess(const clang::ArraySubscriptExpr *E) {
+  const DeclRefExpr *DRE =
+    dyn_cast<DeclRefExpr>(E->getBase()->IgnoreParenImpCasts());
+  if (!DRE)
     return;
-  const VarDecl *vd = dyn_cast<VarDecl>(dr->getDecl());
-  if (!vd)
+  const VarDecl *Variable = dyn_cast<VarDecl>(DRE->getDecl());
+  if (!Variable)
     return;
-  const ConstantArrayType *cat = Context.getAsConstantArrayType(vd->getType());
-  if (!cat)
+  const ConstantArrayType *ArrayTy =
+    Context.getAsConstantArrayType(Variable->getType());
+  if (!ArrayTy)
     return;
-  const Expr *idx = ae->getIdx();
-  if (idx->isValueDependent())
+  const Expr *IndexExpr = E->getIdx();
+  if (IndexExpr->isValueDependent())
     return;
-  llvm::APSInt result;
-  if (!idx->isIntegerConstantExpr(result, Context))
+  llvm::APSInt index;
+  if (!IndexExpr->isIntegerConstantExpr(index, Context))
     return;
 
-  if (result.slt(0)) {
-    Diag(ae->getBase()->getLocStart(), diag::warn_array_index_precedes_bounds)
-      << result.toString(10, true) << idx->getSourceRange();
-  }
-  else {
-    const llvm::APInt &size = cat->getSize();
-    if (size.getBitWidth() > result.getBitWidth())
-      result = result.sext(size.getBitWidth());
-    if (result.sge(size)) {
-      Diag(ae->getBase()->getLocStart(), diag::warn_array_index_exceeds_bounds)
-        << result.toString(10, true) << size.toString(10, true)
-        << idx->getSourceRange();
-    }
-    else
+  if (!index.isNegative()) {
+    const llvm::APInt &size = ArrayTy->getSize();
+    if (size.getBitWidth() > index.getBitWidth())
+      index = index.sext(size.getBitWidth());
+    if (index.slt(size))
       return;
+
+    Diag(E->getBase()->getLocStart(), diag::warn_array_index_exceeds_bounds)
+      << index.toString(10, true) << size.toString(10, true)
+      << IndexExpr->getSourceRange();
+  } else {
+    Diag(E->getBase()->getLocStart(), diag::warn_array_index_precedes_bounds)
+      << index.toString(10, true) << IndexExpr->getSourceRange();
   }
-  Diag(vd->getLocStart(), diag::note_array_index_out_of_bounds)
-    << vd->getDeclName();
+  Diag(Variable->getLocStart(), diag::note_array_index_out_of_bounds)
+    << Variable->getDeclName();
 }
 





More information about the cfe-commits mailing list