brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · e808c64 Raw
62 lines · cpp
1// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -fextend-variable-liveness -fsanitize=null -fsanitize-trap=null -o - | FileCheck --check-prefixes=CHECK,NULL --implicit-check-not=ubsantrap %s2// RUN: %clang_cc1 %s -triple x86_64-unknown-linux-gnu -emit-llvm -fextend-variable-liveness -o - | FileCheck %s3 4// With -fextend-variable-liveness, the compiler previously generated a fake.use of any5// reference variable at the end of the scope in which its alloca exists. This6// caused two issues, where we would get fake uses for uninitialized variables7// if that variable was declared after an early-return, and UBSan's null checks8// would complain about this.9// This test verifies that UBSan does not produce null-checks for arguments to10// llvm.fake.use, and that fake uses are not emitted for a variable on paths11// it has not been declared.12 13struct A { short s1, s2; };14extern long& getA();15 16void foo()17{18  auto& va = getA();19  if (va < 5)20    return;21 22  auto& vb = getA();23}24 25// CHECK-LABEL:  define{{.*}}foo26// CHECK:  [[VA_CALL:%.+]] = call{{.*}} ptr @_Z4getAv()27 28/// We check here for the first UBSan check for "va".29// NULL:   [[VA_ISNULL:%.+]] = icmp ne ptr [[VA_CALL]], null30// NULL:   br i1 [[VA_ISNULL]], label %{{[^,]+}}, label %[[VA_TRAP:[^,]+]]31// NULL: [[VA_TRAP]]:32// NULL:   call void @llvm.ubsantrap(33 34// CHECK:       [[VA_PTR:%.+]] = load ptr, ptr %va35// CHECK-NEXT:  [[VA_CMP:%.+]] = load i64, ptr [[VA_PTR]]36// CHECK-NEXT:  [[VA_CMP_RES:%.+]] = icmp slt i64 [[VA_CMP]], 537// CHECK-NEXT:  br i1 [[VA_CMP_RES]], label %[[EARLY_EXIT:[^,]+]], label %[[NOT_EARLY_EXIT:[^,]+]]38 39// CHECK: [[EARLY_EXIT]]:40// CHECK:   br label %cleanup41 42/// The fake use for "vb" only appears on the path where its declaration is43/// reached.44// CHECK:     [[NOT_EARLY_EXIT]]:45// CHECK:  [[VB_CALL:%.+]] = call{{.*}} ptr @_Z4getAv()46 47/// We check here for the second UBSan check for "vb".48// NULL:   [[VB_ISNULL:%.+]] = icmp ne ptr [[VB_CALL]], null49// NULL:   br i1 [[VB_ISNULL]], label %{{[^,]+}}, label %[[VB_TRAP:[^,]+]]50// NULL: [[VB_TRAP]]:51// NULL:   call void @llvm.ubsantrap(52 53// CHECK:       [[VB_FAKE_USE:%.+]] = load ptr, ptr %vb54// CHECK-NEXT:  call void (...) @llvm.fake.use(ptr [[VB_FAKE_USE]])55// CHECK:       br label %cleanup56 57// CHECK:     cleanup:58// CHECK:       [[VA_FAKE_USE:%.+]] = load ptr, ptr %va59// CHECK-NEXT:  call void (...) @llvm.fake.use(ptr [[VA_FAKE_USE]])60 61// NULL: declare void @llvm.ubsantrap62