diff options
Diffstat (limited to 'lib/Basic')
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 219 | ||||
-rw-r--r-- | lib/Basic/IdentifierTable.cpp | 4 | ||||
-rw-r--r-- | lib/Basic/Makefile | 1 | ||||
-rw-r--r-- | lib/Basic/SourceManager.cpp | 10 | ||||
-rw-r--r-- | lib/Basic/TargetInfo.cpp | 39 | ||||
-rw-r--r-- | lib/Basic/Targets.cpp | 157 | ||||
-rw-r--r-- | lib/Basic/Version.cpp | 78 |
7 files changed, 361 insertions, 147 deletions
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index abbf6f9..094f776 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -21,8 +21,10 @@ #include "clang/Analysis/AnalysisDiagnostic.h" #include "clang/Driver/DriverDiagnostic.h" +#include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" @@ -385,6 +387,123 @@ Diagnostic::getDiagnosticLevel(unsigned DiagID, unsigned DiagClass) const { return Result; } +static bool ReadUnsigned(const char *&Memory, const char *MemoryEnd, + unsigned &Value) { + if (Memory + sizeof(unsigned) > MemoryEnd) + return true; + + memmove(&Value, Memory, sizeof(unsigned)); + Memory += sizeof(unsigned); + return false; +} + +static bool ReadSourceLocation(FileManager &FM, SourceManager &SM, + const char *&Memory, const char *MemoryEnd, + SourceLocation &Location) { + // Read the filename. + unsigned FileNameLen = 0; + if (ReadUnsigned(Memory, MemoryEnd, FileNameLen) || + Memory + FileNameLen > MemoryEnd) + return true; + + llvm::StringRef FileName(Memory, FileNameLen); + Memory += FileNameLen; + + // Read the line, column. + unsigned Line = 0, Column = 0; + if (ReadUnsigned(Memory, MemoryEnd, Line) || + ReadUnsigned(Memory, MemoryEnd, Column)) + return true; + + if (FileName.empty()) { + Location = SourceLocation(); + return false; + } + + const FileEntry *File = FM.getFile(FileName); + if (!File) + return true; + + // Make sure that this file has an entry in the source manager. + if (!SM.hasFileInfo(File)) + SM.createFileID(File, SourceLocation(), SrcMgr::C_User); + + Location = SM.getLocation(File, Line, Column); + return false; +} + +DiagnosticBuilder Diagnostic::Deserialize(FileManager &FM, SourceManager &SM, + const char *&Memory, + const char *MemoryEnd) { + if (Memory == MemoryEnd) + return DiagnosticBuilder(0); + + // Read the severity level. + unsigned Level = 0; + if (ReadUnsigned(Memory, MemoryEnd, Level) || Level > Fatal) + return DiagnosticBuilder(0); + + // Read the source location. + SourceLocation Location; + if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Location)) + return DiagnosticBuilder(0); + + // Read the diagnostic text. + if (Memory == MemoryEnd) + return DiagnosticBuilder(0); + + unsigned MessageLen = 0; + if (ReadUnsigned(Memory, MemoryEnd, MessageLen) || + Memory + MessageLen > MemoryEnd) + return DiagnosticBuilder(0); + + llvm::StringRef Message(Memory, MessageLen); + Memory += MessageLen; + + // At this point, we have enough information to form a diagnostic. Do so. + unsigned DiagID = getCustomDiagID((enum Level)Level, Message); + DiagnosticBuilder DB = Report(FullSourceLoc(Location, SM), DiagID); + if (Memory == MemoryEnd) + return DB; + + // Read the source ranges. + unsigned NumSourceRanges = 0; + if (ReadUnsigned(Memory, MemoryEnd, NumSourceRanges)) + return DB; + for (unsigned I = 0; I != NumSourceRanges; ++I) { + SourceLocation Begin, End; + if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, Begin) || + ReadSourceLocation(FM, SM, Memory, MemoryEnd, End)) + return DB; + + DB << SourceRange(Begin, End); + } + + // Read the fix-it hints. + unsigned NumFixIts = 0; + if (ReadUnsigned(Memory, MemoryEnd, NumFixIts)) + return DB; + for (unsigned I = 0; I != NumFixIts; ++I) { + SourceLocation RemoveBegin, RemoveEnd, InsertionLoc; + unsigned InsertLen = 0; + if (ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveBegin) || + ReadSourceLocation(FM, SM, Memory, MemoryEnd, RemoveEnd) || + ReadSourceLocation(FM, SM, Memory, MemoryEnd, InsertionLoc) || + ReadUnsigned(Memory, MemoryEnd, InsertLen) || + Memory + InsertLen > MemoryEnd) + return DB; + + CodeModificationHint Hint; + Hint.RemoveRange = SourceRange(RemoveBegin, RemoveEnd); + Hint.InsertionLoc = InsertionLoc; + Hint.CodeToInsert.assign(Memory, Memory + InsertLen); + Memory += InsertLen; + DB << Hint; + } + + return DB; +} + struct WarningOption { const char *Name; const short *Members; @@ -510,7 +629,7 @@ bool Diagnostic::ProcessDiag() { // it. if (SuppressSystemWarnings && !ShouldEmitInSystemHeader && Info.getLocation().isValid() && - Info.getLocation().getSpellingLoc().isInSystemHeader() && + Info.getLocation().getInstantiationLoc().isInSystemHeader() && (DiagLevel != Diagnostic::Note || LastDiagLevel == Diagnostic::Ignored)) { LastDiagLevel = Diagnostic::Ignored; return false; @@ -917,6 +1036,104 @@ FormatDiagnostic(const char *DiagStr, const char *DiagEnd, } } +static void WriteUnsigned(llvm::raw_ostream &OS, unsigned Value) { + OS.write((const char *)&Value, sizeof(unsigned)); +} + +static void WriteString(llvm::raw_ostream &OS, llvm::StringRef String) { + WriteUnsigned(OS, String.size()); + OS.write(String.data(), String.size()); +} + +static void WriteSourceLocation(llvm::raw_ostream &OS, + SourceManager *SM, + SourceLocation Location) { + if (!SM || Location.isInvalid()) { + // If we don't have a source manager or this location is invalid, + // just write an invalid location. + WriteUnsigned(OS, 0); + WriteUnsigned(OS, 0); + WriteUnsigned(OS, 0); + return; + } + + Location = SM->getInstantiationLoc(Location); + std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location); + + WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName()); + WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second)); + WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second)); +} + +void DiagnosticInfo::Serialize(Diagnostic::Level DiagLevel, + llvm::raw_ostream &OS) const { + SourceManager *SM = 0; + if (getLocation().isValid()) + SM = &const_cast<SourceManager &>(getLocation().getManager()); + + // Write the diagnostic level and location. + WriteUnsigned(OS, (unsigned)DiagLevel); + WriteSourceLocation(OS, SM, getLocation()); + + // Write the diagnostic message. + llvm::SmallString<64> Message; + FormatDiagnostic(Message); + WriteString(OS, Message); + + // Count the number of ranges that don't point into macros, since + // only simple file ranges serialize well. + unsigned NumNonMacroRanges = 0; + for (unsigned I = 0, N = getNumRanges(); I != N; ++I) { + SourceRange R = getRange(I); + if (R.getBegin().isMacroID() || R.getEnd().isMacroID()) + continue; + + ++NumNonMacroRanges; + } + + // Write the ranges. + WriteUnsigned(OS, NumNonMacroRanges); + if (NumNonMacroRanges) { + for (unsigned I = 0, N = getNumRanges(); I != N; ++I) { + SourceRange R = getRange(I); + if (R.getBegin().isMacroID() || R.getEnd().isMacroID()) + continue; + + WriteSourceLocation(OS, SM, R.getBegin()); + WriteSourceLocation(OS, SM, R.getEnd()); + } + } + + // Determine if all of the fix-its involve rewrites with simple file + // locations (not in macro instantiations). If so, we can write + // fix-it information. + unsigned NumFixIts = getNumCodeModificationHints(); + for (unsigned I = 0; I != NumFixIts; ++I) { + const CodeModificationHint &Hint = getCodeModificationHint(I); + if (Hint.RemoveRange.isValid() && + (Hint.RemoveRange.getBegin().isMacroID() || + Hint.RemoveRange.getEnd().isMacroID())) { + NumFixIts = 0; + break; + } + + if (Hint.InsertionLoc.isValid() && Hint.InsertionLoc.isMacroID()) { + NumFixIts = 0; + break; + } + } + + // Write the fix-its. + WriteUnsigned(OS, NumFixIts); + for (unsigned I = 0; I != NumFixIts; ++I) { + const CodeModificationHint &Hint = getCodeModificationHint(I); + WriteSourceLocation(OS, SM, Hint.RemoveRange.getBegin()); + WriteSourceLocation(OS, SM, Hint.RemoveRange.getEnd()); + WriteSourceLocation(OS, SM, Hint.InsertionLoc); + WriteString(OS, Hint.CodeToInsert); + } +} + /// IncludeInDiagnosticCounts - This method (whose default implementation /// returns true) indicates whether the diagnostics handled by this /// DiagnosticClient should be included in the number of diagnostics diff --git a/lib/Basic/IdentifierTable.cpp b/lib/Basic/IdentifierTable.cpp index 401e6cb..16a61b7 100644 --- a/lib/Basic/IdentifierTable.cpp +++ b/lib/Basic/IdentifierTable.cpp @@ -68,7 +68,8 @@ namespace { KEYCXX0X = 8, KEYGNU = 16, KEYMS = 32, - BOOLSUPPORT = 64 + BOOLSUPPORT = 64, + KEYALTIVEC = 128 }; } @@ -91,6 +92,7 @@ static void AddKeyword(const char *Keyword, unsigned KWLen, else if (LangOpts.GNUMode && (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; // Don't add this keyword if disabled in this language. if (AddResult == 0) return; diff --git a/lib/Basic/Makefile b/lib/Basic/Makefile index f733578..58ac7eb 100644 --- a/lib/Basic/Makefile +++ b/lib/Basic/Makefile @@ -14,7 +14,6 @@ LEVEL = ../../../.. LIBRARYNAME := clangBasic BUILD_ARCHIVE = 1 -CXXFLAGS = -fno-rtti CPPFLAGS += -I$(PROJ_SRC_DIR)/../../include -I$(PROJ_OBJ_DIR)/../../include ifdef CLANG_VENDOR diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 354bf7b..b91671a 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -560,10 +560,14 @@ FileID SourceManager::getFileIDSlow(unsigned SLocOffset) const { SourceLocation SourceManager:: getInstantiationLocSlowCase(SourceLocation Loc) const { do { - std::pair<FileID, unsigned> LocInfo = getDecomposedLoc(Loc); - Loc = getSLocEntry(LocInfo.first).getInstantiation() + // Note: If Loc indicates an offset into a token that came from a macro + // expansion (e.g. the 5th character of the token) we do not want to add + // this offset when going to the instantiation location. The instatiation + // location is the macro invocation, which the offset has nothing to do + // with. This is unlike when we get the spelling loc, because the offset + // directly correspond to the token whose spelling we're inspecting. + Loc = getSLocEntry(getFileID(Loc)).getInstantiation() .getInstantiationLocStart(); - Loc = Loc.getFileLocWithOffset(LocInfo.second); } while (!Loc.isFileID()); return Loc; diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index 493beee..136089f 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -150,39 +150,41 @@ void TargetInfo::setForcedLangOptions(LangOptions &Opts) { //===----------------------------------------------------------------------===// -static void removeGCCRegisterPrefix(const char *&Name) { +static llvm::StringRef removeGCCRegisterPrefix(llvm::StringRef Name) { if (Name[0] == '%' || Name[0] == '#') - Name++; + Name = Name.substr(1); + + return Name; } /// isValidGCCRegisterName - Returns whether the passed in string /// is a valid register name according to GCC. This is used by Sema for /// inline asm statements. -bool TargetInfo::isValidGCCRegisterName(const char *Name) const { +bool TargetInfo::isValidGCCRegisterName(llvm::StringRef Name) const { + if (Name.empty()) + return false; + const char * const *Names; unsigned NumNames; // Get rid of any register prefix. - removeGCCRegisterPrefix(Name); + Name = removeGCCRegisterPrefix(Name); - - if (strcmp(Name, "memory") == 0 || - strcmp(Name, "cc") == 0) + if (Name == "memory" || Name == "cc") return true; getGCCRegNames(Names, NumNames); // If we have a number it maps to an entry in the register name array. if (isdigit(Name[0])) { - char *End; - int n = (int)strtol(Name, &End, 0); - if (*End == 0) + int n; + if (!Name.getAsInteger(0, n)) return n >= 0 && (unsigned)n < NumNames; } // Check register names. for (unsigned i = 0; i < NumNames; i++) { - if (strcmp(Name, Names[i]) == 0) + if (Name == Names[i]) return true; } @@ -195,7 +197,7 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) break; - if (strcmp(Aliases[i].Aliases[j], Name) == 0) + if (Aliases[i].Aliases[j] == Name) return true; } } @@ -203,10 +205,12 @@ bool TargetInfo::isValidGCCRegisterName(const char *Name) const { return false; } -const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const { +llvm::StringRef +TargetInfo::getNormalizedGCCRegisterName(llvm::StringRef Name) const { assert(isValidGCCRegisterName(Name) && "Invalid register passed in"); - removeGCCRegisterPrefix(Name); + // Get rid of any register prefix. + Name = removeGCCRegisterPrefix(Name); const char * const *Names; unsigned NumNames; @@ -215,9 +219,8 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const { // First, check if we have a number. if (isdigit(Name[0])) { - char *End; - int n = (int)strtol(Name, &End, 0); - if (*End == 0) { + int n; + if (!Name.getAsInteger(0, n)) { assert(n >= 0 && (unsigned)n < NumNames && "Out of bounds register number!"); return Names[n]; @@ -233,7 +236,7 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const { for (unsigned j = 0 ; j < llvm::array_lengthof(Aliases[i].Aliases); j++) { if (!Aliases[i].Aliases[j]) break; - if (strcmp(Aliases[i].Aliases[j], Name) == 0) + if (Aliases[i].Aliases[j] == Name) return Aliases[i].Register; } } diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index ea076ae..c1cd96e 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -74,7 +74,8 @@ public: } // end anonymous namespace -static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts) { +static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts, + const llvm::Triple &Triple) { Builder.defineMacro("__APPLE_CC__", "5621"); Builder.defineMacro("__APPLE__"); Builder.defineMacro("__MACH__"); @@ -96,51 +97,45 @@ static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts) { if (Opts.POSIXThreads) Builder.defineMacro("_REENTRANT"); -} - -static void getDarwinOSXDefines(MacroBuilder &Builder, - const llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) - return; - - // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. - unsigned Maj, Min, Rev; - Triple.getDarwinNumber(Maj, Min, Rev); - - char MacOSXStr[] = "1000"; - if (Maj >= 4 && Maj <= 13) { // 10.0-10.9 - // darwin7 -> 1030, darwin8 -> 1040, darwin9 -> 1050, etc. - MacOSXStr[2] = '0' + Maj-4; - } - - // Handle minor version: 10.4.9 -> darwin8.9 -> "1049" - // Cap 10.4.11 -> darwin8.11 -> "1049" - MacOSXStr[3] = std::min(Min, 9U)+'0'; - Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", - MacOSXStr); -} - -static void getDarwinIPhoneOSDefines(MacroBuilder &Builder, - const llvm::Triple &Triple) { - if (Triple.getOS() != llvm::Triple::Darwin) - return; - // Figure out which "darwin number" the target triple is. "darwin9" -> 10.5. + // Get the OS version number from the triple. unsigned Maj, Min, Rev; - Triple.getDarwinNumber(Maj, Min, Rev); - // When targetting iPhone OS, interpret the minor version and - // revision as the iPhone OS version - char iPhoneOSStr[] = "10000"; - if (Min >= 2 && Min <= 9) { // iPhone OS 2.0-9.0 - // darwin9.2.0 -> 20000, darwin9.3.0 -> 30000, etc. - iPhoneOSStr[0] = '0' + Min; + // If no version was given, default to to 10.4.0, for simplifying tests. + if (Triple.getOSName() == "darwin") { + Min = Rev = 0; + Maj = 8; + } else + Triple.getDarwinNumber(Maj, Min, Rev); + + // Set the appropriate OS version define. + if (Triple.getEnvironmentName() == "iphoneos") { + assert(Maj < 10 && Min < 99 && Rev < 99 && "Invalid version!"); + char Str[6]; + Str[0] = '0' + Maj; + Str[1] = '0' + (Min / 10); + Str[2] = '0' + (Min % 10); + Str[3] = '0' + (Rev / 10); + Str[4] = '0' + (Rev % 10); + Str[5] = '\0'; + Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", Str); + } else { + // For historical reasons that make little sense, the version passed here is + // the "darwin" version, which drops the 10 and offsets by 4. + Rev = Min; + Min = Maj - 4; + Maj = 10; + + assert(Triple.getEnvironmentName().empty() && "Invalid environment!"); + assert(Maj < 99 && Min < 10 && Rev < 10 && "Invalid version!"); + char Str[5]; + Str[0] = '0' + (Maj / 10); + Str[1] = '0' + (Maj % 10); + Str[2] = '0' + Min; + Str[3] = '0' + Rev; + Str[4] = '\0'; + Builder.defineMacro("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__", Str); } - - // Handle minor version: 2.2 -> darwin9.2.2 -> 20200 - iPhoneOSStr[2] = std::min(Rev, 9U)+'0'; - Builder.defineMacro("__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__", - iPhoneOSStr); } namespace { @@ -149,8 +144,7 @@ class DarwinTargetInfo : public OSTargetInfo<Target> { protected: virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const { - getDarwinDefines(Builder, Opts); - getDarwinOSXDefines(Builder, Triple); + getDarwinDefines(Builder, Opts, Triple); } public: @@ -159,11 +153,7 @@ public: this->TLSSupported = false; } - virtual const char *getUnicodeStringSection() const { - return "__TEXT,__ustring"; - } - - virtual std::string isValidSectionSpecifier(const llvm::StringRef &SR) const { + virtual std::string isValidSectionSpecifier(llvm::StringRef SR) const { // Let MCSectionMachO validate this. llvm::StringRef Segment, Section; unsigned TAA, StubSize; @@ -201,16 +191,10 @@ protected: // FreeBSD defines; list based off of gcc output // FIXME: Move version number handling to llvm::Triple. - const char *FreeBSD = strstr(Triple.getTriple().c_str(), - "-freebsd"); - FreeBSD += strlen("-freebsd"); - char release[] = "X"; - release[0] = FreeBSD[0]; - char version[] = "X00001"; - version[0] = FreeBSD[0]; - - Builder.defineMacro("__FreeBSD__", release); - Builder.defineMacro("__FreeBSD_cc_version", version); + llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1); + + Builder.defineMacro("__FreeBSD__", Release); + Builder.defineMacro("__FreeBSD_cc_version", Release + "00001"); Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); DefineStd(Builder, "unix", Opts); Builder.defineMacro("__ELF__"); @@ -643,9 +627,13 @@ class X86TargetInfo : public TargetInfo { enum X86SSEEnum { NoMMXSSE, MMX, SSE1, SSE2, SSE3, SSSE3, SSE41, SSE42 } SSELevel; + enum AMD3DNowEnum { + NoAMD3DNow, AMD3DNow, AMD3DNowAthlon + } AMD3DNowLevel; + public: X86TargetInfo(const std::string& triple) - : TargetInfo(triple), SSELevel(NoMMXSSE) { + : TargetInfo(triple), SSELevel(NoMMXSSE), AMD3DNowLevel(NoAMD3DNow) { LongDoubleFormat = &llvm::APFloat::x87DoubleExtended; } virtual void getTargetBuiltins(const Builtin::Info *&Records, @@ -810,6 +798,14 @@ void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) { .Case("mmx", MMX) .Default(NoMMXSSE); SSELevel = std::max(SSELevel, Level); + + AMD3DNowEnum ThreeDNowLevel = + llvm::StringSwitch<AMD3DNowEnum>(Features[i].substr(1)) + .Case("3dnowa", AMD3DNowAthlon) + .Case("3dnow", AMD3DNow) + .Default(NoAMD3DNow); + + AMD3DNowLevel = std::max(AMD3DNowLevel, ThreeDNowLevel); } } @@ -864,6 +860,16 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts, case NoMMXSSE: break; } + + // Each case falls through to the previous one here. + switch (AMD3DNowLevel) { + case AMD3DNowAthlon: + Builder.defineMacro("__3dNOW_A__"); + case AMD3DNow: + Builder.defineMacro("__3dNOW__"); + case NoAMD3DNow: + break; + } } @@ -1224,7 +1230,7 @@ public: // FIXME: We need support for -meabi... we could just mangle it into the // name. if (Name == "apcs-gnu") { - DoubleAlign = LongLongAlign = 32; + DoubleAlign = LongLongAlign = LongDoubleAlign = 32; SizeType = UnsignedLong; if (IsThumb) { @@ -1379,9 +1385,6 @@ public: // when Neon instructions are actually available. if (FPU == NeonFPU && !SoftFloat && IsThumb2) Builder.defineMacro("__ARM_NEON__"); - - if (getTriple().getOS() == llvm::Triple::Darwin) - Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__"); } virtual void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) const { @@ -1461,8 +1464,7 @@ class DarwinARMTargetInfo : protected: virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, MacroBuilder &Builder) const { - getDarwinDefines(Builder, Opts); - getDarwinIPhoneOSDefines(Builder, Triple); + getDarwinDefines(Builder, Opts, Triple); } public: @@ -1617,23 +1619,25 @@ namespace { virtual void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const { Builder.defineMacro("__pic16"); + Builder.defineMacro("__PIC16"); Builder.defineMacro("rom", "__attribute__((address_space(1)))"); Builder.defineMacro("ram", "__attribute__((address_space(0)))"); - Builder.defineMacro("_section(SectName)", + Builder.defineMacro("__section(SectName)", "__attribute__((section(SectName)))"); Builder.defineMacro("near", "__attribute__((section(\"Address=NEAR\")))"); - Builder.defineMacro("_address(Addr)", + Builder.defineMacro("__address(Addr)", "__attribute__((section(\"Address=\"#Addr)))"); - Builder.defineMacro("_CONFIG(conf)", "asm(\"CONFIG \"#conf)"); - Builder.defineMacro("_interrupt", + Builder.defineMacro("__config(conf)", "asm(\"CONFIG \"#conf)"); + Builder.defineMacro("__idlocs(value)", "asm(\"__IDLOCS \"#value)"); + Builder.defineMacro("interrupt", "__attribute__((section(\"interrupt=0x4\"))) \ __attribute__((used))"); } virtual void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) const {} virtual const char *getVAListDeclaration() const { - return ""; + return "typedef char* __builtin_va_list;"; } virtual const char *getClobbers() const { return ""; @@ -1656,13 +1660,10 @@ namespace { public: MSP430TargetInfo(const std::string& triple) : TargetInfo(triple) { TLSSupported = false; - IntWidth = 16; - LongWidth = 32; - LongLongWidth = 64; - PointerWidth = 16; - IntAlign = 8; - LongAlign = LongLongAlign = 8; - PointerAlign = 8; + IntWidth = 16; IntAlign = 16; + LongWidth = 32; LongLongWidth = 64; + LongAlign = LongLongAlign = 16; + PointerWidth = 16; PointerAlign = 16; SizeType = UnsignedInt; IntMaxType = SignedLong; UIntMaxType = UnsignedLong; diff --git a/lib/Basic/Version.cpp b/lib/Basic/Version.cpp index b1b250f..98cf42b 100644 --- a/lib/Basic/Version.cpp +++ b/lib/Basic/Version.cpp @@ -21,67 +21,55 @@ using namespace std; namespace clang { llvm::StringRef getClangRepositoryPath() { - static const char *Path = 0; - if (Path) - return Path; - - static char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"; - char *End = strstr(URL, "/lib/Basic"); + static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"; + const char *URLEnd = URL + strlen(URL); + + const char *End = strstr(URL, "/lib/Basic"); if (End) - *End = 0; - + URLEnd = End; + End = strstr(URL, "/clang/tools/clang"); if (End) - *End = 0; - - char *Begin = strstr(URL, "cfe/"); - if (Begin) { - Path = Begin + 4; - return Path; - } - - Path = URL; - return Path; -} + URLEnd = End; + + const char *Begin = strstr(URL, "cfe/"); + if (Begin) + return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); + return llvm::StringRef(URL, URLEnd - URL); +} -llvm::StringRef getClangRevision() { +std::string getClangRevision() { #ifndef SVN_REVISION // Subversion was not available at build time? - return llvm::StringRef(); + return ""; #else - static std::string revision; - if (revision.empty()) { - llvm::raw_string_ostream OS(revision); - OS << strtol(SVN_REVISION, 0, 10); - } + std::string revision; + llvm::raw_string_ostream OS(revision); + OS << strtol(SVN_REVISION, 0, 10); return revision; #endif } -llvm::StringRef getClangFullRepositoryVersion() { - static std::string buf; - if (buf.empty()) { - llvm::raw_string_ostream OS(buf); - OS << getClangRepositoryPath(); - llvm::StringRef Revision = getClangRevision(); - if (!Revision.empty()) - OS << ' ' << Revision; - } +std::string getClangFullRepositoryVersion() { + std::string buf; + llvm::raw_string_ostream OS(buf); + OS << getClangRepositoryPath(); + const std::string &Revision = getClangRevision(); + if (!Revision.empty()) + OS << ' ' << Revision; return buf; } -const char *getClangFullVersion() { - static std::string buf; - if (buf.empty()) { - llvm::raw_string_ostream OS(buf); +std::string getClangFullVersion() { + std::string buf; + llvm::raw_string_ostream OS(buf); #ifdef CLANG_VENDOR - OS << CLANG_VENDOR; + OS << CLANG_VENDOR; #endif - OS << "clang version " CLANG_VERSION_STRING " (" - << getClangFullRepositoryVersion() << ')'; - } - return buf.c_str(); + OS << "clang version " CLANG_VERSION_STRING " (" + << getClangFullRepositoryVersion() << ')'; + return buf; } - + } // end namespace clang |