[PATCH] D45505: [WIP] [GCC] Match a GCC version with a patch suffix without a third version component

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 10 13:58:38 PDT 2018


mstorsjo created this revision.
mstorsjo added reviewers: chandlerc, martell, ismail, rnk, compnerd, mati865, yaron.keren.

Previously it would only accept a string as a GCC version if it had either two components and no suffix, or three components with an optional suffix.

Debian and ubuntu provided mingw compilers have lib/gcc/target entries like "5.3-posix" and "5.3-win32". This doesn't try to make any specific preference between them (other than lexical sorting of the suffix).

Tests are missing though; I guess the neatest thing for this would be a unit test? Is the ToolChains internal header Gnu.h testable from the unittests directory? OTOH I could just do a simple driver based test with a dummy directory structure.


Repository:
  rC Clang

https://reviews.llvm.org/D45505

Files:
  lib/Driver/ToolChains/Gnu.cpp


Index: lib/Driver/ToolChains/Gnu.cpp
===================================================================
--- lib/Driver/ToolChains/Gnu.cpp
+++ lib/Driver/ToolChains/Gnu.cpp
@@ -1615,21 +1615,29 @@
   GoodVersion.MajorStr = First.first.str();
   if (First.second.empty())
     return GoodVersion;
-  if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
+  StringRef MinorStr = Second.first;
+  if (Second.second.empty()) {
+    if (size_t EndNumber = MinorStr.find_first_not_of("0123456789")) {
+      GoodVersion.PatchSuffix = MinorStr.substr(EndNumber);
+      MinorStr = MinorStr.slice(0, EndNumber);
+    }
+  }
+  if (MinorStr.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
     return BadVersion;
-  GoodVersion.MinorStr = Second.first.str();
+  GoodVersion.MinorStr = MinorStr.str();
 
   // First look for a number prefix and parse that if present. Otherwise just
   // stash the entire patch string in the suffix, and leave the number
   // unspecified. This covers versions strings such as:
   //   5        (handled above)
   //   4.4
+  //   4.4-patched
   //   4.4.0
   //   4.4.x
   //   4.4.2-rc4
   //   4.4.x-patched
   // And retains any patch number it finds.
-  StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str();
+  StringRef PatchText = Second.second.str();
   if (!PatchText.empty()) {
     if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
       // Try to parse the number and any suffix.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45505.141907.patch
Type: text/x-patch
Size: 1489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180410/15147e46/attachment.bin>


More information about the cfe-commits mailing list