aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-09-11 12:33:58 +0000
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>2013-09-11 12:33:58 +0000
commit2bb6dad4a44569dd2f86e7500a5ba21680718736 (patch)
tree2926afbdb357fe0aa01c59bf248f7444a2fdafdc /tools
parent73d845cbe26df2fb188e30853efb8ce4b0556afe (diff)
downloadclang-2bb6dad4a44569dd2f86e7500a5ba21680718736.tar.gz
Fix 2 cases of uninitialized reads of an invalid PresumedLoc.
The code in CGExpr was added back in 2012 (r165536) but not exercised in tests until recently. Detected on the MemorySanitizer bootstrap bot. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190521 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r--tools/libclang/CXSourceLocation.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/tools/libclang/CXSourceLocation.cpp b/tools/libclang/CXSourceLocation.cpp
index a33c9d4f26..64b2908c49 100644
--- a/tools/libclang/CXSourceLocation.cpp
+++ b/tools/libclang/CXSourceLocation.cpp
@@ -266,7 +266,7 @@ void clang_getPresumedLocation(CXSourceLocation location,
CXString *filename,
unsigned *line,
unsigned *column) {
-
+
if (!isASTUnitSourceLocation(location)) {
// Other SourceLocation implementations do not support presumed locations
// at this time.
@@ -276,20 +276,22 @@ void clang_getPresumedLocation(CXSourceLocation location,
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
- if (!location.ptr_data[0] || Loc.isInvalid())
+ if (!location.ptr_data[0] || Loc.isInvalid()) {
createNullLocation(filename, line, column);
- else {
- const SourceManager &SM =
- *static_cast<const SourceManager*>(location.ptr_data[0]);
- PresumedLoc PreLoc = SM.getPresumedLoc(Loc);
-
- if (filename)
- *filename = cxstring::createRef(PreLoc.getFilename());
- if (line)
- *line = PreLoc.getLine();
- if (column)
- *column = PreLoc.getColumn();
+ return;
}
+
+ const SourceManager &SM =
+ *static_cast<const SourceManager *>(location.ptr_data[0]);
+ PresumedLoc PreLoc = SM.getPresumedLoc(Loc);
+ if (PreLoc.isInvalid()) {
+ createNullLocation(filename, line, column);
+ return;
+ }
+
+ if (filename) *filename = cxstring::createRef(PreLoc.getFilename());
+ if (line) *line = PreLoc.getLine();
+ if (column) *column = PreLoc.getColumn();
}
void clang_getInstantiationLocation(CXSourceLocation location,