r267914 - Fix use of uninitialized value exposed by r267802. Accessors of an invalid
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 28 11:26:33 PDT 2016
Author: rsmith
Date: Thu Apr 28 13:26:32 2016
New Revision: 267914
URL: http://llvm.org/viewvc/llvm-project?rev=267914&view=rev
Log:
Fix use of uninitialized value exposed by r267802. Accessors of an invalid
PresumedLoc should not be called.
Modified:
cfe/trunk/include/clang/Basic/SourceLocation.h
cfe/trunk/lib/Basic/SourceManager.cpp
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/lib/Frontend/TextDiagnostic.cpp
Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=267914&r1=267913&r2=267914&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Thu Apr 28 13:26:32 2016
@@ -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; }
};
Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=267914&r1=267913&r2=267914&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Thu Apr 28 13:26:32 2016
@@ -1160,7 +1160,8 @@ unsigned SourceManager::getColumnNumber(
// 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::getExpansionColu
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__
Modified: cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp?rev=267914&r1=267913&r2=267914&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp (original)
+++ cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp Thu Apr 28 13:26:32 2016
@@ -167,7 +167,8 @@ void DiagnosticRenderer::emitIncludeStac
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)
Modified: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnostic.cpp?rev=267914&r1=267913&r2=267914&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp Thu Apr 28 13:26:32 2016
@@ -883,7 +883,7 @@ void TextDiagnostic::emitDiagnosticLoc(S
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
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::emitBuildingModuleL
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
More information about the cfe-commits
mailing list