break;
CASE_CONST_SCALAR_INT:
+ if (ix86_endbr_immediate_operand (x, VOIDmode))
+ return false;
+
switch (mode)
{
case E_TImode:
/* Validate displacement. */
if (disp)
{
+ if (ix86_endbr_immediate_operand (disp, VOIDmode))
+ return false;
+
if (GET_CODE (disp) == CONST
&& GET_CODE (XEXP (disp, 0)) == UNSPEC
&& XINT (XEXP (disp, 0), 1) != UNSPEC_MACHOPIC_OFFSET)
(define_predicate "symbol_operand"
(match_code "symbol_ref"))
+;; Return true if VALUE is an ENDBR opcode in immediate field.
+(define_predicate "ix86_endbr_immediate_operand"
+ (match_code "const_int")
+{
+ if (flag_cf_protection & CF_BRANCH)
+ {
+ unsigned HOST_WIDE_INT imm = UINTVAL (op);
+ unsigned HOST_WIDE_INT val = TARGET_64BIT ? 0xfa1e0ff3 : 0xfb1e0ff3;
+
+ if (imm == val)
+ return 1;
+
+ /* NB: Encoding is byte based. */
+ if (TARGET_64BIT)
+ for (; imm >= val; imm >>= 8)
+ if (imm == val)
+ return 1;
+ }
+
+ return 0;
+})
+
;; Return true if VALUE can be stored in a sign extended immediate field.
(define_predicate "x86_64_immediate_operand"
(match_code "const_int,symbol_ref,label_ref,const")
{
+ if (ix86_endbr_immediate_operand (op, VOIDmode))
+ return false;
+
if (!TARGET_64BIT)
return immediate_operand (op, mode);
(define_predicate "x86_64_zext_immediate_operand"
(match_code "const_int,symbol_ref,label_ref,const")
{
+ if (ix86_endbr_immediate_operand (op, VOIDmode))
+ return false;
+
switch (GET_CODE (op))
{
case CONST_INT:
(define_predicate "x86_64_dwzext_immediate_operand"
(match_code "const_int,const_wide_int")
{
+ if (ix86_endbr_immediate_operand (op, VOIDmode))
+ return false;
+
switch (GET_CODE (op))
{
case CONST_INT:
--- /dev/null
+/* PR target/96350 */
+/* { dg-do compile } */
+/* { dg-options "-fcf-protection -O2" } */
+/* { dg-final { scan-assembler-not "$-81915917" { target { ia32 } } } } */
+/* { dg-final { scan-assembler-not "$-98693133" { target { ! ia32 } } } } *
+/* { dg-final { scan-assembler-not "$-423883778574778368" { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler "\[ \t\]*-81915917" { target { ia32 } } } } */
+/* { dg-final { scan-assembler "\[ \t\]*-98693133" { target { ! ia32 } } } } */
+/* { dg-final { scan-assembler "\[ \t\]*-423883778574778368" { target { ! ia32 } } } } */
+
+
+#ifdef __x86_64__
+#define ENDBR_IMMEDIATE 0xfa1e0ff3
+#define EXTEND_ENDBR_IMMEDIATE 0xfa1e0ff300000000
+#else
+#define ENDBR_IMMEDIATE 0xfb1e0ff3
+#define EXTEND_ENDBR_IMMEDIATE 0xfffb1e0ff300
+#endif
+
+int
+foo (int a)
+{
+ return a + ENDBR_IMMEDIATE;
+}
+
+int
+foo2 (int a)
+{
+ return a - ENDBR_IMMEDIATE;
+}
+
+int
+foo3 (int a)
+{
+ return a * ENDBR_IMMEDIATE;
+}
+
+int
+foo4 (int a)
+{
+ return a | ENDBR_IMMEDIATE;
+}
+
+int
+foo5 (int a)
+{
+ return a ^ ENDBR_IMMEDIATE;
+}
+
+int
+foo6 (int a)
+{
+ return a & ENDBR_IMMEDIATE;
+}
+
+int
+foo7 (int a)
+{
+ return a > ENDBR_IMMEDIATE;
+}
+
+int
+foo8 (int a)
+{
+ return ENDBR_IMMEDIATE;
+}
+
+int
+foo9 (int* p)
+{
+ return *(p + ENDBR_IMMEDIATE);
+}
+
+int
+foo10 (int* p)
+{
+ return *(int*) ENDBR_IMMEDIATE;
+}
+
+long long
+foo11 (long long a)
+{
+ return a + EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo12 (long long a)
+{
+ return a - EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo13 (long long a)
+{
+ return a * EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo14 (long long a)
+{
+ return a | EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo15 (long long a)
+{
+ return a ^ EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo16 (long long a)
+{
+ return a & EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo17 (long long a)
+{
+ return a > EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo18 (long long a)
+{
+ return EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo19 (long long* p)
+{
+ return *(p + EXTEND_ENDBR_IMMEDIATE);
+}
+
+long long
+foo20 (long long* p)
+{
+ return *(long long*) EXTEND_ENDBR_IMMEDIATE;
+}
+
+long long
+foo21 (int a)
+{
+ return a + ENDBR_IMMEDIATE;
+}
+
+long long
+foo22 (int a)
+{
+ return a - ENDBR_IMMEDIATE;
+}
+
+long long
+foo23 (long long a)
+{
+ return a * ENDBR_IMMEDIATE;
+}
+
+long long
+foo24 (int a)
+{
+ return a | ENDBR_IMMEDIATE;
+}
+
+long long
+foo25 (int a)
+{
+ return a ^ ENDBR_IMMEDIATE;
+}
+
+long long
+foo26 (int a)
+{
+ return a & ENDBR_IMMEDIATE;
+}
+
+long long
+foo27 (int a)
+{
+ return a > ENDBR_IMMEDIATE;
+}
+
+long long
+foo28 (int a)
+{
+ return ENDBR_IMMEDIATE;
+}
+
+long long
+foo29 (int* p)
+{
+ return *(p + ENDBR_IMMEDIATE);
+}
+
+long long
+foo30 (int* p)
+{
+ return *(long long*) ENDBR_IMMEDIATE;
+}