LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 25552 - extend -fwrapv to apply to left shifts
Summary: extend -fwrapv to apply to left shifts
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: unspecified
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-17 06:07 PST by Paolo Bonzini
Modified: 2016-08-16 04:55 PDT (History)
10 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Bonzini 2015-11-17 06:07:22 PST
If you pass clang -fwrapv then this causes -fsanitize=undefined to no longer complain about signed integer overflows from addition.  However the sanitizer will still complain about left shifts of negative values.

-fwrapv should apply also to shifts.  In addition -fwrapv in clang should suppress -Wshift-negative-value.

(The GCC manuals only mention -fwrapv to affect add/sub/mult because GCC currently _never_ treats signed left shifts as having undefined behavior.  GCC documentation however says very clearly, under -fstrict-overflow, that "Using '-fwrapv' means that integer signed overflow is fully defined: it wraps").
Comment 1 Paolo Bonzini 2015-12-12 02:29:52 PST
These changes have now been committed to GCC.

In addition, GCC is now promising not to use the latitude offered by the standard in treating overflowing << and << of a negative number as undefined in C99 or later.  LLVM is not yet documenting any kind of implementation-defined behavior (bug 11272).
Comment 3 James Molloy 2016-08-15 05:33:55 PDT
Fix up for review at https://reviews.llvm.org/D23498
Comment 4 James Molloy 2016-08-16 04:55:07 PDT
Fix committed in r278786. Nominated for inclusion in 3.9.