xref: /aosp_15_r20/external/compiler-rt/test/ubsan/TestCases/Integer/mul-overflow.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=signed-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   // CHECK: mul-overflow.cpp:13:27: runtime error: signed integer overflow: 65535 * 32769 cannot be represented in type 'int'
13*7c3d14c8STreehugger Robot   (void)(uint16_t(0xffff) * uint16_t(0x8001));
14*7c3d14c8STreehugger Robot }
15