Update slang for LLVM rebase to r222494.

Change-Id: I19e441e193637ddb39b3afb3bc95579755ac0a90
diff --git a/Android.mk b/Android.mk
index 542a6fe..f07292a 100644
--- a/Android.mk
+++ b/Android.mk
@@ -70,7 +70,6 @@
 
 LOCAL_SRC_FILES :=	\
 	slang.cpp	\
-	slang_utils.cpp	\
 	slang_backend.cpp	\
 	slang_pragma_recorder.cpp	\
 	slang_diagnostic_buffer.cpp
diff --git a/llvm-rs-as.cpp b/llvm-rs-as.cpp
index b176002..1f81b14 100644
--- a/llvm-rs-as.cpp
+++ b/llvm-rs-as.cpp
@@ -87,12 +87,12 @@
     }
   }
 
-  std::string ErrorInfo;
+  std::error_code EC;
   std::unique_ptr<tool_output_file> Out
-  (new tool_output_file(OutputFilename.c_str(), ErrorInfo,
-                        llvm::sys::fs::F_None));
-  if (!ErrorInfo.empty()) {
-    errs() << ErrorInfo << '\n';
+  (new tool_output_file(OutputFilename.c_str(), EC, llvm::sys::fs::F_None));
+  if (EC) {
+    // TODO(srhines): This isn't actually very specific and needs cleanup.
+    errs() << EC.message() << '\n';
     exit(1);
   }
 
@@ -127,7 +127,7 @@
 
   // Parse the file now...
   SMDiagnostic Err;
-  std::unique_ptr<Module> M(ParseAssemblyFile(InputFilename, Err, Context));
+  std::unique_ptr<Module> M(parseAssemblyFile(InputFilename, Err, Context));
   if (M.get() == 0) {
     Err.print(argv[0], errs());
     return 1;
diff --git a/slang.cpp b/slang.cpp
index 21ee692..cf8404d 100644
--- a/slang.cpp
+++ b/slang.cpp
@@ -68,32 +68,12 @@
 
 #include "slang_assert.h"
 #include "slang_backend.h"
-#include "slang_utils.h"
 
 namespace {
 
 static const char *kRSTriple32 = "armv7-none-linux-gnueabi";
 static const char *kRSTriple64 = "aarch64-none-linux-gnueabi";
 
-struct ForceSlangLinking {
-  ForceSlangLinking() {
-    // We must reference the functions in such a way that compilers will not
-    // delete it all as dead code, even with whole program optimization,
-    // yet is effectively a NO-OP. As the compiler isn't smart enough
-    // to know that getenv() never returns -1, this will do the job.
-    if (std::getenv("bar") != reinterpret_cast<char*>(-1))
-      return;
-
-    // llvm-rs-link needs following functions existing in libslang.
-    llvm::parseBitcodeFile(nullptr, llvm::getGlobalContext());
-    llvm::Linker::LinkModules(nullptr, nullptr, 0, nullptr);
-
-    // llvm-rs-cc need this.
-    new clang::TextDiagnosticPrinter(llvm::errs(),
-                                     new clang::DiagnosticOptions());
-  }
-} ForceSlangLinking;
-
 }  // namespace
 
 namespace slang {
@@ -113,22 +93,23 @@
 static inline llvm::tool_output_file *
 OpenOutputFile(const char *OutputFile,
                llvm::sys::fs::OpenFlags Flags,
-               std::string* Error,
+               std::error_code &EC,
                clang::DiagnosticsEngine *DiagEngine) {
-  slangAssert((OutputFile != nullptr) && (Error != nullptr) &&
+  slangAssert((OutputFile != nullptr) &&
               (DiagEngine != nullptr) && "Invalid parameter!");
 
-  if (SlangUtils::CreateDirectoryWithParents(
-                        llvm::sys::path::parent_path(OutputFile), Error)) {
+  EC = llvm::sys::fs::create_directories(
+      llvm::sys::path::parent_path(OutputFile));
+  if (!EC) {
     llvm::tool_output_file *F =
-          new llvm::tool_output_file(OutputFile, *Error, Flags);
+          new llvm::tool_output_file(OutputFile, EC, Flags);
     if (F != nullptr)
       return F;
   }
 
   // Report error here.
   DiagEngine->Report(clang::diag::err_fe_error_opening)
-    << OutputFile << *Error;
+    << OutputFile << EC.message();
 
   return nullptr;
 }
@@ -299,9 +280,9 @@
   mSourceMgr->clearIDTables();
 
   // Load the source
-  llvm::MemoryBuffer *SB =
+  std::unique_ptr<llvm::MemoryBuffer> SB =
       llvm::MemoryBuffer::getMemBuffer(Text, Text + TextLength);
-  mSourceMgr->setMainFileID(mSourceMgr->createFileID(SB));
+  mSourceMgr->setMainFileID(mSourceMgr->createFileID(std::move(SB)));
 
   if (mSourceMgr->getMainFileID().isInvalid()) {
     mDiagEngine->Report(clang::diag::err_fe_error_reading) << InputFile;
@@ -330,15 +311,14 @@
 }
 
 bool Slang::setOutput(const char *OutputFile) {
-  std::string Error;
+  std::error_code EC;
   llvm::tool_output_file *OS = nullptr;
 
   switch (mOT) {
     case OT_Dependency:
     case OT_Assembly:
     case OT_LLVMAssembly: {
-      OS = OpenOutputFile(OutputFile, llvm::sys::fs::F_Text, &Error,
-          mDiagEngine);
+      OS = OpenOutputFile(OutputFile, llvm::sys::fs::F_Text, EC, mDiagEngine);
       break;
     }
     case OT_Nothing: {
@@ -346,8 +326,7 @@
     }
     case OT_Object:
     case OT_Bitcode: {
-      OS = OpenOutputFile(OutputFile, llvm::sys::fs::F_None,
-                          &Error, mDiagEngine);
+      OS = OpenOutputFile(OutputFile, llvm::sys::fs::F_None, EC, mDiagEngine);
       break;
     }
     default: {
@@ -355,7 +334,7 @@
     }
   }
 
-  if (!Error.empty())
+  if (EC)
     return false;
 
   mOS.reset(OS);
@@ -366,11 +345,11 @@
 }
 
 bool Slang::setDepOutput(const char *OutputFile) {
-  std::string Error;
+  std::error_code EC;
 
   mDOS.reset(
-      OpenOutputFile(OutputFile, llvm::sys::fs::F_Text, &Error, mDiagEngine));
-  if (!Error.empty() || (mDOS.get() == nullptr))
+      OpenOutputFile(OutputFile, llvm::sys::fs::F_Text, EC, mDiagEngine));
+  if (EC || (mDOS.get() == nullptr))
     return false;
 
   mDepOutputFileName = OutputFile;
diff --git a/slang_backend.cpp b/slang_backend.cpp
index 8780a77..4c6a3b9 100644
--- a/slang_backend.cpp
+++ b/slang_backend.cpp
@@ -65,7 +65,7 @@
 void Backend::CreateFunctionPasses() {
   if (!mPerFunctionPasses) {
     mPerFunctionPasses = new llvm::FunctionPassManager(mpModule);
-    mPerFunctionPasses->add(new llvm::DataLayoutPass(mpModule));
+    mPerFunctionPasses->add(new llvm::DataLayoutPass());
 
     llvm::PassManagerBuilder PMBuilder;
     PMBuilder.OptLevel = mCodeGenOpts.OptimizationLevel;
@@ -76,7 +76,7 @@
 void Backend::CreateModulePasses() {
   if (!mPerModulePasses) {
     mPerModulePasses = new llvm::PassManager();
-    mPerModulePasses->add(new llvm::DataLayoutPass(mpModule));
+    mPerModulePasses->add(new llvm::DataLayoutPass());
 
     llvm::PassManagerBuilder PMBuilder;
     PMBuilder.OptLevel = mCodeGenOpts.OptimizationLevel;
@@ -108,7 +108,7 @@
     return true;
   } else {
     mCodeGenPasses = new llvm::FunctionPassManager(mpModule);
-    mCodeGenPasses->add(new llvm::DataLayoutPass(mpModule));
+    mCodeGenPasses->add(new llvm::DataLayoutPass());
   }
 
   // Create the TargetMachine for generating code.
diff --git a/slang_rs.cpp b/slang_rs.cpp
index 5ed80d9..88eb909 100644
--- a/slang_rs.cpp
+++ b/slang_rs.cpp
@@ -180,11 +180,14 @@
 
 void SlangRS::initDiagnostic() {
   clang::DiagnosticsEngine &DiagEngine = getDiagnostics();
+  const auto Flavor = clang::diag::Flavor::WarningOrError;
 
-  if (DiagEngine.setSeverityForGroup("implicit-function-declaration",
-                                     clang::diag::Severity::Error))
-    DiagEngine.Report(clang::diag::warn_unknown_warning_option)
+  if (DiagEngine.setSeverityForGroup(Flavor, "implicit-function-declaration",
+                                     clang::diag::Severity::Error)) {
+    DiagEngine.Report(clang::diag::warn_unknown_diag_option)
+      << /* clang::diag::Flavor::WarningOrError */ 0
       << "implicit-function-declaration";
+  }
 
   DiagEngine.setSeverity(
     clang::diag::ext_typecheck_convert_discards_qualifiers,
diff --git a/slang_rs_export_type.cpp b/slang_rs_export_type.cpp
index 216665b..8a8dbe0 100644
--- a/slang_rs_export_type.cpp
+++ b/slang_rs_export_type.cpp
@@ -922,8 +922,8 @@
 
   if (RSSpecificTypeMap->empty()) {
     for (int i = 0; i < MatrixAndObjectDataTypesCount; i++) {
-      RSSpecificTypeMap->GetOrCreateValue(MatrixAndObjectDataTypes[i].name,
-                                          MatrixAndObjectDataTypes[i].dataType);
+      (*RSSpecificTypeMap)[MatrixAndObjectDataTypes[i].name] =
+          MatrixAndObjectDataTypes[i].dataType;
     }
   }
 
diff --git a/slang_rs_reflect_utils.cpp b/slang_rs_reflect_utils.cpp
index cccbdc4..c67a1a8 100644
--- a/slang_rs_reflect_utils.cpp
+++ b/slang_rs_reflect_utils.cpp
@@ -22,10 +22,11 @@
 #include <iomanip>
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
 
 #include "os_sep.h"
 #include "slang_assert.h"
-#include "slang_utils.h"
 
 namespace slang {
 
@@ -261,9 +262,10 @@
     const BitCodeAccessorContext &context) {
   string output_path =
       ComputePackagedPath(context.reflectPath, context.packageName);
-  if (!SlangUtils::CreateDirectoryWithParents(llvm::StringRef(output_path),
-                                              nullptr)) {
-    fprintf(stderr, "Error: could not create dir %s\n", output_path.c_str());
+  if (std::error_code EC = llvm::sys::fs::create_directories(
+          llvm::sys::path::parent_path(output_path))) {
+    fprintf(stderr, "Error: could not create dir %s: %s\n",
+            output_path.c_str(), EC.message().c_str());
     return false;
   }
 
@@ -348,9 +350,9 @@
 
   // Create the parent directories.
   if (!outDirectory.empty()) {
-    std::string errorMsg;
-    if (!SlangUtils::CreateDirectoryWithParents(outDirectory, &errorMsg)) {
-      fprintf(stderr, "Error: %s\n", errorMsg.c_str());
+    if (std::error_code EC = llvm::sys::fs::create_directories(
+            llvm::sys::path::parent_path(outDirectory))) {
+      fprintf(stderr, "Error: %s\n", EC.message().c_str());
       return false;
     }
   }
diff --git a/slang_rs_reflection.cpp b/slang_rs_reflection.cpp
index be3d7dc..70c31d6 100644
--- a/slang_rs_reflection.cpp
+++ b/slang_rs_reflection.cpp
@@ -37,7 +37,6 @@
 #include "slang_rs_export_func.h"
 #include "slang_rs_reflect_utils.h"
 #include "slang_version.h"
-#include "slang_utils.h"
 
 #define RS_SCRIPT_CLASS_NAME_PREFIX "ScriptC_"
 #define RS_SCRIPT_CLASS_SUPER_CLASS_NAME "ScriptC"
diff --git a/slang_rs_reflection_cpp.cpp b/slang_rs_reflection_cpp.cpp
index 0b08028..ee1b4bc 100644
--- a/slang_rs_reflection_cpp.cpp
+++ b/slang_rs_reflection_cpp.cpp
@@ -34,7 +34,6 @@
 #include "slang_rs_export_func.h"
 #include "slang_rs_reflect_utils.h"
 #include "slang_version.h"
-#include "slang_utils.h"
 
 #include "slang_rs_reflection_cpp.h"
 
diff --git a/slang_utils.cpp b/slang_utils.cpp
deleted file mode 100644
index 45d1b93..0000000
--- a/slang_utils.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "slang_utils.h"
-
-#include <string>
-
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/FileSystem.h"
-
-namespace slang {
-
-bool SlangUtils::CreateDirectoryWithParents(llvm::StringRef Dir,
-                                            std::string* Error) {
-  std::error_code EC = llvm::sys::fs::create_directories(Dir);
-  if (EC) {
-    Error->assign(EC.message());
-    return false;
-  }
-  return true;
-}
-
-}  // namespace slang
diff --git a/slang_utils.h b/slang_utils.h
deleted file mode 100644
index 9a123e3..0000000
--- a/slang_utils.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef _COMPILE_SLANG_SLANG_UTILS_H_  // NOLINT
-#define _COMPILE_SLANG_SLANG_UTILS_H_
-
-#include <string>
-
-namespace llvm {
-  class StringRef;
-}
-
-namespace slang {
-
-class SlangUtils {
- private:
-  SlangUtils() {}
-
- public:
-  static bool CreateDirectoryWithParents(llvm::StringRef Dir,
-                                         std::string* Error);
-};
-}  // namespace slang
-
-#endif  // _COMPILE_SLANG_SLANG_UTILS_H_  NOLINT