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 22822 - Aggressive optimization breaks the code and removes checks
Summary: Aggressive optimization breaks the code and removes checks
Status: RESOLVED INVALID
Alias: None
Product: clang
Classification: Unclassified
Component: LLVM Codegen (show other bugs)
Version: 3.6
Hardware: PC All
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-06 09:51 PST by Marek Kurdej
Modified: 2015-03-06 12:13 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Minimal example of the code causing the problem (1.08 KB, text/plain)
2015-03-06 09:51 PST, Marek Kurdej
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Kurdej 2015-03-06 09:51:31 PST
Created attachment 13993 [details]
Minimal example of the code causing the problem

The attached code is miscompiled at optimization levels -Os and above and the checks in checked_add function are apparently ignored.
Reproduced on FreeBSD and Windows with clang 3.5.0 (release=r217039) and 3.6.0(tags/RELEASE_360/final).
Comment 1 David Blaikie 2015-03-06 10:11:49 PST
Looks like undefined behavior to me.

signed integer overflow (as happens at the beginning of the call to checked_add when passed max_int) is undefined. Since your program unconditionally executes that addition, the behavior of the entire program is undefined - nothing it does, even before the point of the addition, is guaranteed by the C++ standard.