]> granicus.if.org Git - clang/commitdiff
[OpenCL] Factor out language version printing
authorSven van Haastregt <sven.vanhaastregt@arm.com>
Tue, 8 May 2018 13:47:43 +0000 (13:47 +0000)
committerSven van Haastregt <sven.vanhaastregt@arm.com>
Tue, 8 May 2018 13:47:43 +0000 (13:47 +0000)
Generate a printable OpenCL language version number in a single place
and select between the OpenCL C or OpenCL C++ version accordingly.

Differential Revision: https://reviews.llvm.org/D46382

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331766 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/LangOptions.h
lib/Basic/LangOptions.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Parse/ParseDecl.cpp

index debf80d1bbfe7026127057b246fe7c541bdd610e..4ebfc8c34632cd7c2a301f4aa8ff45869e40b74d 100644 (file)
@@ -254,6 +254,9 @@ public:
   bool assumeFunctionsAreConvergent() const {
     return (CUDA && CUDAIsDevice) || OpenCL;
   }
+
+  /// \brief Return the OpenCL C or C++ version as a VersionTuple.
+  VersionTuple getOpenCLVersionTuple() const;
 };
 
 /// \brief Floating point control options
index f6b45cbdba2f674a97a1d8a2578f8bebf45d2e5f..763ba33683bcd95db18e26fa6a2768715746f608 100644 (file)
@@ -43,3 +43,8 @@ bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const {
       return true;
   return false;
 }
+
+VersionTuple LangOptions::getOpenCLVersionTuple() const {
+  const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
+  return VersionTuple(Ver / 100, (Ver % 100) / 10);
+}
index cb10706818216d167b62d3e26200e3411ed364c2..0156e75628c006aa715ba4e578ed5eac65219b2e 100644 (file)
@@ -76,7 +76,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Regex.h"
-#include "llvm/Support/ScopedPrinter.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetOptions.h"
 #include <algorithm>
@@ -2157,11 +2156,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
   // this option was added for compatibility with OpenCL 1.0.
   if (Args.getLastArg(OPT_cl_strict_aliasing)
        && Opts.OpenCLVersion > 100) {
-    std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
-                          std::string(".") +
-                          llvm::to_string((Opts.OpenCLVersion % 100) / 10);
     Diags.Report(diag::warn_option_invalid_ocl_version)
-      << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
+        << Opts.getOpenCLVersionTuple().getAsString()
+        << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
   }
 
   // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
index e0948b371705b19f7230958c8e424dc30cf24115..866ca775a7e55107295776309b3d23a4e5671aa1 100644 (file)
@@ -29,7 +29,6 @@
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ScopedPrinter.h"
 
 using namespace clang;
 
@@ -3806,11 +3805,8 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
         Diag(Tok, DiagID)
           << PrevSpec << FixItHint::CreateRemoval(Tok.getLocation());
       else if (DiagID == diag::err_opencl_unknown_type_specifier) {
-        const int OpenCLVer = getLangOpts().OpenCLVersion;
-        std::string VerSpec = llvm::to_string(OpenCLVer / 100) +
-                              std::string (".") +
-                              llvm::to_string((OpenCLVer % 100) / 10);
-        Diag(Tok, DiagID) << VerSpec << PrevSpec << isStorageClass;
+        Diag(Tok, DiagID) << getLangOpts().getOpenCLVersionTuple().getAsString()
+                          << PrevSpec << isStorageClass;
       } else
         Diag(Tok, DiagID) << PrevSpec;
     }