Summary: This PR simply changes the behavior of the `wchar_size` flag. Currently, we emit this in all cases for all targets. This causes problems during LLVM-IR linking, specifically because this would vary between Linux and Windows in unintuitive ways. Now we have an llvm::Triple helper to determine the size from the known values. The module flag will only be emitted if these do not match (indicating a non-standard environment). In addition to fixing AMDGCN bitcode linking, this also means we don't need to bloat *every* IR module compiled by clang with this flag. The changed tests reflects this, one less unnecessary piece of metadata.
61 lines
3.4 KiB
C++
61 lines
3.4 KiB
C++
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
|
|
// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,MSVC,64
|
|
// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
|
|
// RUN: %clang_cc1 -triple aarch64_be-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,GNU,64
|
|
// RUN: %clang_cc1 -triple arm-none-eabi -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all | FileCheck %s --check-prefixes=CHECK,ARM,GNU,32
|
|
|
|
// RUN: %clang_cc1 -triple arm64e-apple-ios -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all -fptrauth-calls | FileCheck %s --check-prefixes=CHECK,GNU,64,AUTH
|
|
// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm -o - %s -fsanitize=function -fno-sanitize-recover=all -fptrauth-calls | FileCheck %s --check-prefixes=CHECK,GNU,64,AUTH
|
|
|
|
// GNU: define{{.*}} void @_Z3funv() #0 !func_sanitize ![[FUNCSAN:.*]] {
|
|
// MSVC: define{{.*}} void @"?fun@@YAXXZ"() #0 !func_sanitize ![[FUNCSAN:.*]] {
|
|
void fun() {}
|
|
|
|
// GNU-LABEL: define{{.*}} void @_Z6callerPFvvE(ptr noundef %f)
|
|
// MSVC-LABEL: define{{.*}} void @"?caller@@YAXP6AXXZ@Z"(ptr noundef %f)
|
|
// ARM: call ptr @llvm.ptrmask.p0.i32(ptr {{.*}}, i32 -2), !nosanitize !6
|
|
// AUTH: %[[STRIPPED:.*]] = ptrtoint ptr {{.*}} to i64, !nosanitize
|
|
// AUTH: call i64 @llvm.ptrauth.auth(i64 %[[STRIPPED]], i32 0, i64 0), !nosanitize
|
|
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 0, !nosanitize
|
|
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
|
|
// CHECK: icmp eq i32 {{.*}}, -1056584962, !nosanitize
|
|
// CHECK: br i1 {{.*}}, label %[[LABEL1:.*]], label %[[LABEL4:.*]], !nosanitize
|
|
// CHECK: [[LABEL1]]:
|
|
// CHECK: getelementptr <{ i32, i32 }>, ptr {{.*}}, i32 -1, i32 1, !nosanitize
|
|
// CHECK: load i32, ptr {{.*}}, align {{.*}}, !nosanitize
|
|
// GNU: icmp eq i32 {{.*}}, 905068220, !nosanitize
|
|
// MSVC: icmp eq i32 {{.*}}, -1600339357, !nosanitize
|
|
// CHECK: br i1 {{.*}}, label %[[LABEL3:.*]], label %[[LABEL2:[^,]*]], {{.*}}!nosanitize
|
|
// CHECK: [[LABEL2]]:
|
|
// 64: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], i64 %[[#]]) #[[#]], !nosanitize
|
|
// 32: call void @__ubsan_handle_function_type_mismatch_abort(ptr @[[#]], i32 %[[#]]) #[[#]], !nosanitize
|
|
// CHECK-NEXT: unreachable, !nosanitize
|
|
// CHECK-EMPTY:
|
|
// CHECK-NEXT: [[LABEL3]]:
|
|
// CHECK: br label %[[LABEL4]], !nosanitize
|
|
// CHECK-EMPTY:
|
|
// CHECK-NEXT: [[LABEL4]]:
|
|
// CHECK-NEXT: call void
|
|
// CHECK-NEXT: ret void
|
|
void caller(void (*f)()) { f(); }
|
|
|
|
// GNU: define{{.*}} void @_Z4fun2v() #0 {
|
|
// MSVC: define{{.*}} void @"?fun2@@YAXXZ"() #0 {
|
|
[[clang::cfi_unchecked_callee]]
|
|
void fun2() {}
|
|
|
|
typedef void (*unchecked_t)() [[clang::cfi_unchecked_callee]];
|
|
|
|
// GNU-LABEL: define{{.*}} void @_Z7caller2PFvvE(ptr noundef %f)
|
|
// MSVC-LABEL: define{{.*}} void @"?caller2@@YAXP6AXXZ@Z"(ptr noundef %f)
|
|
// CHECK-NEXT: entry:
|
|
// CHECK-NEXT: [[ADDR:%.*]] = alloca ptr
|
|
// CHECK-NEXT: store ptr %f, ptr [[ADDR]]
|
|
// CHECK-NEXT: [[FUNC:%.*]] = load ptr, ptr [[ADDR]]
|
|
// CHECK-NEXT: call void [[FUNC]]()
|
|
// CHECK-NEXT: ret void
|
|
void caller2(unchecked_t f) { f(); }
|
|
|
|
// GNU: ![[FUNCSAN]] = !{i32 -1056584962, i32 905068220}
|
|
// MSVC: ![[FUNCSAN]] = !{i32 -1056584962, i32 -1600339357}
|