mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-05-14 18:06:32 +00:00

Msan needs noundef consistency between interface and implementation. If we call C++ from C we can have noundef on C++ side, and no noundef on caller C side, noundef implementation will not set TLS for return value, no noundef caller will expect it. Then we have false reports in msan. The workaround could be set TLS to zero even for noundef return values. However if we do that always it will increase binary size by about 10%. If we do that selectively we need to handle "address is taken" functions, any non local functions, and probably all function which have musttail callers. Which is still a lot. The existing implementation of HasStrictReturn refers to C standard as the reason not enforcing noundef. I believe it applies only to the case when return statement is omitted. Testing on Google codebase I never see such cases, however I've see tens of cases where C code returns actual uninitialized variables, but we ignore that it because of "omitted return" case. So this patch will: 1. fix false-positives with TLS missmatch. 2. detect bugs returning uninitialized variables for C as well. 3. report "omitted return" cases stricter than C, which is already a warning and very likely a bug in a code anyway. Reviewed By: kda Differential Revision: https://reviews.llvm.org/D139296
43 lines
1.6 KiB
C
43 lines
1.6 KiB
C
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -no-enable-noundef-analysis -o - %s | \
|
|
// RUN: FileCheck %s --check-prefixes=CLEAN,CHECK
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -fno-sanitize-memory-param-retval -o - %s | \
|
|
// RUN: FileCheck %s --check-prefixes=NOUNDEF,NOUNDEF_ONLY,CHECK
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -mllvm -msan-eager-checks -o - %s | \
|
|
// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER,CHECK
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -no-enable-noundef-analysis -fsanitize-memory-param-retval -o - %s | \
|
|
// RUN: FileCheck %s --check-prefixes=CLEAN,CHECK
|
|
// RUN: %clang_cc1 -triple x86_64-linux-gnu -S -emit-llvm -fsanitize=memory -o - %s | \
|
|
// RUN: FileCheck %s --check-prefixes=NOUNDEF,EAGER,CHECK
|
|
|
|
void bar(int x) {
|
|
}
|
|
|
|
// CLEAN: define dso_local void @bar(i32 %x) #0 {
|
|
// NOUNDEF: define dso_local void @bar(i32 noundef %x) #0 {
|
|
// CLEAN: @__msan_param_tls
|
|
// NOUNDEF_ONLY: @__msan_param_tls
|
|
// EAGER-NOT: @__msan_param_tls
|
|
// CHECK: }
|
|
|
|
int foo() {
|
|
return 1;
|
|
}
|
|
|
|
// CLEAN: define dso_local i32 @foo() #0 {
|
|
// NOUNDEF: define dso_local noundef i32 @foo() #0 {
|
|
// CLEAN: @__msan_retval_tls
|
|
// NOUNDEF_ONLY: @__msan_retval_tls
|
|
// EAGER-NOT: @__msan_retval_tls
|
|
// CHECK: }
|
|
|
|
int noret() {
|
|
}
|
|
|
|
// CLEAN: define dso_local i32 @noret() #0 {
|
|
// NOUNDEF: define dso_local noundef i32 @noret() #0 {
|
|
// CHECK: %retval = alloca
|
|
// CLEAN: @__msan_retval_tls
|
|
// NOUNDEF_ONLY: @__msan_retval_tls
|
|
// EAGER-NOT: @__msan_retval_tls
|
|
// CHECK: }
|