summaryrefslogtreecommitdiffstats
path: root/clang
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
commita98799fe4b4471a5d392f8fe4b291ae7c73c569c (patch)
treeceac5df403a359396e040ed54e1ada2d8c7767d4 /clang
parent2b3f143f23de6d56ef8f38044ab79d56e9f592ac (diff)
downloadbcm5719-llvm-a98799fe4b4471a5d392f8fe4b291ae7c73c569c.tar.gz
bcm5719-llvm-a98799fe4b4471a5d392f8fe4b291ae7c73c569c.zip
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. llvm-svn: 190521
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp4
-rw-r--r--clang/tools/libclang/CXSourceLocation.cpp28
2 files changed, 17 insertions, 15 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 12aa0a2b7c4..89340b4db82 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -2095,8 +2095,8 @@ llvm::Constant *CodeGenFunction::EmitCheckSourceLocation(SourceLocation Loc) {
PLoc.isValid() ? cast<llvm::Constant>(
Builder.CreateGlobalStringPtr(PLoc.getFilename()))
: llvm::Constant::getNullValue(Int8PtrTy),
- Builder.getInt32(PLoc.getLine()),
- Builder.getInt32(PLoc.getColumn())
+ Builder.getInt32(PLoc.isValid() ? PLoc.getLine() : 0),
+ Builder.getInt32(PLoc.isValid() ? PLoc.getColumn() : 0)
};
return llvm::ConstantStruct::getAnon(Data);
diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp
index a33c9d4f269..64b2908c49d 100644
--- a/clang/tools/libclang/CXSourceLocation.cpp
+++ b/clang/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,
OpenPOWER on IntegriCloud