xref: /aosp_15_r20/external/compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot 
3*7c3d14c8STreehugger Robot #include <stdint.h>
4*7c3d14c8STreehugger Robot 
main()5*7c3d14c8STreehugger Robot int main() {
6*7c3d14c8STreehugger Robot   // These promote to 'int'.
7*7c3d14c8STreehugger Robot   (void)(int8_t(-2) * int8_t(0x7f));
8*7c3d14c8STreehugger Robot   (void)(int16_t(0x7fff) * int16_t(0x7fff));
9*7c3d14c8STreehugger Robot   (void)(uint16_t(0xffff) * int16_t(0x7fff));
10*7c3d14c8STreehugger Robot   (void)(uint16_t(0xffff) * uint16_t(0x8000));
11*7c3d14c8STreehugger Robot 
12*7c3d14c8STreehugger Robot   // Not an unsigned overflow
13*7c3d14c8STreehugger Robot   (void)(uint16_t(0xffff) * uint16_t(0x8001));
14*7c3d14c8STreehugger Robot 
15*7c3d14c8STreehugger Robot   (void)(uint32_t(0xffffffff) * uint32_t(0x2));
16*7c3d14c8STreehugger Robot   // CHECK: umul-overflow.cpp:15:31: runtime error: unsigned integer overflow: 4294967295 * 2 cannot be represented in type 'unsigned int'
17*7c3d14c8STreehugger Robot 
18*7c3d14c8STreehugger Robot   return 0;
19*7c3d14c8STreehugger Robot }
20