This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by j0le on Mar 2 2020, 6:51 AM.

Details

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.

Diff Detail

Event Timeline

j0le created this revision.Mar 2 2020, 6:51 AM
compnerd requested changes to this revision.Apr 1 2020, 10:01 PM

Seems reasonable, though this isn't UB, its just use of an uninitialized variable.

Please add a test case.

This revision now requires changes to proceed.Apr 1 2020, 10:01 PM
j0le updated this revision to Diff 255354.Apr 6 2020, 8:22 AM

I added a test case.
I hope the folder "clang/tests/Driver" is the right one.

j0le added a comment.Apr 24 2020, 4:48 AM

I would like to ask, whether I could "Accept the Revision" myself, or is this only allowed to be done by code owners or other reviewers?
And when the revision is accepted, do I have to commit this, or can this only be done by people who have commit access or is this done automatically?

Many thanks in advance,
Ole

Please update the title and the summary because those will be the commit message.
IMHO the test a case would be extended with a test where the body of the modified if condition is tested.
Otherwise LGTM.

j0le updated this revision to Diff 260912.Apr 29 2020, 7:47 AM
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. (Show Details)

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.

danielkiss accepted this revision.EditedJun 16 2020, 12:52 AM

Sorry for the delay, it is okay to say "ping" after a while :)
LGTM

j0le added a comment.Jun 22 2020, 1:16 AM

Sorry for the delay, it is okay to say "ping" after a while :)
LGTM

Hi Daniel,
no problem, thanks for comming back to this review after that long time. I will say "ping" next time :)

Can you commit the patch? I don't have commit access.

danielkiss added a comment.EditedJun 22 2020, 3:43 AM

@j0le, I will commit later this week for you.
@compnerd do you have any comment for this version?

@j0le patch is landed but I just realised the review is still blocked by @compnerd. So it won't be closed I think, that is my bad.

https://github.com/llvm/llvm-project/commit/070acb1d1e51ffd289a46b8f93e993635d0053b7

This revision was not accepted when it landed; it landed in state Needs Review.Jul 1 2020, 3:44 AM
This revision was automatically updated to reflect the committed changes.