From 8aaf5818a64e9f7687798852af5945b053c68a54 Mon Sep 17 00:00:00 2001
From: rdivacky <rdivacky@FreeBSD.org>
Date: Tue, 4 May 2010 16:12:48 +0000
Subject: Update clang to r103004.

---
 lib/Basic/Diagnostic.cpp      |  70 +++++++++++++++++++++--------
 lib/Basic/IdentifierTable.cpp |   6 +--
 lib/Basic/SourceManager.cpp   | 100 ++++++++++++++++++++++++++++++++----------
 lib/Basic/TargetInfo.cpp      |  12 ++---
 lib/Basic/Targets.cpp         |  33 ++++++++++++++
 5 files changed, 170 insertions(+), 51 deletions(-)

(limited to 'lib/Basic')

diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp
index 2b7fcd0..1870195 100644
--- a/lib/Basic/Diagnostic.cpp
+++ b/lib/Basic/Diagnostic.cpp
@@ -11,24 +11,24 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "clang/Basic/Diagnostic.h"
-#include "clang/Basic/PartialDiagnostic.h"
-
-#include "clang/Lex/LexDiagnostic.h"
-#include "clang/Parse/ParseDiagnostic.h"
 #include "clang/AST/ASTDiagnostic.h"
-#include "clang/Sema/SemaDiagnostic.h"
-#include "clang/Frontend/FrontendDiagnostic.h"
 #include "clang/Analysis/AnalysisDiagnostic.h"
-#include "clang/Driver/DriverDiagnostic.h"
-
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/IdentifierTable.h"
+#include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
+#include "clang/Driver/DriverDiagnostic.h"
+#include "clang/Frontend/FrontendDiagnostic.h"
+#include "clang/Lex/LexDiagnostic.h"
+#include "clang/Parse/ParseDiagnostic.h"
+#include "clang/Sema/SemaDiagnostic.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/raw_ostream.h"
+
 #include <vector>
 #include <map>
 #include <cstring>
@@ -223,9 +223,12 @@ Diagnostic::Diagnostic(DiagnosticClient *client) : Client(client) {
 
   ErrorOccurred = false;
   FatalErrorOccurred = false;
-  NumDiagnostics = 0;
-  
+  ErrorLimit = 0;
+  TemplateBacktraceLimit = 0;
+
+  NumWarnings = 0;
   NumErrors = 0;
+  NumErrorsSuppressed = 0;
   CustomDiagInfo = 0;
   CurDiagID = ~0U;
   LastDiagLevel = Ignored;
@@ -286,11 +289,18 @@ bool Diagnostic::isBuiltinNote(unsigned DiagID) {
 }
 
 /// isBuiltinExtensionDiag - Determine whether the given built-in diagnostic
-/// ID is for an extension of some sort.
+/// ID is for an extension of some sort.  This also returns EnabledByDefault,
+/// which is set to indicate whether the diagnostic is ignored by default (in
+/// which case -pedantic enables it) or treated as a warning/error by default.
 ///
-bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID) {
-  return DiagID < diag::DIAG_UPPER_LIMIT &&
-         getBuiltinDiagClass(DiagID) == CLASS_EXTENSION;
+bool Diagnostic::isBuiltinExtensionDiag(unsigned DiagID,
+                                        bool &EnabledByDefault) {
+  if (DiagID >= diag::DIAG_UPPER_LIMIT ||
+      getBuiltinDiagClass(DiagID) != CLASS_EXTENSION)
+    return false;
+  
+  EnabledByDefault = StaticDiagInfo[DiagID].Mapping != diag::MAP_IGNORE;
+  return true;
 }
 
 
@@ -529,8 +539,14 @@ bool Diagnostic::ProcessDiag() {
 
   // If a fatal error has already been emitted, silence all subsequent
   // diagnostics.
-  if (FatalErrorOccurred)
+  if (FatalErrorOccurred) {
+    if (DiagLevel >= Diagnostic::Error) {
+      ++NumErrors;
+      ++NumErrorsSuppressed;
+    }
+    
     return false;
+  }
 
   // If the client doesn't care about this message, don't issue it.  If this is
   // a note and the last real diagnostic was ignored, ignore it too.
@@ -551,11 +567,20 @@ bool Diagnostic::ProcessDiag() {
   if (DiagLevel >= Diagnostic::Error) {
     ErrorOccurred = true;
     ++NumErrors;
+    
+    // If we've emitted a lot of errors, emit a fatal error after it to stop a
+    // flood of bogus errors.
+    if (ErrorLimit && NumErrors >= ErrorLimit &&
+        DiagLevel == Diagnostic::Error)
+      SetDelayedDiagnostic(diag::fatal_too_many_errors);
   }
 
   // Finally, report it.
   Client->HandleDiagnostic(DiagLevel, Info);
-  if (Client->IncludeInDiagnosticCounts()) ++NumDiagnostics;
+  if (Client->IncludeInDiagnosticCounts()) {
+    if (DiagLevel == Diagnostic::Warning)
+      ++NumWarnings;
+  }
 
   CurDiagID = ~0U;
 
@@ -1026,8 +1051,15 @@ static void WriteSourceLocation(llvm::raw_ostream &OS,
 
   Location = SM->getInstantiationLoc(Location);
   std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location);
-  
-  WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName());
+
+  const FileEntry *FE = SM->getFileEntryForID(Decomposed.first);
+  if (FE)
+    WriteString(OS, FE->getName());
+  else {
+    // Fallback to using the buffer name when there is no entry.
+    WriteString(OS, SM->getBuffer(Decomposed.first)->getBufferIdentifier());
+  }
+
   WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second));
   WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second));
 }
diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp
index 3da19ca..ed0de8c 100644
--- a/lib/Basic/IdentifierTable.cpp
+++ b/lib/Basic/IdentifierTable.cpp
@@ -78,9 +78,9 @@ namespace {
 /// identifiers because they are language keywords.  This causes the lexer to
 /// automatically map matching identifiers to specialized token codes.
 ///
-/// The C90/C99/CPP/CPP0x flags are set to 0 if the token should be
+/// The C90/C99/CPP/CPP0x flags are set to 2 if the token should be
 /// enabled in the specified langauge, set to 1 if it is an extension
-/// in the specified language, and set to 2 if disabled in the
+/// in the specified language, and set to 0 if disabled in the
 /// specified language.
 static void AddKeyword(llvm::StringRef Keyword,
                        tok::TokenKind TokenCode, unsigned Flags,
@@ -90,7 +90,7 @@ static void AddKeyword(llvm::StringRef Keyword,
   else if (LangOpts.CPlusPlus && (Flags & KEYCXX)) AddResult = 2;
   else if (LangOpts.CPlusPlus0x && (Flags & KEYCXX0X)) AddResult = 2;
   else if (LangOpts.C99 && (Flags & KEYC99)) AddResult = 2;
-  else if (LangOpts.GNUMode && (Flags & KEYGNU)) AddResult = 1;
+  else if (LangOpts.GNUKeywords && (Flags & KEYGNU)) AddResult = 1;
   else if (LangOpts.Microsoft && (Flags & KEYMS)) AddResult = 1;
   else if (LangOpts.Bool && (Flags & BOOLSUPPORT)) AddResult = 2;
   else if (LangOpts.AltiVec && (Flags & KEYALTIVEC)) AddResult = 2;
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index 27cb9be..3ecab1d 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -60,6 +60,8 @@ void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B) {
 }
 
 const llvm::MemoryBuffer *ContentCache::getBuffer(Diagnostic &Diag,
+                                                  const SourceManager &SM,
+                                                  SourceLocation Loc,
                                                   bool *Invalid) const {
   if (Invalid)
     *Invalid = false;
@@ -94,22 +96,67 @@ const llvm::MemoryBuffer *ContentCache::getBuffer(Diagnostic &Diag,
         Diag.SetDelayedDiagnostic(diag::err_cannot_open_file, 
                                   Entry->getName(), ErrorStr);
       else 
-        Diag.Report(diag::err_cannot_open_file)
+        Diag.Report(FullSourceLoc(Loc, SM), diag::err_cannot_open_file)
           << Entry->getName() << ErrorStr;
 
       Buffer.setInt(true);
+
+    // FIXME: This conditionalization is horrible, but we see spurious failures
+    // in the test suite due to this warning and no one has had time to hunt it
+    // down. So for now, we just don't emit this diagnostic on Win32, and hope
+    // nothing bad happens.
+    //
+    // PR6812.
+#if !defined(LLVM_ON_WIN32)
     } else if (FileInfo.st_size != Entry->getSize() ||
                FileInfo.st_mtime != Entry->getModificationTime()) {
-      // Check that the file's size, modification time, and inode are
-      // the same as in the file entry (which may have come from a
-      // stat cache).
+      // Check that the file's size and modification time are the same
+      // as in the file entry (which may have come from a stat cache).
       if (Diag.isDiagnosticInFlight())
-        Diag.SetDelayedDiagnostic(diag::err_file_modified, 
+        Diag.SetDelayedDiagnostic(diag::err_file_modified,
                                   Entry->getName());
-      else 
-        Diag.Report(diag::err_file_modified) << Entry->getName();
+      else
+        Diag.Report(FullSourceLoc(Loc, SM), diag::err_file_modified)
+          << Entry->getName();
 
       Buffer.setInt(true);
+#endif
+    }
+    
+    // If the buffer is valid, check to see if it has a UTF Byte Order Mark
+    // (BOM).  We only support UTF-8 without a BOM right now.  See
+    // http://en.wikipedia.org/wiki/Byte_order_mark for more information.
+    if (!Buffer.getInt()) {
+      llvm::StringRef BufStr = Buffer.getPointer()->getBuffer();
+      const char *BOM = 0;
+      if (BufStr.startswith("\xFE\xBB\xBF"))
+        BOM = "UTF-8";
+      else if (BufStr.startswith("\xFE\xFF"))
+        BOM = "UTF-16 (BE)";
+      else if (BufStr.startswith("\xFF\xFE"))
+        BOM = "UTF-16 (LE)";
+      else if (BufStr.startswith(llvm::StringRef("\x00\x00\xFE\xFF", 4)))
+        BOM = "UTF-32 (BE)";
+      else if (BufStr.startswith(llvm::StringRef("\xFF\xFE\x00\x00", 4)))
+        BOM = "UTF-32 (LE)";
+      else if (BufStr.startswith("\x2B\x2F\x76"))
+        BOM = "UTF-7";
+      else if (BufStr.startswith("\xF7\x64\x4C"))
+        BOM = "UTF-1";
+      else if (BufStr.startswith("\xDD\x73\x66\x73"))
+        BOM = "UTF-EBCDIC";
+      else if (BufStr.startswith("\x0E\xFE\xFF"))
+        BOM = "SDSU";
+      else if (BufStr.startswith("\xFB\xEE\x28"))
+        BOM = "BOCU-1";
+      else if (BufStr.startswith("\x84\x31\x95\x33"))
+        BOM = "BOCU-1";
+      
+      if (BOM) {
+        Diag.Report(FullSourceLoc(Loc, SM), diag::err_unsupported_bom)
+          << BOM << Entry->getName();
+        Buffer.setInt(1);
+      }
     }
   }
   
@@ -470,7 +517,7 @@ SourceManager::getMemoryBufferForFile(const FileEntry *File,
                                       bool *Invalid) {
   const SrcMgr::ContentCache *IR = getOrCreateContentCache(File);
   assert(IR && "getOrCreateContentCache() cannot return NULL");
-  return IR->getBuffer(Diag, Invalid);
+  return IR->getBuffer(Diag, *this, SourceLocation(), Invalid);
 }
 
 bool SourceManager::overrideFileContents(const FileEntry *SourceFile,
@@ -717,8 +764,8 @@ const char *SourceManager::getCharacterData(SourceLocation SL,
   // Note that calling 'getBuffer()' may lazily page in a source file.
   bool CharDataInvalid = false;
   const llvm::MemoryBuffer *Buffer
-    = getSLocEntry(LocInfo.first).getFile().getContentCache()->getBuffer(Diag, 
-                                                              &CharDataInvalid);
+    = getSLocEntry(LocInfo.first).getFile().getContentCache()
+    ->getBuffer(Diag, *this, SourceLocation(), &CharDataInvalid);
   if (Invalid)
     *Invalid = CharDataInvalid;
   return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second);
@@ -757,14 +804,16 @@ unsigned SourceManager::getInstantiationColumnNumber(SourceLocation Loc,
   return getColumnNumber(LocInfo.first, LocInfo.second, Invalid);
 }
 
-static DISABLE_INLINE void ComputeLineNumbers(Diagnostic &Diag,
-                                              ContentCache* FI,
-                                              llvm::BumpPtrAllocator &Alloc,
-                                              bool &Invalid);
-static void ComputeLineNumbers(Diagnostic &Diag, ContentCache* FI, 
-                               llvm::BumpPtrAllocator &Alloc, bool &Invalid) {
+static DISABLE_INLINE void
+ComputeLineNumbers(Diagnostic &Diag, ContentCache *FI,
+                   llvm::BumpPtrAllocator &Alloc,
+                   const SourceManager &SM, bool &Invalid);
+static void ComputeLineNumbers(Diagnostic &Diag, ContentCache *FI, 
+                               llvm::BumpPtrAllocator &Alloc,
+                               const SourceManager &SM, bool &Invalid) {
   // Note that calling 'getBuffer()' may lazily page in the file.
-  const MemoryBuffer *Buffer = FI->getBuffer(Diag, &Invalid);
+  const MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(),
+                                             &Invalid);
   if (Invalid)
     return;
 
@@ -825,7 +874,7 @@ unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
   /// SourceLineCache for it on demand.
   if (Content->SourceLineCache == 0) {
     bool MyInvalid = false;
-    ComputeLineNumbers(Diag, Content, ContentCacheAlloc, MyInvalid);
+    ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
     if (Invalid)
       *Invalid = MyInvalid;
     if (MyInvalid)
@@ -991,8 +1040,11 @@ PresumedLoc SourceManager::getPresumedLoc(SourceLocation Loc) const {
   // To get the source name, first consult the FileEntry (if one exists)
   // before the MemBuffer as this will avoid unnecessarily paging in the
   // MemBuffer.
-  const char *Filename =
-    C->Entry ? C->Entry->getName() : C->getBuffer(Diag)->getBufferIdentifier();
+  const char *Filename;
+  if (C->Entry)
+    Filename = C->Entry->getName();
+  else
+    Filename = C->getBuffer(Diag, *this)->getBufferIdentifier();
   unsigned LineNo = getLineNumber(LocInfo.first, LocInfo.second);
   unsigned ColNo  = getColumnNumber(LocInfo.first, LocInfo.second);
   SourceLocation IncludeLoc = FI.getIncludeLoc();
@@ -1050,7 +1102,7 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile,
   /// SourceLineCache for it on demand.
   if (Content->SourceLineCache == 0) {
     bool MyInvalid = false;
-    ComputeLineNumbers(Diag, Content, ContentCacheAlloc, MyInvalid);
+    ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid);
     if (MyInvalid)
       return SourceLocation();
   }
@@ -1082,15 +1134,15 @@ SourceLocation SourceManager::getLocation(const FileEntry *SourceFile,
     return SourceLocation();
 
   if (Line > Content->NumLines) {
-    unsigned Size = Content->getBuffer(Diag)->getBufferSize();
+    unsigned Size = Content->getBuffer(Diag, *this)->getBufferSize();
     if (Size > 0)
       --Size;
     return getLocForStartOfFile(FirstFID).getFileLocWithOffset(Size);
   }
 
   unsigned FilePos = Content->SourceLineCache[Line - 1];
-  const char *Buf = Content->getBuffer(Diag)->getBufferStart() + FilePos;
-  unsigned BufLength = Content->getBuffer(Diag)->getBufferEnd() - Buf;
+  const char *Buf = Content->getBuffer(Diag, *this)->getBufferStart() + FilePos;
+  unsigned BufLength = Content->getBuffer(Diag, *this)->getBufferEnd() - Buf;
   unsigned i = 0;
 
   // Check that the given column is valid.
diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
index 136089f..4c0c59a 100644
--- a/lib/Basic/TargetInfo.cpp
+++ b/lib/Basic/TargetInfo.cpp
@@ -20,10 +20,10 @@ using namespace clang;
 
 // TargetInfo Constructor.
 TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
-  // Set defaults.  Defaults are set for a 32-bit RISC platform,
-  // like PPC or SPARC.
-  // These should be overridden by concrete targets as needed.
+  // Set defaults.  Defaults are set for a 32-bit RISC platform, like PPC or
+  // SPARC.  These should be overridden by concrete targets as needed.
   TLSSupported = true;
+  NoAsmVariants = false;
   PointerWidth = PointerAlign = 32;
   IntWidth = IntAlign = 32;
   LongWidth = LongAlign = 32;
@@ -45,6 +45,7 @@ TargetInfo::TargetInfo(const std::string &T) : Triple(T) {
   Char32Type = UnsignedInt;
   Int64Type = SignedLongLong;
   SigAtomicType = SignedInt;
+  UseBitFieldTypeAlignment = true;
   FloatFormat = &llvm::APFloat::IEEEsingle;
   DoubleFormat = &llvm::APFloat::IEEEdouble;
   LongDoubleFormat = &llvm::APFloat::IEEEdouble;
@@ -142,9 +143,10 @@ bool TargetInfo::isTypeSigned(IntType T) const {
 /// Apply changes to the target information with respect to certain
 /// language options which change the target configuration.
 void TargetInfo::setForcedLangOptions(LangOptions &Opts) {
-  if (Opts.ShortWChar) {
+  if (Opts.NoBitFieldTypeAlign)
+    UseBitFieldTypeAlignment = false;
+  if (Opts.ShortWChar)
     WCharType = UnsignedShort;
-  }
 }
 
 //===----------------------------------------------------------------------===//
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index 1797804..3d5048c 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -219,6 +219,8 @@ protected:
     Builder.defineMacro("__ELF__");
     if (Opts.POSIXThreads)
       Builder.defineMacro("_REENTRANT");
+    if (Opts.CPlusPlus)
+      Builder.defineMacro("_GNU_SOURCE");
   }
 public:
   LinuxTargetInfo(const std::string& triple)
@@ -1221,6 +1223,27 @@ public:
     Builder.defineMacro("__CYGWIN__");
     Builder.defineMacro("__CYGWIN32__");
     DefineStd(Builder, "unix", Opts);
+    if (Opts.CPlusPlus)
+      Builder.defineMacro("_GNU_SOURCE");
+  }
+};
+} // end anonymous namespace
+
+namespace {
+// x86-32 Haiku target
+class HaikuX86_32TargetInfo : public X86_32TargetInfo {
+public:
+  HaikuX86_32TargetInfo(const std::string& triple)
+    : X86_32TargetInfo(triple) {
+    SizeType = UnsignedLong;
+    IntPtrType = SignedLong;
+    PtrDiffType = SignedLong;
+  }                                       	
+  virtual void getTargetDefines(const LangOptions &Opts,
+                                MacroBuilder &Builder) const {
+    X86_32TargetInfo::getTargetDefines(Opts, Builder);
+    Builder.defineMacro("__INTEL__");
+    Builder.defineMacro("__HAIKU__");
   }
 };
 } // end anonymous namespace
@@ -1373,6 +1396,10 @@ public:
     SizeType = UnsignedInt;
     PtrDiffType = SignedInt;
 
+    // {} in inline assembly are neon specifiers, not assembly variant
+    // specifiers.
+    NoAsmVariants = true;
+    
     // FIXME: Should we just treat this as a feature?
     IsThumb = getTriple().getArchName().startswith("thumb");
     if (IsThumb) {
@@ -1397,6 +1424,10 @@ public:
       DoubleAlign = LongLongAlign = LongDoubleAlign = 32;
       SizeType = UnsignedLong;
 
+      // Do not respect the alignment of bit-field types when laying out
+      // structures. This corresponds to PCC_BITFIELD_TYPE_MATTERS in gcc.
+      UseBitFieldTypeAlignment = false;
+
       if (IsThumb) {
         DescriptionString = ("e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"
                              "i64:32:32-f32:32:32-f64:32:32-"
@@ -2351,6 +2382,8 @@ static TargetInfo *AllocateTarget(const std::string &T) {
       return new MinGWX86_32TargetInfo(T);
     case llvm::Triple::Win32:
       return new VisualStudioWindowsX86_32TargetInfo(T);
+    case llvm::Triple::Haiku:
+      return new HaikuX86_32TargetInfo(T);
     default:
       return new X86_32TargetInfo(T);
     }
-- 
cgit v1.1