Fix warnings found by gcc-4.6, from -Wunused-but-set-variable and
-Wint-to-pointer-cast.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123719 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/SourceLocation.h b/include/clang/Basic/SourceLocation.h
index 74f762b..605c4bb 100644
--- a/include/clang/Basic/SourceLocation.h
+++ b/include/clang/Basic/SourceLocation.h
@@ -130,6 +130,22 @@
return X;
}
+ /// getPtrEncoding - When a SourceLocation itself cannot be used, this returns
+ /// an (opaque) pointer encoding for it. This should only be passed
+ /// to SourceLocation::getFromPtrEncoding, it should not be inspected
+ /// directly.
+ void* getPtrEncoding() const {
+ // Double cast to avoid a warning "cast to pointer from integer of different
+ // size".
+ return (void*)(uintptr_t)getRawEncoding();
+ }
+
+ /// getFromPtrEncoding - Turn a pointer encoding of a SourceLocation object
+ /// into a real SourceLocation.
+ static SourceLocation getFromPtrEncoding(void *Encoding) {
+ return getFromRawEncoding((unsigned)(uintptr_t)Encoding);
+ }
+
void print(llvm::raw_ostream &OS, const SourceManager &SM) const;
void dump(const SourceManager &SM) const;
};
@@ -369,7 +385,7 @@
class PointerLikeTypeTraits<clang::SourceLocation> {
public:
static inline void *getAsVoidPointer(clang::SourceLocation L) {
- return (void*)L.getRawEncoding();
+ return L.getPtrEncoding();
}
static inline clang::SourceLocation getFromVoidPointer(void *P) {
return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P);
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 4c6d841..e6af820 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -2081,7 +2081,6 @@
const FunctionType *FnType
= cast<FunctionType>(cast<PointerType>(CalleeType)->getPointeeType());
- QualType ResultType = FnType->getResultType();
CallArgList Args;
EmitCallArgs(Args, dyn_cast<FunctionProtoType>(FnType), ArgBeg, ArgEnd);
@@ -2108,4 +2107,3 @@
return MakeAddrLValue(AddV, MPT->getPointeeType());
}
-
diff --git a/lib/CodeGen/CGExprComplex.cpp b/lib/CodeGen/CGExprComplex.cpp
index 5c4d0a5..bdd2454 100644
--- a/lib/CodeGen/CGExprComplex.cpp
+++ b/lib/CodeGen/CGExprComplex.cpp
@@ -538,7 +538,7 @@
ComplexPairTy &Val) {
TestAndClearIgnoreReal();
TestAndClearIgnoreImag();
- QualType LHSTy = E->getLHS()->getType(), RHSTy = E->getRHS()->getType();
+ QualType LHSTy = E->getLHS()->getType();
BinOpInfo OpInfo;
diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp
index c7e0837..c7f834a 100644
--- a/lib/CodeGen/CGObjC.cpp
+++ b/lib/CodeGen/CGObjC.cpp
@@ -434,7 +434,6 @@
for (unsigned I = 0, E = IvarInitializers.size(); I != E; ++I) {
CXXCtorInitializer *IvarInit = IvarInitializers[I];
FieldDecl *Field = IvarInit->getAnyMember();
- QualType FieldType = Field->getType();
ObjCIvarDecl *Ivar = cast<ObjCIvarDecl>(Field);
LValue LV = EmitLValueForIvar(TypeOfSelfObject(),
LoadObjCSelf(), Ivar, 0);
@@ -860,5 +859,3 @@
}
CGObjCRuntime::~CGObjCRuntime() {}
-
-
diff --git a/lib/CodeGen/ItaniumCXXABI.cpp b/lib/CodeGen/ItaniumCXXABI.cpp
index 554d240..edc03b1 100644
--- a/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/lib/CodeGen/ItaniumCXXABI.cpp
@@ -349,11 +349,11 @@
bool DerivedToBase =
E->getCastKind() == CK_DerivedToBaseMemberPointer;
- const CXXRecordDecl *BaseDecl, *DerivedDecl;
+ const CXXRecordDecl *DerivedDecl;
if (DerivedToBase)
- DerivedDecl = SrcDecl, BaseDecl = DestDecl;
+ DerivedDecl = SrcDecl;
else
- BaseDecl = SrcDecl, DerivedDecl = DestDecl;
+ DerivedDecl = DestDecl;
llvm::Constant *Adj =
CGF.CGM.GetNonVirtualBaseClassOffset(DerivedDecl,
@@ -1000,7 +1000,6 @@
// The cookie size is always 2 * sizeof(size_t).
CookieSize = 2 * SizeSize;
- CharUnits NumElementsOffset = CookieSize - SizeSize;
// The allocated pointer is the input ptr, minus that amount.
AllocPtr = CGF.Builder.CreateBitCast(Ptr, CharPtrTy);
diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp
index 8e334c3..355ba02 100644
--- a/lib/Parse/ParseDecl.cpp
+++ b/lib/Parse/ParseDecl.cpp
@@ -1724,7 +1724,6 @@
}
// Parse the common specifier-qualifiers-list piece.
- SourceLocation DSStart = Tok.getLocation();
ParseSpecifierQualifierList(DS);
// If there are no declarators, this is a free-standing declaration
diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp
index fcd629f..20e2b8b 100644
--- a/lib/Parse/ParseDeclCXX.cpp
+++ b/lib/Parse/ParseDeclCXX.cpp
@@ -1443,7 +1443,6 @@
return;
}
- SourceLocation DSStart = Tok.getLocation();
// decl-specifier-seq:
// Parse the common declaration-specifiers piece.
ParsingDeclSpec DS(*this, TemplateDiags);
@@ -1931,7 +1930,7 @@
bool &hasAnyExceptionSpec) {
assert(Tok.is(tok::kw_throw) && "expected throw");
- SourceLocation ThrowLoc = ConsumeToken();
+ ConsumeToken();
if (!Tok.is(tok::l_paren)) {
return Diag(Tok, diag::err_expected_lparen_after) << "throw";
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index 7133b61..f48b7a5 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -566,7 +566,6 @@
ParenParseOption ParenExprType =
(isUnaryExpression && !getLang().CPlusPlus)? CompoundLiteral : CastExpr;
ParsedType CastTy;
- SourceLocation LParenLoc = Tok.getLocation();
SourceLocation RParenLoc;
{
@@ -641,7 +640,7 @@
(Actions.getTypeName(II, ILoc, getCurScope()) ||
// Allow the base to be 'super' if in an objc-method.
(&II == Ident_super && getCurScope()->isInObjcMethodScope()))) {
- SourceLocation DotLoc = ConsumeToken();
+ ConsumeToken();
if (Tok.isNot(tok::identifier)) {
Diag(Tok, diag::err_expected_property_name);
diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp
index aa638bb..8b12650 100644
--- a/lib/Parse/ParseExprCXX.cpp
+++ b/lib/Parse/ParseExprCXX.cpp
@@ -824,7 +824,7 @@
// '=' assignment-expression
if (isTokenEqualOrMistypedEqualEqual(
diag::err_invalid_equalequal_after_declarator)) {
- SourceLocation EqualLoc = ConsumeToken();
+ ConsumeToken();
ExprResult AssignExpr(ParseAssignmentExpression());
if (!AssignExpr.isInvalid())
Actions.AddInitializerToDecl(DeclOut, AssignExpr.take());
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index 2d293c5..af53d7d 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -150,7 +150,9 @@
SourceLocation nameLoc = ConsumeToken();
if (Tok.is(tok::l_paren) &&
!isKnownToBeTypeSpecifier(GetLookAheadToken(1))) { // we have a category.
- SourceLocation lparenLoc = ConsumeParen();
+ // TODO(dgregor): Use the return value from the next line to provide better
+ // recovery.
+ ConsumeParen();
SourceLocation categoryLoc, rparenLoc;
IdentifierInfo *categoryId = 0;
if (Tok.is(tok::code_completion)) {
@@ -1298,7 +1300,7 @@
if (Tok.is(tok::l_paren)) {
// we have a category implementation.
- SourceLocation lparenLoc = ConsumeParen();
+ ConsumeParen();
SourceLocation categoryLoc, rparenLoc;
IdentifierInfo *categoryId = 0;
@@ -1418,7 +1420,7 @@
Decl *Parser::ParseObjCPropertySynthesize(SourceLocation atLoc) {
assert(Tok.isObjCAtKeyword(tok::objc_synthesize) &&
"ParseObjCPropertyDynamic(): Expected '@synthesize'");
- SourceLocation loc = ConsumeToken(); // consume synthesize
+ ConsumeToken(); // consume synthesize
while (true) {
if (Tok.is(tok::code_completion)) {
@@ -1473,7 +1475,7 @@
Decl *Parser::ParseObjCPropertyDynamic(SourceLocation atLoc) {
assert(Tok.isObjCAtKeyword(tok::objc_dynamic) &&
"ParseObjCPropertyDynamic(): Expected '@dynamic'");
- SourceLocation loc = ConsumeToken(); // consume dynamic
+ ConsumeToken(); // consume dynamic
while (true) {
if (Tok.is(tok::code_completion)) {
Actions.CodeCompleteObjCPropertyDefinition(getCurScope(), ObjCImpDecl);
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index 113b266..3a6f80d 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -545,12 +545,9 @@
Decl *&DeclResult,
SourceLocation Loc,
bool ConvertToBoolean) {
- bool ParseError = false;
-
SourceLocation LParenLoc = ConsumeParen();
if (getLang().CPlusPlus)
- ParseError = ParseCXXCondition(ExprResult, DeclResult, Loc,
- ConvertToBoolean);
+ ParseCXXCondition(ExprResult, DeclResult, Loc, ConvertToBoolean);
else {
ExprResult = ParseExpression();
DeclResult = 0;
diff --git a/lib/Parse/ParseTemplate.cpp b/lib/Parse/ParseTemplate.cpp
index 93f5c9b..05cdd5c 100644
--- a/lib/Parse/ParseTemplate.cpp
+++ b/lib/Parse/ParseTemplate.cpp
@@ -531,7 +531,7 @@
<< PP.getSpelling(Tok);
return 0;
}
- SourceLocation ClassLoc = ConsumeToken();
+ ConsumeToken();
// Parse the ellipsis, if given.
SourceLocation EllipsisLoc;
@@ -595,8 +595,6 @@
/// parameter-declaration
Decl *
Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
- SourceLocation StartLoc = Tok.getLocation();
-
// Parse the declaration-specifiers (i.e., the type).
// FIXME: The type should probably be restricted in some way... Not all
// declarators (parts of declarators?) are accepted for parameters.
diff --git a/lib/Parse/ParseTentative.cpp b/lib/Parse/ParseTentative.cpp
index c6e6784..bec201c 100644
--- a/lib/Parse/ParseTentative.cpp
+++ b/lib/Parse/ParseTentative.cpp
@@ -111,10 +111,7 @@
// We need tentative parsing...
TentativeParsingAction PA(*this);
-
TPR = TryParseSimpleDeclaration();
- SourceLocation TentativeParseLoc = Tok.getLocation();
-
PA.Revert();
// In case of an error, let the declaration parsing code handle it.
diff --git a/lib/Rewrite/RewriteObjC.cpp b/lib/Rewrite/RewriteObjC.cpp
index 7d06038..985a6a2 100644
--- a/lib/Rewrite/RewriteObjC.cpp
+++ b/lib/Rewrite/RewriteObjC.cpp
@@ -1952,7 +1952,6 @@
buf += "}";
ReplaceText(lastCurlyLoc, 1, buf);
}
- bool sawIdTypedCatch = false;
Stmt *lastCatchBody = 0;
for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
ObjCAtCatchStmt *Catch = S->getCatchStmt(I);
@@ -1985,7 +1984,6 @@
if (t == Context->getObjCIdType()) {
buf += "1) { ";
ReplaceText(startLoc, lParenLoc-startBuf+1, buf);
- sawIdTypedCatch = true;
} else if (const ObjCObjectPointerType *Ptr =
t->getAs<ObjCObjectPointerType>()) {
// Should be a pointer to a class.
diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp
index ba1c3b0..200f975 100644
--- a/lib/Sema/SemaCXXCast.cpp
+++ b/lib/Sema/SemaCXXCast.cpp
@@ -601,8 +601,6 @@
// In the CStyle case, the earlier attempt to const_cast should have taken
// care of reverse qualification conversions.
- QualType OrigSrcType = SrcExpr->getType();
-
QualType SrcType = Self.Context.getCanonicalType(SrcExpr->getType());
// C++0x 5.2.9p9: A value of a scoped enumeration type can be explicitly
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index e7bd7d5..c736d47 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -4995,10 +4995,7 @@
// Form the assignment:
// static_cast<Base*>(this)->Base::operator=(static_cast<Base&>(other));
QualType BaseType = Base->getType().getUnqualifiedType();
- CXXRecordDecl *BaseClassDecl = 0;
- if (const RecordType *BaseRecordT = BaseType->getAs<RecordType>())
- BaseClassDecl = cast<CXXRecordDecl>(BaseRecordT->getDecl());
- else {
+ if (!BaseType->isRecordType()) {
Invalid = true;
continue;
}
@@ -6220,8 +6217,6 @@
Invalid = true;
}
- QualType ExDeclType = TInfo->getType();
-
IdentifierInfo *II = D.getIdentifier();
if (NamedDecl *PrevDecl = LookupSingleName(S, II, D.getIdentifierLoc(),
LookupOrdinaryName,
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 902afac..26fdb2e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -8531,7 +8531,7 @@
Expr *expr, ParsedType type,
SourceLocation RPLoc) {
TypeSourceInfo *TInfo;
- QualType T = GetTypeFromParser(type, &TInfo);
+ GetTypeFromParser(type, &TInfo);
return BuildVAArgExpr(BuiltinLoc, expr, TInfo, RPLoc);
}
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index d08d26f..61fe55b 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -718,7 +718,6 @@
if (!TInfo)
TInfo = Context.getTrivialTypeSourceInfo(AllocType);
- SourceRange R = TInfo->getTypeLoc().getSourceRange();
return BuildCXXNew(StartLoc, UseGlobal,
PlacementLParen,
move(PlacementArgs),
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp
index 3c9d386..d4953c3 100644
--- a/lib/Sema/SemaTemplate.cpp
+++ b/lib/Sema/SemaTemplate.cpp
@@ -6128,4 +6128,3 @@
Out << ']';
return Out.str();
}
-
diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp
index a608bea..0d074e0 100644
--- a/lib/Sema/SemaTemplateDeduction.cpp
+++ b/lib/Sema/SemaTemplateDeduction.cpp
@@ -2019,11 +2019,9 @@
// note that the template argument pack is partially substituted and record
// the explicit template arguments. They'll be used as part of deduction
// for this template parameter pack.
- bool HasPartiallySubstitutedPack = false;
for (unsigned I = 0, N = Builder.size(); I != N; ++I) {
const TemplateArgument &Arg = Builder[I];
if (Arg.getKind() == TemplateArgument::Pack) {
- HasPartiallySubstitutedPack = true;
CurrentInstantiationScope->SetPartiallySubstitutedPack(
TemplateParams->getParam(I),
Arg.pack_begin(),
@@ -2438,7 +2436,6 @@
else {
// - If A is a cv-qualified type, the top level cv-qualifiers of A’s
// type are ignored for type deduction.
- QualType CanonArgType = S.Context.getCanonicalType(ArgType);
if (ArgType.getCVRQualifiers())
ArgType = ArgType.getUnqualifiedType();
}
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index be4d82c..2020260 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -7126,7 +7126,6 @@
ParmVarDecl *OldParm = (*P);
ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
llvm::Optional<unsigned>());
- QualType NewType = NewParm->getType();
Params.push_back(NewParm);
ParamTypes.push_back(NewParm->getType());
}
diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp
index 7223362..c329711 100644
--- a/lib/Serialization/ASTWriterDecl.cpp
+++ b/lib/Serialization/ASTWriterDecl.cpp
@@ -661,7 +661,6 @@
if (Map) {
for (StoredDeclsMap::iterator D = Map->begin(), DEnd = Map->end();
D != DEnd; ++D) {
- DeclarationName Name = D->first;
DeclContext::lookup_result Result = D->second.getLookupResult();
while (Result.first != Result.second) {
Writer.GetDeclRef(*Result.first);
diff --git a/lib/StaticAnalyzer/CXXExprEngine.cpp b/lib/StaticAnalyzer/CXXExprEngine.cpp
index 47b3a0b..149d4bd 100644
--- a/lib/StaticAnalyzer/CXXExprEngine.cpp
+++ b/lib/StaticAnalyzer/CXXExprEngine.cpp
@@ -50,14 +50,8 @@
// Evaluate the argument.
ExplodedNodeSet Tmp;
- bool VisitAsLvalue = FstArgAsLValue;
if (FstArgAsLValue) {
FstArgAsLValue = false;
- } else {
- const unsigned ParamIdx = Item.I - AI;
- VisitAsLvalue = FnType && ParamIdx < FnType->getNumArgs()
- ? FnType->getArgType(ParamIdx)->isReferenceType()
- : false;
}
Visit(*Item.I, Item.N, Tmp);
diff --git a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
index f45041b..a022562 100644
--- a/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
+++ b/lib/StaticAnalyzer/Checkers/ExprEngine.cpp
@@ -3168,8 +3168,6 @@
if (Op == BO_Assign) {
// EXPERIMENTAL: "Conjured" symbols.
// FIXME: Handle structs.
- QualType T = RHS->getType();
-
if (RightV.isUnknown() ||!getConstraintManager().canReasonAbout(RightV))
{
unsigned Count = Builder->getCurrentBlockCount();
@@ -3238,7 +3236,6 @@
CLHSTy = getContext().getCanonicalType(CLHSTy);
QualType LTy = getContext().getCanonicalType(LHS->getType());
- QualType RTy = getContext().getCanonicalType(RHS->getType());
// Promote LHS.
V = svalBuilder.evalCast(V, CLHSTy, LTy);
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 910f449..7f00f99 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -1530,22 +1530,22 @@
public:
LabelRefVisit(LabelStmt *LS, SourceLocation labelLoc, CXCursor parent)
: VisitorJob(parent, VisitorJob::LabelRefVisitKind, LS,
- (void*) labelLoc.getRawEncoding()) {}
+ labelLoc.getPtrEncoding()) {}
static bool classof(const VisitorJob *VJ) {
return VJ->getKind() == VisitorJob::LabelRefVisitKind;
}
LabelStmt *get() const { return static_cast<LabelStmt*>(data[0]); }
SourceLocation getLoc() const {
- return SourceLocation::getFromRawEncoding((unsigned)(uintptr_t) data[1]); }
+ return SourceLocation::getFromPtrEncoding(data[1]); }
};
class NestedNameSpecifierVisit : public VisitorJob {
public:
NestedNameSpecifierVisit(NestedNameSpecifier *NS, SourceRange R,
CXCursor parent)
: VisitorJob(parent, VisitorJob::NestedNameSpecifierVisitKind,
- NS, (void*) R.getBegin().getRawEncoding(),
- (void*) R.getEnd().getRawEncoding()) {}
+ NS, R.getBegin().getPtrEncoding(),
+ R.getEnd().getPtrEncoding()) {}
static bool classof(const VisitorJob *VJ) {
return VJ->getKind() == VisitorJob::NestedNameSpecifierVisitKind;
}
@@ -1583,7 +1583,7 @@
public:
MemberRefVisit(FieldDecl *D, SourceLocation L, CXCursor parent)
: VisitorJob(parent, VisitorJob::MemberRefVisitKind, D,
- (void*) L.getRawEncoding()) {}
+ L.getPtrEncoding()) {}
static bool classof(const VisitorJob *VJ) {
return VJ->getKind() == VisitorJob::MemberRefVisitKind;
}
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 7bcd159..7ae9f7d 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -57,7 +57,7 @@
bool FirstInDeclGroup) {
assert(D && TU && "Invalid arguments!");
CXCursor C = { getCursorKindForDecl(D),
- { D, (void*) (FirstInDeclGroup ? 1 : 0), TU }
+ { D, (void*)(intptr_t) (FirstInDeclGroup ? 1 : 0), TU }
};
return C;
}
@@ -560,4 +560,3 @@
return flag;
}
} // end: extern "C"
-