67 lines · c
1// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -emit-llvm -O2 -o - %s | FileCheck %s2// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -emit-llvm -O2 -o - %s | FileCheck %s3 4// The x86_64-w64-windows-gnu version tests mingw target, which relies on5// __declspec(...) being defined as __attribute__((...)) by compiler built-in.6 7void target_func(void);8void (*func_ptr)(void) = &target_func;9 10// The "guard_nocf" attribute must be added.11__declspec(guard(nocf)) void nocf0(void) {12 (*func_ptr)();13}14// CHECK-LABEL: nocf015// CHECK: call{{.*}}[[NOCF:#[0-9]+]]16 17// Explicitly test using the GNU-style attribute without relying on the18// __declspec define for mingw.19// The "guard_nocf" attribute must be added.20__attribute__((guard(nocf))) void nocf0_gnu_style(void) {21 (*func_ptr)();22}23// CHECK-LABEL: nocf0_gnu_style24// CHECK: call{{.*}}[[NOCF:#[0-9]+]]25 26// The "guard_nocf" attribute must *not* be added.27void cf0(void) {28 (*func_ptr)();29}30// CHECK-LABEL: cf031// CHECK: call{{.*}}[[CF:#[0-9]+]]32 33// If the modifier is present on either the function declaration or definition,34// the "guard_nocf" attribute must be added.35__declspec(guard(nocf)) void nocf1(void);36void nocf1(void) {37 (*func_ptr)();38}39// CHECK-LABEL: nocf140// CHECK: call{{.*}}[[NOCF:#[0-9]+]]41 42void nocf2(void);43__declspec(guard(nocf)) void nocf2(void) {44 (*func_ptr)();45}46// CHECK-LABEL: nocf247// CHECK: call{{.*}}[[NOCF:#[0-9]+]]48 49// When inlining a function, the "guard_nocf" attribute on indirect calls must50// be preserved.51void nocf3(void) {52 nocf0();53}54// CHECK-LABEL: nocf355// CHECK: call{{.*}}[[NOCF:#[0-9]+]]56 57// When inlining into a function marked as __declspec(guard(nocf)), the58// "guard_nocf" attribute must *not* be added to the inlined calls.59__declspec(guard(nocf)) void cf1(void) {60 cf0();61}62// CHECK-LABEL: cf163// CHECK: call{{.*}}[[CF:#[0-9]+]]64 65// CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }66// CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }67