Re-applying the target data layout verification patch from r142288, plus appropriate CMake dependencies.
Thanks to Raphael Espindola for tracking down the CMake issues.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142306 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AsmParser/CMakeLists.txt b/lib/AsmParser/CMakeLists.txt
index 7496015..5dcf48d 100644
--- a/lib/AsmParser/CMakeLists.txt
+++ b/lib/AsmParser/CMakeLists.txt
@@ -8,4 +8,5 @@
 add_llvm_library_dependencies(LLVMAsmParser
   LLVMCore
   LLVMSupport
+  LLVMTarget
   )
diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp
index cafaab0..eb6afd3 100644
--- a/lib/AsmParser/LLParser.cpp
+++ b/lib/AsmParser/LLParser.cpp
@@ -24,6 +24,7 @@
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/Target/TargetData.h"
 using namespace llvm;
 
 static std::string getTypeString(Type *T) {
@@ -260,9 +261,14 @@
     return false;
   case lltok::kw_datalayout:
     Lex.Lex();
+    LocTy SpecifierLoc = Lex.getLoc();
     if (ParseToken(lltok::equal, "expected '=' after target datalayout") ||
         ParseStringConstant(Str))
       return true;
+    std::string errMsg = TargetData::parseSpecifier(Str);
+    if (errMsg != "") {
+      return Error(SpecifierLoc, errMsg);
+    }
     M->setDataLayout(Str);
     return false;
   }