From 486b1da7657de73c8d47f876fdcf1e2d8dbf81ee Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Tue, 18 Oct 2011 17:37:18 +0000 Subject: [PATCH] Fix the way clang retrieves the major FreeBSD release number from the target triple, so that the __FreeBSD__ and __FreeBSD_cc_version builtin macros return the expected results. Spotted by: nalitoja at gmail.com --- contrib/llvm/tools/clang/lib/Basic/Targets.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/contrib/llvm/tools/clang/lib/Basic/Targets.cpp b/contrib/llvm/tools/clang/lib/Basic/Targets.cpp index 3518ea6f7986..6434d69241c6 100644 --- a/contrib/llvm/tools/clang/lib/Basic/Targets.cpp +++ b/contrib/llvm/tools/clang/lib/Basic/Targets.cpp @@ -238,11 +238,12 @@ class FreeBSDTargetInfo : public OSTargetInfo { MacroBuilder &Builder) const { // FreeBSD defines; list based off of gcc output - // FIXME: Move version number handling to llvm::Triple. - llvm::StringRef Release = Triple.getOSName().substr(strlen("freebsd"), 1); + unsigned Release = Triple.getOSMajorVersion(); + if (Release == 0U) + Release = 8U; - Builder.defineMacro("__FreeBSD__", Release); - Builder.defineMacro("__FreeBSD_cc_version", Release + "00001"); + Builder.defineMacro("__FreeBSD__", Twine(Release)); + Builder.defineMacro("__FreeBSD_cc_version", Twine(Release * 100000U + 1U)); Builder.defineMacro("__KPRINTF_ATTRIBUTE__"); DefineStd(Builder, "unix", Opts); Builder.defineMacro("__ELF__");