Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang sanitizer complains when trying to output negative integers #1377

Closed
t-b opened this issue Oct 25, 2019 · 5 comments
Closed

clang sanitizer complains when trying to output negative integers #1377

t-b opened this issue Oct 25, 2019 · 5 comments

Comments

@t-b
Copy link

t-b commented Oct 25, 2019

91f7619 (Fix Visual Studio 2019 pedantic warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?), 2019-10-14)

on macosx using xcode

Thomass-iMac:~ ci$ clang --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

when doing something like

  const int INDENT_COMPACT = -1;
  const int INDENT_WIDE    = 10;

   auto str = "Intendation must be between {} (compact) or {} (wide indentation)."_format(INDENT_COMPACT, INDENT_WIDE));

I get

/fmt/format.h:1374:36: runtime error: unsigned integer overflow: 0 - 4294967295 cannot be represented in type 'unsigned int'
    #0 0x16451428b in void fmt::v6::internal::basic_writer<fmt::v6::buffer_range<char> >::write_decimal<int>(int) format.h:1374

SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Users/ci/work/builds
@vitaut
Copy link
Contributor

vitaut commented Oct 28, 2019

This is weird because unsigned integer overflow is not a UB in C++. Also I wasn't able to reproduce it on your example or reduced one (https://godbolt.org/z/oq-O3I). Could you provide more details on how to repro (perhaps there are some additional compiler flags that affect this)?

@t-b
Copy link
Author

t-b commented Oct 28, 2019

@vitaut Thanks for looking into it. You have to pass the sanitize integer option as well, sorry for the sloppy report.

Here is an example https://godbolt.org/z/8xva4e.

@t-b t-b changed the title UBSAN complains when trying to output negative integers clang sanitizer complains when trying to output negative integers Oct 28, 2019
@t-b
Copy link
Author

t-b commented Oct 28, 2019

@vitaut And yes unsigned integer overflow is not UB.

@vitaut
Copy link
Contributor

vitaut commented Oct 28, 2019

Should be worked around in 58c6f8c.

@vitaut vitaut closed this as completed Oct 28, 2019
@t-b
Copy link
Author

t-b commented Oct 29, 2019

@vitaut Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants