forked from OSchip/llvm-project
[Driver][ARM] parse version of arm/thumb architecture correctly
Summary: If you execute the following commandline multiple times, the behavior was not always the same: clang++ --target=thumbv7em-none-windows-eabi-coff -march=armv7-m -mcpu=cortex-m7 -o temp.obj -c -x c++ empty.cpp Most of the time the compilation succeeded, but sometimes clang reported this error: clang++: error: the target architecture 'thumbv7em' is not supported by the target 'thumbv7em-none-windows-eabi' The cause of the inconsistent behavior was the uninitialized variable Version. With these commandline arguments, the variable Version was not set by getAsInteger(), because it cannot parse a number from the substring "7em" (of "thumbv7em"). To get a consistent behaviour, it's enough to initialize the variable Version to zero. Zero is smaller than 7, so the comparison will be true. Then the command always fails with the error message seen above. By using consumeInteger() instead of getAsInteger() we get 7 from the substring "7em" and the command does not fail. Reviewers: compnerd, danielkiss Reviewed By: danielkiss Subscribers: danielkiss, kristof.beyls, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D75453
This commit is contained in:
parent
8180a39965
commit
070acb1d1e
|
@ -4041,9 +4041,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
|
Loading…
Reference in New Issue