Fix use of uninitialized value exposed by r267802. Accessors of an invalid
PresumedLoc should not be called. llvm-svn: 267914
This commit is contained in:
parent
551ccac7e4
commit
41e6629100
|
@ -373,22 +373,22 @@ public:
|
|||
/// \brief Return the presumed filename of this location.
|
||||
///
|
||||
/// This can be affected by \#line etc.
|
||||
const char *getFilename() const { return Filename; }
|
||||
const char *getFilename() const { assert(isValid()); return Filename; }
|
||||
|
||||
/// \brief Return the presumed line number of this location.
|
||||
///
|
||||
/// This can be affected by \#line etc.
|
||||
unsigned getLine() const { return Line; }
|
||||
unsigned getLine() const { assert(isValid()); return Line; }
|
||||
|
||||
/// \brief Return the presumed column number of this location.
|
||||
///
|
||||
/// This cannot be affected by \#line, but is packaged here for convenience.
|
||||
unsigned getColumn() const { return Col; }
|
||||
unsigned getColumn() const { assert(isValid()); return Col; }
|
||||
|
||||
/// \brief Return the presumed include location of this location.
|
||||
///
|
||||
/// This can be affected by GNU linemarker directives.
|
||||
SourceLocation getIncludeLoc() const { return IncludeLoc; }
|
||||
SourceLocation getIncludeLoc() const { assert(isValid()); return IncludeLoc; }
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1160,7 +1160,8 @@ unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos,
|
|||
|
||||
// isInvalid - Return the result of calling loc.isInvalid(), and
|
||||
// if Invalid is not null, set its value to same.
|
||||
static bool isInvalid(SourceLocation Loc, bool *Invalid) {
|
||||
template<typename LocType>
|
||||
static bool isInvalid(LocType Loc, bool *Invalid) {
|
||||
bool MyInvalid = Loc.isInvalid();
|
||||
if (Invalid)
|
||||
*Invalid = MyInvalid;
|
||||
|
@ -1183,8 +1184,9 @@ unsigned SourceManager::getExpansionColumnNumber(SourceLocation Loc,
|
|||
|
||||
unsigned SourceManager::getPresumedColumnNumber(SourceLocation Loc,
|
||||
bool *Invalid) const {
|
||||
if (isInvalid(Loc, Invalid)) return 0;
|
||||
return getPresumedLoc(Loc).getColumn();
|
||||
PresumedLoc PLoc = getPresumedLoc(Loc);
|
||||
if (isInvalid(PLoc, Invalid)) return 0;
|
||||
return PLoc.getColumn();
|
||||
}
|
||||
|
||||
#ifdef __SSE2__
|
||||
|
|
|
@ -167,7 +167,8 @@ void DiagnosticRenderer::emitIncludeStack(SourceLocation Loc,
|
|||
PresumedLoc PLoc,
|
||||
DiagnosticsEngine::Level Level,
|
||||
const SourceManager &SM) {
|
||||
SourceLocation IncludeLoc = PLoc.getIncludeLoc();
|
||||
SourceLocation IncludeLoc =
|
||||
PLoc.isInvalid() ? SourceLocation() : PLoc.getIncludeLoc();
|
||||
|
||||
// Skip redundant include stacks altogether.
|
||||
if (LastIncludeLoc == IncludeLoc)
|
||||
|
|
|
@ -883,7 +883,7 @@ void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
|
|||
void TextDiagnostic::emitIncludeLocation(SourceLocation Loc,
|
||||
PresumedLoc PLoc,
|
||||
const SourceManager &SM) {
|
||||
if (DiagOpts->ShowLocation && PLoc.getFilename())
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid())
|
||||
OS << "In file included from " << PLoc.getFilename() << ':'
|
||||
<< PLoc.getLine() << ":\n";
|
||||
else
|
||||
|
@ -893,7 +893,7 @@ void TextDiagnostic::emitIncludeLocation(SourceLocation Loc,
|
|||
void TextDiagnostic::emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
|
||||
StringRef ModuleName,
|
||||
const SourceManager &SM) {
|
||||
if (DiagOpts->ShowLocation && PLoc.getFilename())
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid())
|
||||
OS << "In module '" << ModuleName << "' imported from "
|
||||
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
|
||||
else
|
||||
|
@ -904,7 +904,7 @@ void TextDiagnostic::emitBuildingModuleLocation(SourceLocation Loc,
|
|||
PresumedLoc PLoc,
|
||||
StringRef ModuleName,
|
||||
const SourceManager &SM) {
|
||||
if (DiagOpts->ShowLocation && PLoc.getFilename())
|
||||
if (DiagOpts->ShowLocation && PLoc.isValid())
|
||||
OS << "While building module '" << ModuleName << "' imported from "
|
||||
<< PLoc.getFilename() << ':' << PLoc.getLine() << ":\n";
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue