j0le updated this revision to Diff 260912. j0le retitled this revision from "[Driver][ARM] fix undefined behaviour when checking architecture version" to "[Driver][ARM] parse version of arm/thumb architecture correctly". j0le edited the summary of this revision. j0le added a comment.
Changed title and summary to not contain the phrase "undefined behaviour". Extended the test case with a test, that passes the argument "-mcpu=cortex-m1" to clang, which causes the architecture part of the triple to become "thumbv6m". This tests the body of the if statement. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D75453/new/ https://reviews.llvm.org/D75453 Files: clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/windows-thumbv7em.cpp Index: clang/test/Driver/windows-thumbv7em.cpp =================================================================== --- /dev/null +++ clang/test/Driver/windows-thumbv7em.cpp @@ -0,0 +1,8 @@ +// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m7 -### -c %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-V7 +// CHECK-V7-NOT: error: the target architecture 'thumbv7em' is not supported by the target 'thumbv7em-none-windows-eabi' + +// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m1 -### -c %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-V6 +// CHECK-V6: error: the target architecture 'thumbv6m' is not supported by the target 'thumbv6m-none-windows-eabi' + Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4090,9 +4090,10 @@ if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm || Triple.getArch() == llvm::Triple::thumb)) { unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6; - unsigned Version; - Triple.getArchName().substr(Offset).getAsInteger(10, Version); - if (Version < 7) + unsigned Version = 0; + bool Failure = + Triple.getArchName().substr(Offset).consumeInteger(10, Version); + if (Failure || Version < 7) D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() << TripleStr; }
Index: clang/test/Driver/windows-thumbv7em.cpp =================================================================== --- /dev/null +++ clang/test/Driver/windows-thumbv7em.cpp @@ -0,0 +1,8 @@ +// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m7 -### -c %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-V7 +// CHECK-V7-NOT: error: the target architecture 'thumbv7em' is not supported by the target 'thumbv7em-none-windows-eabi' + +// RUN: %clang -target thumb-none-windows-eabi-coff -mcpu=cortex-m1 -### -c %s 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-V6 +// CHECK-V6: error: the target architecture 'thumbv6m' is not supported by the target 'thumbv6m-none-windows-eabi' + Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4090,9 +4090,10 @@ if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm || Triple.getArch() == llvm::Triple::thumb)) { unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6; - unsigned Version; - Triple.getArchName().substr(Offset).getAsInteger(10, Version); - if (Version < 7) + unsigned Version = 0; + bool Failure = + Triple.getArchName().substr(Offset).consumeInteger(10, Version); + if (Failure || Version < 7) D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName() << TripleStr; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits