r190521 - Fix 2 cases of uninitialized reads of an invalid PresumedLoc.

Evgeniy Stepanov eugeni.stepanov at gmail.com
Wed Sep 11 05:33:58 PDT 2013


Author: eugenis
Date: Wed Sep 11 07:33:58 2013
New Revision: 190521

URL: http://llvm.org/viewvc/llvm-project?rev=190521&view=rev
Log:
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.


Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/tools/libclang/CXSourceLocation.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=190521&r1=190520&r2=190521&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Sep 11 07:33:58 2013
@@ -2095,8 +2095,8 @@ llvm::Constant *CodeGenFunction::EmitChe
     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);

Modified: cfe/trunk/tools/libclang/CXSourceLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXSourceLocation.cpp?rev=190521&r1=190520&r2=190521&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXSourceLocation.cpp (original)
+++ cfe/trunk/tools/libclang/CXSourceLocation.cpp Wed Sep 11 07:33:58 2013
@@ -266,7 +266,7 @@ void clang_getPresumedLocation(CXSourceL
                                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(CXSourceL
 
   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,





More information about the cfe-commits mailing list