@@ -32,24 +32,28 @@ using namespace llvm::opt;
3232
3333// Parses the contents of version.txt in an CUDA installation. It should
3434// contain one line of the from e.g. "CUDA Version 7.5.2".
35- static CudaVersion ParseCudaVersionFile (const Driver &D, llvm::StringRef V) {
35+ void CudaInstallationDetector::ParseCudaVersionFile (llvm::StringRef V) {
36+ Version = CudaVersion::UNKNOWN;
3637 if (!V.startswith (" CUDA Version " ))
37- return CudaVersion::UNKNOWN ;
38+ return ;
3839 V = V.substr (strlen (" CUDA Version " ));
3940 SmallVector<StringRef,4 > VersionParts;
4041 V.split (VersionParts, ' .' );
4142 if (VersionParts.size () < 2 )
42- return CudaVersion::UNKNOWN ;
43- std::string MajorMinor = join_items (" ." , VersionParts[0 ], VersionParts[1 ]);
44- CudaVersion Version = CudaStringToVersion (MajorMinor );
43+ return ;
44+ DetectedVersion = join_items (" ." , VersionParts[0 ], VersionParts[1 ]);
45+ Version = CudaStringToVersion (DetectedVersion );
4546 if (Version != CudaVersion::UNKNOWN)
46- return Version ;
47+ return ;
4748
48- // Issue a warning and assume that the version we've found is compatible with
49- // the latest version we support.
50- D.Diag (diag::warn_drv_unknown_cuda_version)
51- << MajorMinor << CudaVersionToString (CudaVersion::LATEST);
52- return CudaVersion::LATEST;
49+ Version = CudaVersion::LATEST;
50+ DetectedVersionIsNotSupported = true ;
51+ }
52+
53+ void CudaInstallationDetector::WarnIfUnsupportedVersion () {
54+ if (DetectedVersionIsNotSupported)
55+ D.Diag (diag::warn_drv_unknown_cuda_version)
56+ << DetectedVersion << CudaVersionToString (Version);
5357}
5458
5559CudaInstallationDetector::CudaInstallationDetector (
@@ -147,7 +151,7 @@ CudaInstallationDetector::CudaInstallationDetector(
147151 // version.txt isn't present.
148152 Version = CudaVersion::CUDA_70;
149153 } else {
150- Version = ParseCudaVersionFile (D, (*VersionFile)->getBuffer ());
154+ ParseCudaVersionFile ((*VersionFile)->getBuffer ());
151155 }
152156
153157 if (Version >= CudaVersion::CUDA_90) {
@@ -565,8 +569,10 @@ CudaToolChain::CudaToolChain(const Driver &D, const llvm::Triple &Triple,
565569 const Action::OffloadKind OK)
566570 : ToolChain(D, Triple, Args), HostTC(HostTC),
567571 CudaInstallation(D, HostTC.getTriple(), Args), OK(OK) {
568- if (CudaInstallation.isValid ())
572+ if (CudaInstallation.isValid ()) {
573+ CudaInstallation.WarnIfUnsupportedVersion ();
569574 getProgramPaths ().push_back (CudaInstallation.getBinPath ());
575+ }
570576 // Lookup binaries into the driver directory, this is used to
571577 // discover the clang-offload-bundler executable.
572578 getProgramPaths ().push_back (getDriver ().Dir );
0 commit comments