error ("conflicting type qualifiers for %q+D", newdecl);
}
else
- error ("conflicting types for %q+D; have %qT", newdecl, newtype);
- diagnose_arglist_conflict (newdecl, olddecl, newtype, oldtype);
- locate_old_decl (olddecl);
- return false;
+ {
+ if (TREE_CODE (olddecl) == FUNCTION_DECL)
+ {
+ tree attrs = TYPE_ATTRIBUTES (TREE_TYPE (olddecl));
+ if (attrs && !TYPE_ATTRIBUTES (TREE_TYPE (newdecl)))
+ {
+ /* Similar to the C++ front-end, for FUNCTION_DECL,
+ if OLDDECL has attributes and NEWDECL doesn't,
+ try the type with OLDDECL attributes. */
+ tree rettype = TREE_TYPE (newtype);
+ tree tryargs = TYPE_ARG_TYPES (newtype);
+ tree trytype = c_build_function_type (rettype,
+ tryargs);
+ trytype = c_build_type_attribute_variant (trytype,
+ attrs);
+ if (comptypes (oldtype, trytype))
+ {
+ *newtypep = newtype = trytype;
+ comptypes_result = 1;
+ }
+ }
+ }
+
+ if (!comptypes_result)
+ error ("conflicting types for %q+D; have %qT", newdecl,
+ newtype);
+ }
+ if (!comptypes_result)
+ {
+ diagnose_arglist_conflict (newdecl, olddecl, newtype,
+ oldtype);
+ locate_old_decl (olddecl);
+ return false;
+ }
}
}
/* Warn about enum/integer type mismatches. They are compatible types
--- /dev/null
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+
+extern void foo (void) __attribute__((nocf_check));
+extern void foo (void);
+
+void
+foo (void)
+{
+}
+
+extern void bar (void);
+extern void bar (void) __attribute__((nocf_check)); /* { dg-error "ambiguating new declaration" } */
+
+void
+bar (void)
+{
+}
--- /dev/null
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+
+extern void bar (void);
+extern void bar (void) __attribute__((nocf_check)); /* { dg-error "ambiguating new declaration" } */
+extern void foo (void) __attribute__((nocf_check));
+extern void foo (void);
+
+void
+func (void)
+{
+ bar ();
+ foo ();
+}
--- /dev/null
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */
+/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } } */
+
+/*
+**_Z3foov:
+**.LFB[0-9]+:
+** .cfi_startproc
+** ret
+**...
+*/
+
+extern void foo (void) __attribute__((nocf_check));
+
+void
+foo (void)
+{
+}
--- /dev/null
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-require-weak "" } */
+/* { dg-options "-O2 -fcf-protection" } */
+/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */
+/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } } */
+
+/*
+**_Z3foov:
+**.LFB[0-9]+:
+** .cfi_startproc
+** ret
+**...
+*/
+
+extern void foo (void) __attribute__((nocf_check));
+
+__attribute__((weak))
+void
+foo (void)
+{
+}
+
+/* { dg-final { scan-assembler ".weak\[ \t\]_?_Z3foov" } } */
--- /dev/null
+/* PR c/122427 */
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+
+extern void foo (void) __attribute__((nocf_check));
+extern void foo (void);
+
+void
+foo (void)
+{
+}
+
+extern void bar (void);
+extern void bar (void) __attribute__((nocf_check)); /* { dg-error "conflicting types" } */
+
+void
+bar (void)
+{
+}
--- /dev/null
+/* PR c/122427 */
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-require-weak "" } */
+/* { dg-options "-O2 -fcf-protection" } */
+/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */
+/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } } */
+
+/*
+**foo:
+**.LFB[0-9]+:
+** .cfi_startproc
+** ret
+**...
+*/
+
+extern void foo (void) __attribute__((nocf_check));
+
+__attribute__((weak))
+void
+foo (void)
+{
+}
+
+/* { dg-final { scan-assembler ".weak\[ \t\]_?foo" } } */
--- /dev/null
+/* PR c/122427 */
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+/* Keep labels and directives ('.cfi_startproc', '.cfi_endproc'). */
+/* { dg-final { check-function-bodies "**" "" "" { target "*-*-*" } {^\t?\.} } } */
+
+/*
+**foo:
+**.LFB[0-9]+:
+** .cfi_startproc
+** ret
+**...
+*/
+
+extern void foo (void) __attribute__((nocf_check));
+
+void
+foo (void)
+{
+}
--- /dev/null
+/* PR c/122427 */
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+
+extern void foo (void);
+
+__attribute__((nocf_check))
+void
+foo (void) /* { dg-error "conflicting types" } */
+{
+}
--- /dev/null
+/* PR c/122427 */
+/* { dg-do compile { target { "i?86-*-* x86_64-*-*" } } } */
+/* { dg-options "-O2 -fcf-protection" } */
+
+extern void bar (void);
+extern void bar (void) __attribute__((nocf_check)); /* { dg-error "conflicting types" } */
+extern void foo (void) __attribute__((nocf_check));
+extern void foo (void);
+
+void
+func (void)
+{
+ bar ();
+ foo ();
+}
/* { dg-do compile } */
/* { dg-options "-O2" } */
-extern void foo (void) __attribute__ ((no_callee_saved_registers)); /* { dg-note "previous declaration" } */
+extern void foo (void) __attribute__ ((no_callee_saved_registers));
void
-foo (void) /* { dg-error "conflicting types" } */
+foo (void)
{
}
-
/* { dg-do compile } */
/* { dg-options "-O2" } */
-extern void foo (void) __attribute__ ((preserve_none)); /* { dg-note "previous declaration" } */
+extern void foo (void) __attribute__ ((preserve_none));
void
-foo (void) /* { dg-error "conflicting types" } */
+foo (void)
{
}
-