]> granicus.if.org Git - clang/commitdiff
CodeGenAction::ExecuteAction(): check for invalid LLVM source locations
authorAlp Toker <alp@nuanti.com>
Mon, 30 Jun 2014 01:33:59 +0000 (01:33 +0000)
committerAlp Toker <alp@nuanti.com>
Mon, 30 Jun 2014 01:33:59 +0000 (01:33 +0000)
Add sign checks to deal with the fact that IR parser line/column pairs are
signed integers and sometimes invalid.

The crash path is potentially triggered by corrupt '.bc' files in practice,
though I don't have a binary input test case that can be checked-in right now.

(Unfortunately the backend itself crashes on various ill-formed '.bc' inputs so
this bandage isn't as helpful as it appears yet.)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212007 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenAction.cpp

index 3342aa12c8666fd7bcee2b889db0973556d52689..0f637594413a53a990c5dc4d0b7f640ae3a72863 100644 (file)
@@ -641,17 +641,23 @@ void CodeGenAction::ExecuteAction() {
 
     bool Invalid;
     SourceManager &SM = CI.getSourceManager();
-    llvm::MemoryBuffer *MainFile = SM.getBuffer(SM.getMainFileID(), &Invalid);
+    FileID FID = SM.getMainFileID();
+    llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid);
     if (Invalid)
       return;
 
     llvm::SMDiagnostic Err;
     TheModule.reset(ParseIR(MainFile, Err, *VMContext));
     if (!TheModule) {
-      // Translate from the diagnostic info to the SourceManager location.
-      SourceLocation Loc = SM.translateFileLineCol(
-        SM.getFileEntryForID(SM.getMainFileID()), Err.getLineNo(),
-        Err.getColumnNo() + 1);
+      // Translate from the diagnostic info to the SourceManager location if
+      // available.
+      // TODO: Unify this with ConvertBackendLocation()
+      SourceLocation Loc;
+      if (Err.getLineNo() > 0) {
+        assert(Err.getColumnNo() >= 0);
+        Loc = SM.translateFileLineCol(SM.getFileEntryForID(FID),
+                                      Err.getLineNo(), Err.getColumnNo() + 1);
+      }
 
       // Strip off a leading diagnostic code if there is one.
       StringRef Msg = Err.getMessage();