HomePhabricator

[Driver][ARM] parse version of arm/thumb architecture correctly

Authored by danielkiss on Jul 1 2020, 2:15 AM.

Description

[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

Details

Committed
danielkissJul 1 2020, 3:13 AM
Reviewer
danielkiss
Differential Revision
D75453: [Driver][ARM] parse version of arm/thumb architecture correctly
Parents
rG8180a399652a: [StackSafety,NFC] Remove expensive assert
Branches
Unknown
Tags
Unknown