[clang] [X86][test] Added extra cet tests (PR #88736)

Isha Agarwal via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 18 00:16:06 PDT 2024


https://github.com/iagarwa updated https://github.com/llvm/llvm-project/pull/88736

>From 821c61fb4905b491176e00ea9ed322aad04c98e3 Mon Sep 17 00:00:00 2001
From: Isha Agarwal <isha.agarwal at intel.com>
Date: Mon, 15 Apr 2024 06:22:34 -0700
Subject: [PATCH 1/3] [X86][test] Added extra cet tests

Updated cet test to:
-Check different modules based on different cet options
-Added negative tests also

Signed-off-by: Isha Agarwal <isha.agarwal at intel.com>
---
 clang/test/CodeGen/X86/x86-cf-protection.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/clang/test/CodeGen/X86/x86-cf-protection.c b/clang/test/CodeGen/X86/x86-cf-protection.c
index ba63b9e17c6f63..abc6ed63d61289 100644
--- a/clang/test/CodeGen/X86/x86-cf-protection.c
+++ b/clang/test/CodeGen/X86/x86-cf-protection.c
@@ -2,6 +2,10 @@
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=branch %s | FileCheck %s --check-prefix=BRANCH
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=full %s   | FileCheck %s --check-prefix=FULL
 // RUN: not %clang_cc1 -emit-llvm-only -triple i386 -target-cpu pentium-mmx -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=NOCFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | FileCheck %s --check-prefix=CFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | FileCheck %s --check-prefix=CFPROTF
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | FileCheck %s --check-prefix=CFPROTNONE
+// RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | FileCheck %s --check-prefix=NOTCET
 
 // RETURN: #define __CET__ 2
 // BRANCH: #define __CET__ 1
@@ -9,5 +13,9 @@
 // CFPROT: !{i32 8, !"cf-protection-branch", i32 1}
 
 // NOCFPROT: error: option 'cf-protection=branch' cannot be specified on this target
+// CFPROTF: !{i32 8, !"cf-protection-return", i32 1}
+// CFPROTF-NEXT: !{i32 8, !"cf-protection-branch", i32 1}
+// CFPROTNONE-NOT: cf-protection-branch
+// NOTCET-NOT: #define __CET__
 
 void foo() {}

>From ac2078274b367896aef6840d04e24a72012cf0ba Mon Sep 17 00:00:00 2001
From: Isha Agarwal <isha.agarwal at intel.com>
Date: Mon, 15 Apr 2024 21:09:54 -0700
Subject: [PATCH 2/3] Address comments

---
 clang/test/CodeGen/X86/x86-cf-protection.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/clang/test/CodeGen/X86/x86-cf-protection.c b/clang/test/CodeGen/X86/x86-cf-protection.c
index abc6ed63d61289..02aee868936b40 100644
--- a/clang/test/CodeGen/X86/x86-cf-protection.c
+++ b/clang/test/CodeGen/X86/x86-cf-protection.c
@@ -1,21 +1,22 @@
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=return %s | FileCheck %s --check-prefix=RETURN
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=branch %s | FileCheck %s --check-prefix=BRANCH
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=full %s   | FileCheck %s --check-prefix=FULL
+// RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | FileCheck %s --check-prefix=NOTCET
 // RUN: not %clang_cc1 -emit-llvm-only -triple i386 -target-cpu pentium-mmx -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=NOCFPROT
-// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | FileCheck %s --check-prefix=CFPROT
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=return %s -emit-llvm | FileCheck %s --check-prefix=CFPROTR
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | FileCheck %s --check-prefix=CFPROTB
 // RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | FileCheck %s --check-prefix=CFPROTF
 // RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | FileCheck %s --check-prefix=CFPROTNONE
-// RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | FileCheck %s --check-prefix=NOTCET
 
 // RETURN: #define __CET__ 2
 // BRANCH: #define __CET__ 1
 // FULL: #define __CET__ 3
-// CFPROT: !{i32 8, !"cf-protection-branch", i32 1}
-
+// NOTCET-NOT: #define __CET__
 // NOCFPROT: error: option 'cf-protection=branch' cannot be specified on this target
+// CFPROTR: !{i32 8, !"cf-protection-return", i32 1}
+// CFPROTB: !{i32 8, !"cf-protection-branch", i32 1}
 // CFPROTF: !{i32 8, !"cf-protection-return", i32 1}
 // CFPROTF-NEXT: !{i32 8, !"cf-protection-branch", i32 1}
-// CFPROTNONE-NOT: cf-protection-branch
-// NOTCET-NOT: #define __CET__
+// CFPROTNONE-NOT: cf-protection-
 
 void foo() {}

>From 1e17b2678160077e7d548ce7b9ca568da3007d8e Mon Sep 17 00:00:00 2001
From: Isha Agarwal <isha.agarwal at intel.com>
Date: Wed, 17 Apr 2024 23:50:21 -0700
Subject: [PATCH 3/3] Address comments

Signed-off-by: Isha Agarwal <isha.agarwal at intel.com>
---
 clang/test/CodeGen/X86/x86-cf-protection.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/clang/test/CodeGen/X86/x86-cf-protection.c b/clang/test/CodeGen/X86/x86-cf-protection.c
index 02aee868936b40..84c7c0f16663c9 100644
--- a/clang/test/CodeGen/X86/x86-cf-protection.c
+++ b/clang/test/CodeGen/X86/x86-cf-protection.c
@@ -3,10 +3,10 @@
 // RUN: %clang_cc1 -E -triple i386 -dM -o - -fcf-protection=full %s   | FileCheck %s --check-prefix=FULL
 // RUN: %clang_cc1 -E -triple=x86_64 -dM -o - -fcf-protection=none %s | FileCheck %s --check-prefix=NOTCET
 // RUN: not %clang_cc1 -emit-llvm-only -triple i386 -target-cpu pentium-mmx -fcf-protection=branch %s 2>&1 | FileCheck %s --check-prefix=NOCFPROT
-// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=return %s -emit-llvm | FileCheck %s --check-prefix=CFPROTR
-// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | FileCheck %s --check-prefix=CFPROTB
-// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | FileCheck %s --check-prefix=CFPROTF
-// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | FileCheck %s --check-prefix=CFPROTNONE
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=return %s -emit-llvm | FileCheck %s --check-prefixes=CFPROTR,CFPROTNONE
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=branch %s -emit-llvm | FileCheck %s --check-prefixes=CFPROTB,CFPROTNONE
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=full %s -emit-llvm | FileCheck %s --check-prefixes=CFPROTR,CFPROTB,CFPROTNONE
+// RUN: %clang_cc1 -triple=x86_64 -o - -fcf-protection=none %s -emit-llvm | FileCheck %s --check-prefixes=CFPROTNONE
 
 // RETURN: #define __CET__ 2
 // BRANCH: #define __CET__ 1
@@ -15,8 +15,6 @@
 // NOCFPROT: error: option 'cf-protection=branch' cannot be specified on this target
 // CFPROTR: !{i32 8, !"cf-protection-return", i32 1}
 // CFPROTB: !{i32 8, !"cf-protection-branch", i32 1}
-// CFPROTF: !{i32 8, !"cf-protection-return", i32 1}
-// CFPROTF-NEXT: !{i32 8, !"cf-protection-branch", i32 1}
 // CFPROTNONE-NOT: cf-protection-
 
 void foo() {}



More information about the cfe-commits mailing list