Skip to content

Commit

Permalink
[test][PAC][clang] Add missing tests against linux triples (#99482)
Browse files Browse the repository at this point in the history
Enhance tests introduced in #94056, #96992, #98276 and #98847 by adding
RUN and CHECK lines against linux triples.
  • Loading branch information
kovdan01 authored Jul 19, 2024
1 parent 90668d2 commit a1d77ca
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 101 deletions.
10 changes: 6 additions & 4 deletions clang/test/CodeGen/ptrauth-function-lvalue-cast-disc.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -emit-llvm -o- -fptrauth-function-pointer-type-discrimination | FileCheck -check-prefixes CHECK,TYPE %s
// RUN: %clang_cc1 %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -emit-llvm -o- -fptrauth-function-pointer-type-discrimination | FileCheck -check-prefixes CHECK,TYPE %s
// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -emit-llvm -o- | FileCheck -check-prefixes CHECK,ZERO %s
// RUN: %clang_cc1 %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -emit-llvm -o- | FileCheck -check-prefixes CHECK,ZERO %s

typedef void (*fptr_t)(void);

char *cptr;
void (*fptr)(void);

// CHECK-LABEL: define void @test1
// CHECK-LABEL: define{{.*}} void @test1
void test1() {
// TYPE: [[LOAD:%.*]] = load ptr, ptr @cptr
// TYPE: [[TOINT:%.*]] = ptrtoint ptr [[LOAD]] to i64
Expand All @@ -17,7 +19,7 @@ void test1() {
(*(fptr_t)cptr)();
}

// CHECK-LABEL: define i8 @test2
// CHECK-LABEL: define{{.*}} i8 @test2
char test2() {
return *(char *)fptr;

Expand All @@ -35,7 +37,7 @@ char test2() {
// ZERO-NOT: @llvm.ptrauth.resign
}

// CHECK-LABEL: define void @test4
// CHECK-LABEL: define{{.*}} void @test4
void test4() {
(*((fptr_t)(&*((char *)(&*(fptr_t)cptr)))))();

Expand All @@ -49,7 +51,7 @@ void test4() {
}

void *vptr;
// CHECK-LABEL: define void @test5
// CHECK-LABEL: define{{.*}} void @test5
void test5() {
vptr = &*(char *)fptr;

Expand Down
32 changes: 23 additions & 9 deletions clang/test/CodeGen/ptrauth-function-type-discriminator-cast.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,TYPE
// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,ZERO
// RUN: %clang_cc1 -xc++ %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,CHECKCXX,TYPE,TYPECXX
// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,TYPE

// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,TYPE

// RUN: %clang_cc1 %s -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,ZERO

// RUN: %clang_cc1 %s -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefixes=CHECK,ZERO

// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -xc++ -o- | FileCheck %s --check-prefixes=CHECK,CHECKCXX,TYPE,TYPECXX

// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -xc++ -o- | FileCheck %s --check-prefixes=CHECK,CHECKCXX,TYPE,TYPECXX

#ifdef __cplusplus
extern "C" {
Expand All @@ -19,12 +33,12 @@ struct ptr_member {
ptr_member pm;
void (*test_member)() = (void (*)())pm.fptr_;

// CHECKCXX-LABEL: define internal void @__cxx_global_var_init
// CHECKCXX-LABEL: define{{.*}} internal void @__cxx_global_var_init
// TYPECXX: call i64 @llvm.ptrauth.resign(i64 {{.*}}, i32 0, i64 2712, i32 0, i64 18983)
#endif


// CHECK-LABEL: define void @test_cast_to_opaque
// CHECK-LABEL: define{{.*}} void @test_cast_to_opaque
void test_cast_to_opaque() {
opaque = (void *)f;

Expand All @@ -33,7 +47,7 @@ void test_cast_to_opaque() {
// ZERO-NOT: @llvm.ptrauth.resign
}

// CHECK-LABEL: define void @test_cast_from_opaque
// CHECK-LABEL: define{{.*}} void @test_cast_from_opaque
void test_cast_from_opaque() {
fptr = (void (*)(void))opaque;

Expand All @@ -48,7 +62,7 @@ void test_cast_from_opaque() {
// ZERO-NOT: @llvm.ptrauth.resign
}

// CHECK-LABEL: define void @test_cast_to_intptr
// CHECK-LABEL: define{{.*}} void @test_cast_to_intptr
void test_cast_to_intptr() {
uintptr = (unsigned long)fptr;

Expand All @@ -69,14 +83,14 @@ void test_cast_to_intptr() {
// ZERO-NOT: @llvm.ptrauth.resign
}

// CHECK-LABEL: define void @test_function_to_function_cast
// CHECK-LABEL: define{{.*}} void @test_function_to_function_cast
void test_function_to_function_cast() {
void (*fptr2)(int) = (void (*)(int))fptr;
// TYPE: call i64 @llvm.ptrauth.resign(i64 {{.*}}, i32 0, i64 18983, i32 0, i64 2712)
// ZERO-NOT: @llvm.ptrauth.resign
}

// CHECK-LABEL: define void @test_call_lvalue_cast
// CHECK-LABEL: define{{.*}} void @test_call_lvalue_cast
void test_call_lvalue_cast() {
(*(void (*)(int))f)(42);

Expand Down
33 changes: 22 additions & 11 deletions clang/test/CodeGen/ptrauth-function-type-discriminator.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefix=CHECK --check-prefix=CHECKC
// RUN: %clang_cc1 -xc++ %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s --check-prefix=CHECK
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -emit-pch %s -o %t.ast
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -emit-llvm -x ast -o - %t.ast | FileCheck -check-prefix=CHECK --check-prefix=CHECKC %s
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm %s -o- | FileCheck --check-prefixes=CHECK,CHECKC %s
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -xc++ %s -o- | FileCheck --check-prefix=CHECK %s
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics -emit-pch %s -o %t.ast
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple arm64-apple-ios -fptrauth-calls -fptrauth-intrinsics \
// RUN: -emit-llvm -x ast -o - %t.ast | FileCheck --check-prefixes=CHECK,CHECKC %s

// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm %s -o- | FileCheck --check-prefixes=CHECK,CHECKC %s
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -disable-llvm-passes -emit-llvm -xc++ %s -o- | FileCheck --check-prefix=CHECK %s
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics -emit-pch %s -o %t.ast
// RUN: %clang_cc1 -fptrauth-function-pointer-type-discrimination -triple aarch64-linux-gnu -fptrauth-calls -fptrauth-intrinsics \
// RUN: -emit-llvm -x ast -o - %t.ast | FileCheck --check-prefixes=CHECK,CHECKC %s

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -47,29 +58,29 @@ void (*fptr3)(void) = __builtin_ptrauth_sign_constant(&external_function, 2, 26)
// CHECK: @fptr4 = global ptr ptrauth (ptr @external_function, i32 2, i64 26, ptr @fptr4)
void (*fptr4)(void) = __builtin_ptrauth_sign_constant(&external_function, 2, __builtin_ptrauth_blend_discriminator(&fptr4, 26));

// CHECK-LABEL: define void @test_call()
// CHECK-LABEL: define{{.*}} void @test_call()
void test_call() {
// CHECK: [[T0:%.*]] = load ptr, ptr @fnptr,
// CHECK-NEXT: call void [[T0]]() [ "ptrauth"(i32 0, i64 18983) ]
fnptr();
}

// CHECK-LABEL: define ptr @test_function_pointer()
// CHECK-LABEL: define{{.*}} ptr @test_function_pointer()
// CHECK: ret ptr ptrauth (ptr @external_function, i32 0, i64 18983)
void (*test_function_pointer())(void) {
return external_function;
}

struct InitiallyIncomplete;
extern struct InitiallyIncomplete returns_initially_incomplete(void);
// CHECK-LABEL: define void @use_while_incomplete()
// CHECK-LABEL: define{{.*}} void @use_while_incomplete()
void use_while_incomplete() {
// CHECK: [[VAR:%.*]] = alloca ptr,
// CHECK-NEXT: store ptr ptrauth (ptr @returns_initially_incomplete, i32 0, i64 25106), ptr [[VAR]]
struct InitiallyIncomplete (*fnptr)(void) = &returns_initially_incomplete;
}
struct InitiallyIncomplete { int x; };
// CHECK-LABEL: define void @use_while_complete()
// CHECK-LABEL: define{{.*}} void @use_while_complete()
void use_while_complete() {
// CHECK: [[VAR:%.*]] = alloca ptr,
// CHECK-NEXT: store ptr ptrauth (ptr @returns_initially_incomplete, i32 0, i64 25106), ptr [[VAR]]
Expand All @@ -83,7 +94,7 @@ void knr(param)
int param;
{}

// CHECKC-LABEL: define void @test_knr
// CHECKC-LABEL: define{{.*}} void @test_knr
void test_knr() {
void (*p)() = knr;
p(0);
Expand All @@ -94,7 +105,7 @@ void test_knr() {
// CHECKC: call void [[LOAD]](i32 noundef 0) [ "ptrauth"(i32 0, i64 18983) ]
}

// CHECKC-LABEL: define void @test_redeclaration
// CHECKC-LABEL: define{{.*}} void @test_redeclaration
void test_redeclaration() {
void redecl();
void (*ptr)() = redecl;
Expand All @@ -113,7 +124,7 @@ void knr2(param)
int param;
{}

// CHECKC-LABEL: define void @test_redecl_knr
// CHECKC-LABEL: define{{.*}} void @test_redecl_knr
void test_redecl_knr() {
void (*p)() = knr2;
p();
Expand Down
3 changes: 3 additions & 0 deletions clang/test/CodeGen/ptrauth-ubsan-vptr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// RUN: %clang_cc1 -triple arm64e-apple-ios15 -fsanitize=vptr -O0 -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple arm64e-apple-ios15 -fsanitize=vptr -O2 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s

// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsanitize=vptr -O0 -emit-llvm -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsanitize=vptr -O2 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s

struct S {
S() {}
~S() {}
Expand Down
Loading

0 comments on commit a1d77ca

Please sign in to comment.