xref: /llvm-project/clang/test/CodeGenCXX/cxx2a-left-shift.cpp (revision 7939ba08ab42922a00b7f1b7e4761c7f9cc51f0c)
1*7939ba08SRichard Smith // RUN: %clang_cc1 -std=c++2a -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,REGULAR
2*7939ba08SRichard Smith // RUN: %clang_cc1 -std=c++2a -fsanitize=shift-base,shift-exponent -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefixes=CHECK,SANITIZED
3*7939ba08SRichard Smith 
4*7939ba08SRichard Smith // CHECK-LABEL: @_Z12lsh_overflow
lsh_overflow(int a,int b)5*7939ba08SRichard Smith int lsh_overflow(int a, int b) {
6*7939ba08SRichard Smith   // SANITIZED: %[[RHS_INBOUNDS:.*]] = icmp ule i32 %[[RHS:.*]], 31
7*7939ba08SRichard Smith   // SANITIZED-NEXT: br i1 %[[RHS_INBOUNDS]], label %[[VALID:.*]], label
8*7939ba08SRichard Smith 
9*7939ba08SRichard Smith   // SANITIZED: call void @__ubsan_handle_shift_out_of_bounds
10*7939ba08SRichard Smith 
11*7939ba08SRichard Smith   // No check for the LHS here.
12*7939ba08SRichard Smith   // SANITIZED: [[VALID]]:
13*7939ba08SRichard Smith   // SANITIZED-NEXT: shl i32 %
14*7939ba08SRichard Smith   // SANITIZED-NEXT: ret i32
15*7939ba08SRichard Smith 
16*7939ba08SRichard Smith   // Just ensure there's no nsw nuw flags here.
17*7939ba08SRichard Smith   // REGULAR: shl i32 %
18*7939ba08SRichard Smith   return a << b;
19*7939ba08SRichard Smith }
20