brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · bd87f4a Raw
50 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -o - %s | FileCheck %s --check-prefixes=CHECK,C2// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fsanitize-cfi-icall-experimental-normalize-integers -x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,CPP3#if !__has_feature(kcfi)4#error Missing kcfi?5#endif6 7// Test that normalized type metadata for functions are emitted for cross-language KCFI support with8// other languages that can't represent and encode C/C++ integer types.9 10void foo(void (*fn)(int), int arg) {11    // CHECK-LABEL: define{{.*}}foo12    // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE1:[0-9]+]]13    // CHECK: call void %0(i32 noundef %1){{.*}}[ "kcfi"(i32 1162514891) ]14    fn(arg);15}16 17void bar(void (*fn)(int, int), int arg1, int arg2) {18    // CHECK-LABEL: define{{.*}}bar19    // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE2:[0-9]+]]20    // CHECK: call void %0(i32 noundef %1, i32 noundef %2){{.*}}[ "kcfi"(i32 448046469) ]21    fn(arg1, arg2);22}23 24void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {25    // CHECK-LABEL: define{{.*}}baz26    // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE3:[0-9]+]]27    // CHECK: call void %0(i32 noundef %1, i32 noundef %2, i32 noundef %3){{.*}}[ "kcfi"(i32 -2049681433) ]28    fn(arg1, arg2, arg3);29}30 31union Union {32  char *c;33  long *n;34} __attribute__((transparent_union));35 36void uni(void (*fn)(union Union), union Union arg1) {37    // CHECK-LABEL: define{{.*}}uni38    // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE4:[0-9]+]]39    // C: call void %0(ptr %1) [ "kcfi"(i32 1819770848) ]40    // CPP: call void %0(ptr %1) [ "kcfi"(i32 -1430221633) ]41    fn(arg1);42}43 44// CHECK: ![[#]] = !{i32 4, !"cfi-normalize-integers", i32 1}45// CHECK: ![[TYPE1]] = !{i32 -1143117868}46// CHECK: ![[TYPE2]] = !{i32 -460921415}47// CHECK: ![[TYPE3]] = !{i32 -333839615}48// C: ![[TYPE4]] = !{i32 -650530463}49// CPP: ![[TYPE4]] = !{i32 1766237188}50