This is an archive of the discontinued LLVM Phabricator instance.

[libc] add atoi, atol, and atoll
ClosedPublic

Authored by michaelrj on Aug 18 2021, 2:35 PM.

Details

Summary

This is based on the work done to add strtoll and the other strto
functions. The atoi functions also were added to stdc and
entrypoints.txt.

Diff Detail

Event Timeline

michaelrj created this revision.Aug 18 2021, 2:35 PM
michaelrj requested review of this revision.Aug 18 2021, 2:35 PM
sivachandra accepted this revision.Aug 18 2021, 4:39 PM
sivachandra added inline comments.
libc/test/src/stdlib/atol_test.cpp
42

No LONG_MAX tests?

Also, test for overflow values in all tests? We don't need to check the errno value but may be check that the return value is *_MAX/*_MIN?

48

Is this really an invalid number?

This revision is now accepted and ready to land.Aug 18 2021, 4:39 PM
michaelrj updated this revision to Diff 367362.Aug 18 2021, 4:59 PM
michaelrj marked 2 inline comments as done.

address comments

libc/test/src/stdlib/atol_test.cpp
42

I've been avoiding LONG_MAX in the tests, since the size of LONG_MAX changes based on the operating system, specifically Windows uses 32 bit long while linux uses 64 bit long. This is difficult when I'm hardcoding the strings.

There aren't any overflow value tests since overflowing is undefined behavior for atoi. I can add them, but it means we're testing things that aren't in the specification.

48

I've changed the name of the tests, 010 isn't an invalid number, but it is interpreted as an octal number if the base is set to 0.

sivachandra accepted this revision.Aug 18 2021, 5:18 PM
This revision was automatically updated to reflect the committed changes.