[Driver][ARM] parse version of arm/thumb architecture correctly
authorDaniel Kiss <daniel.kiss@arm.com>
Wed, 1 Jul 2020 09:15:52 +0000 (11:15 +0200)
committerDaniel Kiss <daniel.kiss@arm.com>
Wed, 1 Jul 2020 10:13:52 +0000 (12:13 +0200)
commit070acb1d1e51ffd289a46b8f93e993635d0053b7
tree22cf82ad51feca0a959fc3ee8a73fa334cde7e50
parent8180a399652a3896239b2b4e8730f8141a78a72e
[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
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/windows-thumbv7em.cpp [new file with mode: 0644]