]> granicus.if.org Git - clang/commitdiff
Dont cast away const needlessly. Found by gcc48 -Wcast-qual.
authorRoman Divacky <rdivacky@freebsd.org>
Thu, 6 Sep 2012 15:59:27 +0000 (15:59 +0000)
committerRoman Divacky <rdivacky@freebsd.org>
Thu, 6 Sep 2012 15:59:27 +0000 (15:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163325 91177308-0d34-0410-b5e6-96231b3b80d8

21 files changed:
include/clang/Basic/OnDiskHashTable.h
lib/AST/RecordLayoutBuilder.cpp
lib/AST/StmtDumper.cpp
lib/Analysis/ReachableCode.cpp
lib/Analysis/ThreadSafety.cpp
lib/Basic/SourceManager.cpp
lib/CodeGen/CGDebugInfo.cpp
lib/CodeGen/CGObjCMac.cpp
lib/CodeGen/CodeGenModule.cpp
lib/Lex/HeaderMap.cpp
lib/Lex/Lexer.cpp
lib/Lex/PTHLexer.cpp
lib/Sema/SemaChecking.cpp
lib/Sema/SemaDecl.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaType.cpp
lib/StaticAnalyzer/Core/Environment.cpp
lib/StaticAnalyzer/Core/ExprEngine.cpp
lib/StaticAnalyzer/Core/MemRegion.cpp
lib/StaticAnalyzer/Core/RegionStore.cpp
utils/TableGen/OptParserEmitter.cpp

index 66109e7b3c0969eca2185fe22837e0450bae7cc3..cc9ca9f2ec37fa60c02c2b8ef5b3bfe910826121 100644 (file)
@@ -101,7 +101,7 @@ inline uint64_t ReadUnalignedLE64(const unsigned char *&Data) {
 inline uint32_t ReadLE32(const unsigned char *&Data) {
   // Hosts that directly support little-endian 32-bit loads can just
   // use them.  Big-endian hosts need a bswap.
-  uint32_t V = *((uint32_t*)Data);
+  uint32_t V = *((const uint32_t*)Data);
   if (llvm::sys::isBigEndianHost())
     V = llvm::ByteSwap_32(V);
   Data += 4;
index fba23fb468a04113bcb90aa41be1a8bbb013bac8..6581df40468265a3e920509d3314834e6e2d65e1 100644 (file)
@@ -2522,8 +2522,8 @@ ASTContext::getObjCLayout(const ObjCInterfaceDecl *D,
   assert(D && D->isThisDeclarationADefinition() && "Invalid interface decl!");
 
   // Look up this layout, if already laid out, return what we have.
-  ObjCContainerDecl *Key =
-    Impl ? (ObjCContainerDecl*) Impl : (ObjCContainerDecl*) D;
+  const ObjCContainerDecl *Key =
+    Impl ? (const ObjCContainerDecl*) Impl : (const ObjCContainerDecl*) D;
   if (const ASTRecordLayout *Entry = ObjCLayouts[Key])
     return *Entry;
 
index 962e35269c18ad72567a418a5dbc6e83abbd0e73..3695bf3430ba7ac9a23bede206ae763b3d8d4134 100644 (file)
@@ -98,7 +98,7 @@ namespace  {
     void DumpStmt(const Stmt *Node) {
       Indent();
       OS << "(" << Node->getStmtClassName()
-         << " " << (void*)Node;
+         << " " << (const void*)Node;
       DumpSourceRange(Node);
     }
     void DumpValueKind(ExprValueKind K) {
index bb63e2c184909b13b131a11bd42461de8e50f124..11f2ebe9ad2d371daf98c8e35b04d0d9abf2c288 100644 (file)
@@ -112,8 +112,8 @@ const Stmt *DeadCodeScan::findDeadCode(const clang::CFGBlock *Block) {
 
 static int SrcCmp(const void *p1, const void *p2) {
   return
-    ((std::pair<const CFGBlock *, const Stmt *>*) p2)->second->getLocStart() <
-    ((std::pair<const CFGBlock *, const Stmt *>*) p1)->second->getLocStart();
+    ((const std::pair<const CFGBlock *, const Stmt *>*) p2)->second->getLocStart() <
+    ((const std::pair<const CFGBlock *, const Stmt *>*) p1)->second->getLocStart();
 }
 
 unsigned DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
index 90c407ac656cfcde4109370b22fc6960e612ffb3..b3e97afd90d6c6728f51f6657139c3fc36f59442 100644 (file)
@@ -953,7 +953,7 @@ public:
       return;
     }
     Dec->printName(llvm::errs());
-    llvm::errs() << "." << i << " " << ((void*) Dec);
+    llvm::errs() << "." << i << " " << ((const void*) Dec);
   }
 
   /// Dumps an ASCII representation of the variable map to llvm::errs()
index 9ec247429945c063644394bfade77a8328390fd7..65bd601eeaf09b322b856498d16b0f1fa85d4ab5 100644 (file)
@@ -1112,7 +1112,7 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
 
     // Scan 16 byte chunks for '\r' and '\n'. Ignore '\0'.
     while (NextBuf+16 <= End) {
-      __m128i Chunk = *(__m128i*)NextBuf;
+      const __m128i Chunk = *(const __m128i*)NextBuf;
       __m128i Cmp = _mm_or_si128(_mm_cmpeq_epi8(Chunk, CRs),
                                  _mm_cmpeq_epi8(Chunk, LFs));
       unsigned Mask = _mm_movemask_epi8(Cmp);
index d6c39c610fcc3193eaa9389b8d5be18ef8986415..d1ccfe6944149720473a65de4c4ae9a820915126 100644 (file)
@@ -157,7 +157,7 @@ StringRef CGDebugInfo::getObjCMethodName(const ObjCMethodDecl *OMD) {
       OS << OID->getName();
   } else if (const ObjCCategoryImplDecl *OCD = 
              dyn_cast<const ObjCCategoryImplDecl>(DC)){
-      OS << ((NamedDecl *)OCD)->getIdentifier()->getNameStart() << '(' <<
+      OS << ((const NamedDecl *)OCD)->getIdentifier()->getNameStart() << '(' <<
           OCD->getIdentifier()->getNameStart() << ')';
   }
   OS << ' ' << OMD->getSelector().getAsString() << ']';
index ef802a3ed0ca515551ca7d4c5a94bf4659b79341..9a61e34ab2ebf304b92895460adb589a92fc9413 100644 (file)
@@ -1860,7 +1860,7 @@ llvm::Constant *CGObjCCommonMac::BuildGCBlockLayout(CodeGenModule &CGM,
   llvm::Constant *C = BuildIvarLayoutBitmap(BitMap);
   if (CGM.getLangOpts().ObjCGCBitmapPrint) {
     printf("\n block variable layout for block: ");
-    const unsigned char *s = (unsigned char*)BitMap.c_str();
+    const unsigned char *s = (const unsigned char*)BitMap.c_str();
     for (unsigned i = 0, e = BitMap.size(); i < e; i++)
       if (!(s[i] & 0xf0))
         printf("0x0%x%s", s[i], s[i] != 0 ? ", " : "");
@@ -4187,7 +4187,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
     printf("\n%s ivar layout for class '%s': ",
            ForStrongLayout ? "strong" : "weak",
            OMD->getClassInterface()->getName().data());
-    const unsigned char *s = (unsigned char*)BitMap.c_str();
+    const unsigned char *s = (const unsigned char*)BitMap.c_str();
     for (unsigned i = 0, e = BitMap.size(); i < e; i++)
       if (!(s[i] & 0xf0))
         printf("0x0%x%s", s[i], s[i] != 0 ? ", " : "");
index 554aa1cb4cde06d7800a41cc28bde5dddf03599c..87e74547c2091010075f5097265ed1666d1565ca 100644 (file)
@@ -1995,7 +1995,7 @@ GetConstantCFStringEntry(llvm::StringMap<llvm::Constant*> &Map,
   IsUTF16 = true;
 
   SmallVector<UTF16, 128> ToBuf(NumBytes + 1); // +1 for ending nulls.
-  const UTF8 *FromPtr = (UTF8 *)String.data();
+  const UTF8 *FromPtr = (const UTF8 *)String.data();
   UTF16 *ToPtr = &ToBuf[0];
 
   (void)ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes,
index bbfc1df76fddd268f61c1718390508398785c8de..7dc0491392ccb76721d26d1506f7085ce00858f5 100644 (file)
@@ -144,7 +144,7 @@ HMapBucket HeaderMap::getBucket(unsigned BucketNo) const {
                                         sizeof(HMapHeader));
 
   const HMapBucket *BucketPtr = BucketArray+BucketNo;
-  if ((char*)(BucketPtr+1) > FileBuffer->getBufferEnd()) {
+  if ((const char*)(BucketPtr+1) > FileBuffer->getBufferEnd()) {
     Result.Prefix = 0;
     Result.Suffix = 0;
     return Result;  // Invalid buffer, corrupt hmap.
index e214ece281b165c68a27258d1b03e63ac6424a98..ebb3b6a9a28655d1297e520d408870404d1ebdde 100644 (file)
@@ -2179,7 +2179,8 @@ bool Lexer::SkipBlockComment(Token &Result, const char *CurPtr) {
 #ifdef __SSE2__
       __m128i Slashes = _mm_set1_epi8('/');
       while (CurPtr+16 <= BufferEnd) {
-        int cmp = _mm_movemask_epi8(_mm_cmpeq_epi8(*(__m128i*)CurPtr, Slashes));
+        int cmp = _mm_movemask_epi8(_mm_cmpeq_epi8(*(const __m128i*)CurPtr,
+                                    Slashes));
         if (cmp != 0) {
           // Adjust the pointer to point directly after the first slash. It's
           // not necessary to set C here, it will be overwritten at the end of
index 67738e907516705f4ba95a986aa404ebcab58c87..bb6e73cc75f0828edf6e24eb5a3ef57ae7b68691 100644 (file)
@@ -448,8 +448,8 @@ PTHManager *PTHManager::Create(const std::string &file,
 
   // Get the buffer ranges and check if there are at least three 32-bit
   // words at the end of the file.
-  const unsigned char *BufBeg = (unsigned char*)File->getBufferStart();
-  const unsigned char *BufEnd = (unsigned char*)File->getBufferEnd();
+  const unsigned char *BufBeg = (const unsigned char*)File->getBufferStart();
+  const unsigned char *BufEnd = (const unsigned char*)File->getBufferEnd();
 
   // Check the prologue of the file.
   if ((BufEnd - BufBeg) < (signed)(sizeof("cfe-pth") + 4 + 4) ||
index 5d54ca361d57995cd32ff9a5a7dda8e1e1e4ba9e..9bddfdc6f0b920b0a2e9e242c3534da6c66fe9d3 100644 (file)
@@ -1268,7 +1268,7 @@ bool Sema::CheckObjCString(Expr *Arg) {
     StringRef String = Literal->getString();
     unsigned NumBytes = String.size();
     SmallVector<UTF16, 128> ToBuf(NumBytes);
-    const UTF8 *FromPtr = (UTF8 *)String.data();
+    const UTF8 *FromPtr = (const UTF8 *)String.data();
     UTF16 *ToPtr = &ToBuf[0];
     
     ConversionResult Result = ConvertUTF8toUTF16(&FromPtr, FromPtr + NumBytes,
index d3ef15c432d66acc84d8cca54bca60b51fb36a35..711ea4c7293a616183cae07f2f58566641c1abcd 100644 (file)
@@ -10182,7 +10182,7 @@ void Sema::ActOnFields(Scope* S,
                 //   class subobject has more than one final overrider the
                 //   program is ill-formed.
                 Diag(Record->getLocation(), diag::err_multiple_final_overriders)
-                  << (NamedDecl *)M->first << Record;
+                  << (const NamedDecl *)M->first << Record;
                 Diag(M->first->getLocation(), 
                      diag::note_overridden_virtual_function);
                 for (OverridingMethods::overriding_iterator 
@@ -10190,7 +10190,7 @@ void Sema::ActOnFields(Scope* S,
                        OMEnd = SO->second.end();
                      OM != OMEnd; ++OM)
                   Diag(OM->Method->getLocation(), diag::note_final_overrider)
-                    << (NamedDecl *)M->first << OM->Method->getParent();
+                    << (const NamedDecl *)M->first << OM->Method->getParent();
                 
                 Record->setInvalidDecl();
               }
index f4d63faaafabe886301bf80ec1ae449c8bc6a1a3..e800a6a7a486d13e374c0c56f73a59c0d43d78db 100644 (file)
@@ -536,7 +536,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
 
   // Check then save referenced protocols.
   if (NumProtoRefs) {
-    IDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
+    IDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs,
                            ProtoLocs, Context);
     IDecl->setEndOfDefinitionLoc(EndProtoLoc);
   }
@@ -678,7 +678,7 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
 
   if (!err && NumProtoRefs ) {
     /// Check then save referenced protocols.
-    PDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
+    PDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs,
                            ProtoLocs, Context);
   }
 
@@ -845,11 +845,11 @@ ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
   CurContext->addDecl(CDecl);
 
   if (NumProtoRefs) {
-    CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, 
+    CDecl->setProtocolList((ObjCProtocolDecl*const*)ProtoRefs, NumProtoRefs, 
                            ProtoLocs, Context);
     // Protocols in the class extension belong to the class.
     if (CDecl->IsClassExtension())
-     IDecl->mergeClassExtensionProtocolList((ObjCProtocolDecl**)ProtoRefs, 
+     IDecl->mergeClassExtensionProtocolList((ObjCProtocolDecl*const*)ProtoRefs, 
                                             NumProtoRefs, Context); 
   }
 
index 82dccfa5f442f9993ddd38782aa1e4b5c2206229..39d367f07930753da8d82d3a49327afaceaddc94 100644 (file)
@@ -636,7 +636,7 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
     // "<proto1,proto2>" is an objc qualified ID with a missing id.
     if (DeclSpec::ProtocolQualifierListTy PQ = DS.getProtocolQualifiers()) {
       Result = Context.getObjCObjectType(Context.ObjCBuiltinIdTy,
-                                         (ObjCProtocolDecl**)PQ,
+                                         (ObjCProtocolDecl*const*)PQ,
                                          DS.getNumProtocolQualifiers());
       Result = Context.getObjCObjectPointerType(Result);
       break;
@@ -795,18 +795,18 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
 
         if (DS.getNumProtocolQualifiers())
           Result = Context.getObjCObjectType(Result,
-                                             (ObjCProtocolDecl**) PQ,
+                                             (ObjCProtocolDecl*const*) PQ,
                                              DS.getNumProtocolQualifiers());
       } else if (Result->isObjCIdType()) {
         // id<protocol-list>
         Result = Context.getObjCObjectType(Context.ObjCBuiltinIdTy,
-                                           (ObjCProtocolDecl**) PQ,
+                                           (ObjCProtocolDecl*const*) PQ,
                                            DS.getNumProtocolQualifiers());
         Result = Context.getObjCObjectPointerType(Result);
       } else if (Result->isObjCClassType()) {
         // Class<protocol-list>
         Result = Context.getObjCObjectType(Context.ObjCBuiltinClassTy,
-                                           (ObjCProtocolDecl**) PQ,
+                                           (ObjCProtocolDecl*const*) PQ,
                                            DS.getNumProtocolQualifiers());
         Result = Context.getObjCObjectPointerType(Result);
       } else {
index 534f37858c7895add03edcf24ad52ceed8ad2bc1..a8c2da76424f6b00266a305b07a639069c6a86f2 100644 (file)
@@ -289,7 +289,8 @@ void Environment::printAux(raw_ostream &Out, bool printLocations,
       S = (Stmt*) (((uintptr_t) S) & ((uintptr_t) ~0x1));
     }
     
-    Out << " (" << (void*) En.getLocationContext() << ',' << (void*) S << ") ";
+    Out << " (" << (const void*) En.getLocationContext() << ','
+      << (const void*) S << ") ";
     LangOptions LO; // FIXME.
     S->printPretty(Out, 0, PrintingPolicy(LO));
     Out << " : " << I.getData();
index 4225c67dc704a791d17f7b2150b97caf6d6a187f..b95a3fedb712891790e274a544e8865b8757b7d0 100644 (file)
@@ -1935,7 +1935,7 @@ struct DOTGraphTraits<ExplodedNode*> :
         if (StmtPoint *L = dyn_cast<StmtPoint>(&Loc)) {
           const Stmt *S = L->getStmt();
 
-          Out << S->getStmtClassName() << ' ' << (void*) S << ' ';
+          Out << S->getStmtClassName() << ' ' << (const void*) S << ' ';
           LangOptions LO; // FIXME.
           S->printPretty(Out, 0, PrintingPolicy(LO));
           printLocation(Out, S->getLocStart());
@@ -2041,8 +2041,8 @@ struct DOTGraphTraits<ExplodedNode*> :
     }
 
     ProgramStateRef state = N->getState();
-    Out << "\\|StateID: " << (void*) state.getPtr()
-        << " NodeID: " << (void*) N << "\\|";
+    Out << "\\|StateID: " << (const void*) state.getPtr()
+        << " NodeID: " << (const void*) N << "\\|";
     state->printDOT(Out);
 
     Out << "\\l";    
index 62e602a7e1e158ff974db6c395ce2fde12fe45cc..b29327efcfc95f58a1318099e8bf389b62b0351b 100644 (file)
@@ -444,7 +444,7 @@ void MemRegion::dumpToStream(raw_ostream &os) const {
 }
 
 void AllocaRegion::dumpToStream(raw_ostream &os) const {
-  os << "alloca{" << (void*) Ex << ',' << Cnt << '}';
+  os << "alloca{" << (const void*) Ex << ',' << Cnt << '}';
 }
 
 void FunctionTextRegion::dumpToStream(raw_ostream &os) const {
@@ -452,7 +452,7 @@ void FunctionTextRegion::dumpToStream(raw_ostream &os) const {
 }
 
 void BlockTextRegion::dumpToStream(raw_ostream &os) const {
-  os << "block_code{" << (void*) this << '}';
+  os << "block_code{" << (const void*) this << '}';
 }
 
 void BlockDataRegion::dumpToStream(raw_ostream &os) const {
@@ -461,12 +461,12 @@ void BlockDataRegion::dumpToStream(raw_ostream &os) const {
 
 void CompoundLiteralRegion::dumpToStream(raw_ostream &os) const {
   // FIXME: More elaborate pretty-printing.
-  os << "{ " << (void*) CL <<  " }";
+  os << "{ " << (const void*) CL <<  " }";
 }
 
 void CXXTempObjectRegion::dumpToStream(raw_ostream &os) const {
   os << "temp_object{" << getValueType().getAsString() << ','
-     << (void*) Ex << '}';
+     << (const void*) Ex << '}';
 }
 
 void CXXBaseObjectRegion::dumpToStream(raw_ostream &os) const {
index c2cdb2af4350accf3acf89579b7833f86c6a7488..628b790f1f45a9146e1637f6b823e2d74d806955 100644 (file)
@@ -783,7 +783,7 @@ RegionBindings RegionStoreManager::invalidateGlobalRegion(MemRegion::Kind K,
   // Bind the globals memory space to a new symbol that we will use to derive
   // the bindings for all globals.
   const GlobalsSpaceRegion *GS = MRMgr.getGlobalsRegion(K);
-  SVal V = svalBuilder.conjureSymbolVal(/* SymbolTag = */ (void*) GS, Ex, LCtx,
+  SVal V = svalBuilder.conjureSymbolVal(/* SymbolTag = */ (const void*) GS, Ex, LCtx,
                                         /* type does not matter */ Ctx.IntTy,
                                         Count);
 
index b0431a9be16b715ce45619f66e2061eef91347bd..c9492ad719444b7e7364a2cb5feb2274810ce0cf 100644 (file)
@@ -32,8 +32,8 @@ static int StrCmpOptionName(const char *A, const char *B) {
 }
 
 static int CompareOptionRecords(const void *Av, const void *Bv) {
-  const Record *A = *(Record**) Av;
-  const Record *B = *(Record**) Bv;
+  const Record *A = *(const Record*const*) Av;
+  const Record *B = *(const Record*const*) Bv;
 
   // Sentinel options precede all others and are only ordered by precedence.
   bool ASent = A->getValueAsDef("Kind")->getValueAsBit("Sentinel");