[PATCH] D132302: [clang] Add support for __attribute__((guard(nocf)))
Alvin Wong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 21 00:38:03 PDT 2022
alvinhochun created this revision.
Herald added subscribers: pengfei, mstorsjo.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
alvinhochun added reviewers: ajpaverd, rnk.
alvinhochun updated this revision to Diff 454274.
alvinhochun edited the summary of this revision.
alvinhochun added a comment.
Herald added a subscriber: jdoerfert.
alvinhochun updated this revision to Diff 454277.
alvinhochun published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Update patch
alvinhochun added a comment.
Revert llvm test changes
To support using Control Flow Guard with mingw-w64, Clang needs to
accept `__declspec(guard(nocf))` also for the GNU target. Since mingw
has `#define __declspec(a) __attribute__((a))` as built-in, the simplest
solution is to accept `__attribute((guard(nocf)))` to be compatible with
MSVC and Clang's msvc target.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132302
Files:
clang/include/clang/Basic/Attr.td
clang/test/CodeGen/guard_nocf.c
clang/test/CodeGenCXX/guard_nocf.cpp
clang/test/Misc/pragma-attribute-supported-attributes-list.test
clang/test/Sema/attr-guard_nocf.c
Index: clang/test/Sema/attr-guard_nocf.c
===================================================================
--- clang/test/Sema/attr-guard_nocf.c
+++ clang/test/Sema/attr-guard_nocf.c
@@ -1,5 +1,10 @@
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -fsyntax-only %s
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -verify -std=c++11 -fsyntax-only -x c++ %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -verify -fsyntax-only %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -verify -std=c++11 -fsyntax-only -x c++ %s
+
+// The %itanium_abi_triple version tests mingw target, which relies on
+// __declspec(...) being defined as __attribute__((...)) by compiler built-in.
// Function definition.
__declspec(guard(nocf)) void testGuardNoCF(void) { // no warning
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===================================================================
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -26,6 +26,7 @@
// CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function)
// CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function)
// CHECK-NEXT: CFConsumed (SubjectMatchRule_variable_is_parameter)
+// CHECK-NEXT: CFGuard (SubjectMatchRule_function)
// CHECK-NEXT: CFICanonicalJumpTable (SubjectMatchRule_function)
// CHECK-NEXT: CFUnknownTransfer (SubjectMatchRule_function)
// CHECK-NEXT: CPUDispatch (SubjectMatchRule_function)
Index: clang/test/CodeGenCXX/guard_nocf.cpp
===================================================================
--- clang/test/CodeGenCXX/guard_nocf.cpp
+++ clang/test/CodeGenCXX/guard_nocf.cpp
@@ -1,4 +1,8 @@
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -std=c++11 -emit-llvm -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 -emit-llvm -O2 -o - %s | FileCheck %s
+
+// The %itanium_abi_triple version tests mingw target, which relies on
+// __declspec(...) being defined as __attribute__((...)) by compiler built-in.
void target_func();
void (*func_ptr)() = &target_func;
Index: clang/test/CodeGen/guard_nocf.c
===================================================================
--- clang/test/CodeGen/guard_nocf.c
+++ clang/test/CodeGen/guard_nocf.c
@@ -1,4 +1,8 @@
// RUN: %clang_cc1 -triple %ms_abi_triple -fms-extensions -emit-llvm -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -O2 -o - %s | FileCheck %s
+
+// The %itanium_abi_triple version tests mingw target, which relies on
+// __declspec(...) being defined as __attribute__((...)) by compiler built-in.
void target_func(void);
void (*func_ptr)(void) = &target_func;
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -3493,7 +3493,7 @@
def CFGuard : InheritableAttr {
// Currently only the __declspec(guard(nocf)) modifier is supported. In future
// we might also want to support __declspec(guard(suppress)).
- let Spellings = [Declspec<"guard">];
+ let Spellings = [Declspec<"guard">, GCC<"guard">];
let Subjects = SubjectList<[Function]>;
let Args = [EnumArgument<"Guard", "GuardArg", ["nocf"], ["nocf"]>];
let Documentation = [CFGuardDocs];
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132302.454277.patch
Type: text/x-patch
Size: 3375 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220821/1a84ebc0/attachment.bin>
More information about the cfe-commits
mailing list