Don't use std::errc.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 13 Jun 2015 17:23:15 +0000 (17:23 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 13 Jun 2015 17:23:15 +0000 (17:23 +0000)
As noted on Errc.h:

// * std::errc is just marked with is_error_condition_enum. This means that
//   common patters like AnErrorCode == errc::no_such_file_or_directory take
//   4 virtual calls instead of two comparisons.

And on some libstdc++ those virtual functions conclude that

------------------------
int main() {
  std::error_code foo = std::make_error_code(std::errc::no_such_file_or_directory);
  return foo == std::errc::no_such_file_or_directory;
}
-------------------------

should exit with 0.

llvm-svn: 239685

lld/lib/ReaderWriter/LinkerScript.cpp

index 9c7f937..6d82e29 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/APInt.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/Errc.h"
 #include "llvm/Support/ELF.h"
 
 namespace lld {
@@ -106,7 +107,7 @@ static llvm::ErrorOr<uint64_t> parseDecimal(StringRef str) {
   for (auto &c : str) {
     res *= 10;
     if (c < '0' || c > '9')
-      return llvm::ErrorOr<uint64_t>(std::make_error_code(std::errc::io_error));
+      return llvm::ErrorOr<uint64_t>(make_error_code(llvm::errc::io_error));
     res += c - '0';
   }
   return res;
@@ -117,7 +118,7 @@ static llvm::ErrorOr<uint64_t> parseOctal(StringRef str) {
   for (auto &c : str) {
     res <<= 3;
     if (c < '0' || c > '7')
-      return llvm::ErrorOr<uint64_t>(std::make_error_code(std::errc::io_error));
+      return llvm::ErrorOr<uint64_t>(make_error_code(llvm::errc::io_error));
     res += c - '0';
   }
   return res;
@@ -128,7 +129,7 @@ static llvm::ErrorOr<uint64_t> parseBinary(StringRef str) {
   for (auto &c : str) {
     res <<= 1;
     if (c != '0' && c != '1')
-      return llvm::ErrorOr<uint64_t>(std::make_error_code(std::errc::io_error));
+      return llvm::ErrorOr<uint64_t>(make_error_code(llvm::errc::io_error));
     res += c - '0';
   }
   return res;
@@ -145,7 +146,7 @@ static llvm::ErrorOr<uint64_t> parseHex(StringRef str) {
     else if (c >= 'A' && c <= 'F')
       res += c - 'A' + 10;
     else
-      return llvm::ErrorOr<uint64_t>(std::make_error_code(std::errc::io_error));
+      return llvm::ErrorOr<uint64_t>(make_error_code(llvm::errc::io_error));
   }
   return res;
 }
@@ -1637,7 +1638,7 @@ llvm::ErrorOr<InputSectionsCmd::VectorTy> Parser::parseExcludeFile() {
 
   if (!expectAndConsume(Token::l_paren, "expected ("))
     return llvm::ErrorOr<InputSectionsCmd::VectorTy>(
-        std::make_error_code(std::errc::io_error));
+        make_error_code(llvm::errc::io_error));
 
   while (_tok._kind == Token::identifier) {
     res.push_back(new (_alloc) InputSectionName(*this, _tok._range, true));
@@ -1646,7 +1647,7 @@ llvm::ErrorOr<InputSectionsCmd::VectorTy> Parser::parseExcludeFile() {
 
   if (!expectAndConsume(Token::r_paren, "expected )"))
     return llvm::ErrorOr<InputSectionsCmd::VectorTy>(
-        std::make_error_code(std::errc::io_error));
+        make_error_code(llvm::errc::io_error));
   return llvm::ErrorOr<InputSectionsCmd::VectorTy>(std::move(res));
 }