brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · ad434b7 Raw
106 lines · cpp
1// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -std=c++11 -emit-llvm -O2 -o - %s | FileCheck %s2// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -std=c++11 -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();8void (*func_ptr)() = &target_func;9 10// The "guard_nocf" attribute must be added.11__declspec(guard(nocf)) void nocf0() {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() {21  (*func_ptr)();22}23// CHECK-LABEL: nocf0_gnu_style24// CHECK: call{{.*}}[[NOCF:#[0-9]+]]25 26// Test using the c++-style attribute.27// The "guard_nocf" attribute must be added.28[[clang::guard(nocf)]] void nocf0_cxx_style() {29  (*func_ptr)();30}31// CHECK-LABEL: nocf0_cxx_style32// CHECK: call{{.*}}[[NOCF:#[0-9]+]]33 34// The "guard_nocf" attribute must *not* be added.35void cf0() {36  (*func_ptr)();37}38// CHECK-LABEL: cf039// CHECK: call{{.*}}[[CF:#[0-9]+]]40 41// If the modifier is present on either the function declaration or definition,42// the "guard_nocf" attribute must be added.43__declspec(guard(nocf)) void nocf1();44void nocf1() {45  (*func_ptr)();46}47// CHECK-LABEL: nocf148// CHECK: call{{.*}}[[NOCF:#[0-9]+]]49 50void nocf2();51__declspec(guard(nocf)) void nocf2() {52  (*func_ptr)();53}54// CHECK-LABEL: nocf255// CHECK: call{{.*}}[[NOCF:#[0-9]+]]56 57// When inlining a function, the "guard_nocf" attribute on indirect calls must58// be preserved.59void nocf3() {60  nocf0();61}62// CHECK-LABEL: nocf363// CHECK: call{{.*}}[[NOCF:#[0-9]+]]64 65// When inlining into a function marked as __declspec(guard(nocf)), the66// "guard_nocf" attribute must *not* be added to the inlined calls.67__declspec(guard(nocf)) void cf1() {68  cf0();69}70// CHECK-LABEL: cf171// CHECK: call{{.*}}[[CF:#[0-9]+]]72 73// When the __declspec(guard(nocf)) modifier is present on an override function,74// the "guard_nocf" attribute must be added.75struct Base {76  virtual void nocf4();77};78 79struct Derived : Base {80  __declspec(guard(nocf)) void nocf4() override {81    (*func_ptr)();82  }83};84Derived d;85// CHECK-LABEL: nocf486// CHECK: call{{.*}}[[NOCF:#[0-9]+]]87 88// When the modifier is not present on an override function, the "guard_nocf"89// attribute must *not* be added, even if the modifier is present on the virtual90// function.91struct Base1 {92  __declspec(guard(nocf)) virtual void cf2();93};94 95struct Derived1 : Base1 {96  void cf2() override {97    (*func_ptr)();98  }99};100Derived1 d1;101// CHECK-LABEL: cf2102// CHECK: call{{.*}}[[CF:#[0-9]+]]103 104// CHECK: attributes [[NOCF]] = { {{.*}}"guard_nocf"{{.*}} }105// CHECK-NOT: attributes [[CF]] = { {{.*}}"guard_nocf"{{.*}} }106