forked from OSchip/llvm-project
[clang] Make guard(nocf) attribute available only for Windows
Control Flow Guard is only supported on Windows target, therefore there is no point to make it an accepted attribute for other targets. Reviewed By: rnk, aaron.ballman Differential Revision: https://reviews.llvm.org/D132661
This commit is contained in:
parent
a845d8fc57
commit
00d648bdb5
|
@ -146,7 +146,8 @@ Attribute Changes in Clang
|
||||||
``[[clang::guard(nocf)]]``, which is equivalent to ``__declspec(guard(nocf))``
|
``[[clang::guard(nocf)]]``, which is equivalent to ``__declspec(guard(nocf))``
|
||||||
when using the MSVC environment. This is to support enabling Windows Control
|
when using the MSVC environment. This is to support enabling Windows Control
|
||||||
Flow Guard checks with the ability to disable them for specific functions when
|
Flow Guard checks with the ability to disable them for specific functions when
|
||||||
using the MinGW environment.
|
using the MinGW environment. This attribute is only available for Windows
|
||||||
|
targets.
|
||||||
|
|
||||||
Windows Support
|
Windows Support
|
||||||
---------------
|
---------------
|
||||||
|
|
|
@ -399,6 +399,9 @@ def TargetRISCV : TargetArch<["riscv32", "riscv64"]>;
|
||||||
def TargetX86 : TargetArch<["x86"]>;
|
def TargetX86 : TargetArch<["x86"]>;
|
||||||
def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
|
def TargetAnyX86 : TargetArch<["x86", "x86_64"]>;
|
||||||
def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
|
def TargetWebAssembly : TargetArch<["wasm32", "wasm64"]>;
|
||||||
|
def TargetWindows : TargetSpec {
|
||||||
|
let OSes = ["Win32"];
|
||||||
|
}
|
||||||
def TargetHasDLLImportExport : TargetSpec {
|
def TargetHasDLLImportExport : TargetSpec {
|
||||||
let CustomCode = [{ Target.getTriple().hasDLLImportExport() }];
|
let CustomCode = [{ Target.getTriple().hasDLLImportExport() }];
|
||||||
}
|
}
|
||||||
|
@ -3494,7 +3497,7 @@ def MSAllocator : InheritableAttr {
|
||||||
let Documentation = [MSAllocatorDocs];
|
let Documentation = [MSAllocatorDocs];
|
||||||
}
|
}
|
||||||
|
|
||||||
def CFGuard : InheritableAttr {
|
def CFGuard : InheritableAttr, TargetSpecificAttr<TargetWindows> {
|
||||||
// Currently only the __declspec(guard(nocf)) modifier is supported. In future
|
// Currently only the __declspec(guard(nocf)) modifier is supported. In future
|
||||||
// we might also want to support __declspec(guard(suppress)).
|
// we might also want to support __declspec(guard(suppress)).
|
||||||
let Spellings = [Declspec<"guard">, Clang<"guard">];
|
let Spellings = [Declspec<"guard">, Clang<"guard">];
|
||||||
|
|
|
@ -2,10 +2,14 @@
|
||||||
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -std=c++11 -fsyntax-only -x c++ %s
|
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -std=c++11 -fsyntax-only -x c++ %s
|
||||||
// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -fsyntax-only %s
|
// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -fsyntax-only %s
|
||||||
// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -std=c++11 -fsyntax-only -x c++ %s
|
// RUN: %clang_cc1 -triple x86_64-w64-windows-gnu -verify -std=c++11 -fsyntax-only -x c++ %s
|
||||||
|
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -fsyntax-only %s
|
||||||
|
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -verify -std=c++11 -fsyntax-only -x c++ %s
|
||||||
|
|
||||||
// The x86_64-w64-windows-gnu version tests mingw target, which relies on
|
// The x86_64-w64-windows-gnu version tests mingw target, which relies on
|
||||||
// __declspec(...) being defined as __attribute__((...)) by compiler built-in.
|
// __declspec(...) being defined as __attribute__((...)) by compiler built-in.
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
|
||||||
// Function definition.
|
// Function definition.
|
||||||
__declspec(guard(nocf)) void testGuardNoCF(void) { // no warning
|
__declspec(guard(nocf)) void testGuardNoCF(void) { // no warning
|
||||||
}
|
}
|
||||||
|
@ -35,3 +39,9 @@ __declspec(guard(nocf, nocf)) void testGuardNoCFTooManyParams(void) { // expecte
|
||||||
// 'guard' Attribute argument must be a supported identifier.
|
// 'guard' Attribute argument must be a supported identifier.
|
||||||
__declspec(guard(cf)) void testGuardNoCFInvalidParam(void) { // expected-warning {{'guard' attribute argument not supported: 'cf'}}
|
__declspec(guard(cf)) void testGuardNoCFInvalidParam(void) { // expected-warning {{'guard' attribute argument not supported: 'cf'}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
__attribute((guard(nocf))) void testGNUStyleGuardNoCF(void) {} // expected-warning {{unknown attribute 'guard' ignored}}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue