llvm-project/clang/test/CodeGen/indirect-noundef.cpp
Gui Andrade 10264a1b21 Introduce noundef attribute at call sites for stricter poison analysis
This change adds a new IR noundef attribute, which denotes when a function call argument or return val may never contain uninitialized bits.

In MemorySanitizer, this attribute enables optimizations which decrease instrumented code size by up to 17% (measured with an instrumented build of clang) . I'll introduce the change allowing msan to take advantage of this information in a separate patch.

Differential Revision: https://reviews.llvm.org/D81678
2021-03-04 12:15:12 -08:00

35 lines
1.1 KiB
C++

// RUN: %clang -cc1 -x c++ -triple x86_64-unknown-unknown -O0 -emit-llvm -enable-noundef-analysis -o - %s | FileCheck %s
union u1 {
int val;
};
// CHECK: @indirect_callee_int_ptr = [[GLOBAL:(dso_local )?global]] i32 (i32)*
int (*indirect_callee_int_ptr)(int);
// CHECK: @indirect_callee_union_ptr = [[GLOBAL]] i32 (i32)*
union u1 (*indirect_callee_union_ptr)(union u1);
// CHECK: [[DEFINE:define( dso_local)?]] noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef %
int indirect_callee_int(int a) { return a; }
// CHECK: [[DEFINE]] i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
union u1 indirect_callee_union(union u1 a) {
return a;
}
int main() {
// CHECK: call noundef i32 @{{.*}}indirect_callee_int{{.*}}(i32 noundef 0)
indirect_callee_int(0);
// CHECK: call i32 @{{.*}}indirect_callee_union{{.*}}(i32 %
indirect_callee_union((union u1){0});
indirect_callee_int_ptr = indirect_callee_int;
indirect_callee_union_ptr = indirect_callee_union;
// CHECK: call noundef i32 %{{.*}}(i32 noundef 0)
indirect_callee_int_ptr(0);
// CHECK: call i32 %{{.*}}(i32 %
indirect_callee_union_ptr((union u1){});
return 0;
}