Skip to content

Commit 6afcd64

Browse files
committed
[GCC] Match a GCC version with a patch suffix without a third version component
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). Differential Revision: https://reviews.llvm.org/D45505 llvm-svn: 330696
1 parent f212460 commit 6afcd64

File tree

6 files changed

+18
-3
lines changed
  • clang
    • lib/Driver/ToolChains
    • test/Driver
      • Inputs/mingw_ubuntu_posix_tree/usr
        • lib/gcc/x86_64-w64-mingw32/5.3-posix
        • x86_64-w64-mingw32/include

6 files changed

+18
-3
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,21 +1594,29 @@ Generic_GCC::GCCVersion Generic_GCC::GCCVersion::Parse(StringRef VersionText) {
15941594
GoodVersion.MajorStr = First.first.str();
15951595
if (First.second.empty())
15961596
return GoodVersion;
1597-
if (Second.first.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
1597+
StringRef MinorStr = Second.first;
1598+
if (Second.second.empty()) {
1599+
if (size_t EndNumber = MinorStr.find_first_not_of("0123456789")) {
1600+
GoodVersion.PatchSuffix = MinorStr.substr(EndNumber);
1601+
MinorStr = MinorStr.slice(0, EndNumber);
1602+
}
1603+
}
1604+
if (MinorStr.getAsInteger(10, GoodVersion.Minor) || GoodVersion.Minor < 0)
15981605
return BadVersion;
1599-
GoodVersion.MinorStr = Second.first.str();
1606+
GoodVersion.MinorStr = MinorStr.str();
16001607

16011608
// First look for a number prefix and parse that if present. Otherwise just
16021609
// stash the entire patch string in the suffix, and leave the number
16031610
// unspecified. This covers versions strings such as:
16041611
// 5 (handled above)
16051612
// 4.4
1613+
// 4.4-patched
16061614
// 4.4.0
16071615
// 4.4.x
16081616
// 4.4.2-rc4
16091617
// 4.4.x-patched
16101618
// And retains any patch number it finds.
1611-
StringRef PatchText = GoodVersion.PatchSuffix = Second.second.str();
1619+
StringRef PatchText = Second.second.str();
16121620
if (!PatchText.empty()) {
16131621
if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
16141622
// Try to parse the number and any suffix.

clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/include-fixed/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/include/c++/backward/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/lib/gcc/x86_64-w64-mingw32/5.3-posix/include/c++/x86_64-w64-mingw32/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/mingw_ubuntu_posix_tree/usr/x86_64-w64-mingw32/include/.keep

Whitespace-only changes.

clang/test/Driver/mingw.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@
4949
// CHECK_MINGW_UBUNTU_TREE: "{{.*}}/Inputs/mingw_ubuntu_tree/usr{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}4.8{{/|\\\\}}x86_64-w64-mingw32"
5050
// CHECK_MINGW_UBUNTU_TREE: "{{.*}}/Inputs/mingw_ubuntu_tree/usr{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}4.8{{/|\\\\}}backward"
5151
// CHECK_MINGW_UBUNTU_TREE: "{{.*}}/Inputs/mingw_ubuntu_tree/usr{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"
52+
53+
54+
// RUN: %clang -target x86_64-pc-windows-gnu -rtlib=platform -stdlib=libstdc++ -c -### --sysroot=%S/Inputs/mingw_ubuntu_posix_tree/usr %s 2>&1 | FileCheck -check-prefix=CHECK_MINGW_UBUNTU_POSIX_TREE %s
55+
// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}5.3-posix{{/|\\\\}}include{{/|\\\\}}c++"
56+
// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}5.3-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}x86_64-w64-mingw32"
57+
// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|\\\\}}lib{{/|\\\\}}gcc{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}5.3-posix{{/|\\\\}}include{{/|\\\\}}c++{{/|\\\\}}backward"
58+
// CHECK_MINGW_UBUNTU_POSIX_TREE: "{{.*}}/Inputs/mingw_ubuntu_posix_tree/usr{{/|\\\\}}x86_64-w64-mingw32{{/|\\\\}}include"

0 commit comments

Comments
 (0)