aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-11-13 19:57:51 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-11-13 12:57:51 -0700
commitf9731de3db4c59ff0a241ce2c3d6f80aca5b5c28 (patch)
treea1212b5c29022147c933bf559db408eba9345157
parentee8393f465b6b06cc16499f7f7cfcbc3dc797d9b (diff)
downloadgcc-f9731de3db4c59ff0a241ce2c3d6f80aca5b5c28.zip
gcc-f9731de3db4c59ff0a241ce2c3d6f80aca5b5c28.tar.gz
gcc-f9731de3db4c59ff0a241ce2c3d6f80aca5b5c28.tar.bz2
PR middle-end/81824 - Warn for missing attributes with function aliases
gcc/c-family/ChangeLog: * c-attribs.c (handle_copy_attribute): Exclude inlining attributes. (handle_tls_model_attribute): Improve diagnostics. gcc/testsuite/ChangeLog: * gcc.dg/attr-copy-5.c: New test. * gcc.dg/tls/diag-6.c: Adjust expected diagnostics. From-SVN: r266084
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-attribs.c28
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/attr-copy-5.c57
-rw-r--r--gcc/testsuite/gcc.dg/tls/diag-6.c4
5 files changed, 92 insertions, 9 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 165f9b7..26a2b4e 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-13 Martin Sebor <msebor@redhat.com>
+
+ PR middle-end/81824
+ * c-attribs.c (handle_copy_attribute): Exclude inlining attributes.
+ (handle_tls_model_attribute): Improve diagnostics.
+
2018-11-12 Jason Merrill <jason@redhat.com>
* c-cppbuiltin.c (c_cpp_builtins): Define
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 5e3b127..1657df7 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -2239,14 +2239,17 @@ handle_copy_attribute (tree *node, tree name, tree args,
/* Copy decl attributes from REF to DECL. */
for (tree at = attrs; at; at = TREE_CHAIN (at))
{
- /* Avoid copying attributes that affect a symbol linkage or
- visibility since those in all likelihood only apply to
- the target.
+ /* Avoid copying attributes that affect a symbol linkage,
+ inlining, or visibility since those in all likelihood
+ only apply to the target.
FIXME: make it possible to specify which attributes to
copy or not to copy in the copy attribute itself. */
tree atname = get_attribute_name (at);
if (is_attribute_p ("alias", atname)
+ || is_attribute_p ("always_inline", atname)
+ || is_attribute_p ("gnu_inline", atname)
|| is_attribute_p ("ifunc", atname)
+ || is_attribute_p ("noinline", atname)
|| is_attribute_p ("visibility", atname)
|| is_attribute_p ("weak", atname)
|| is_attribute_p ("weakref", atname))
@@ -2458,9 +2461,18 @@ handle_tls_model_attribute (tree *node, tree name, tree args,
tree decl = *node;
enum tls_model kind;
- if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl))
+ if (!VAR_P (decl))
{
- warning (OPT_Wattributes, "%qE attribute ignored", name);
+ warning (OPT_Wattributes, "%qE attribute ignored because %qD "
+ "is not a variable",
+ name, decl);
+ return NULL_TREE;
+ }
+
+ if (!DECL_THREAD_LOCAL_P (decl))
+ {
+ warning (OPT_Wattributes, "%qE attribute ignored because %qD does "
+ "not have thread storage duration", name, decl);
return NULL_TREE;
}
@@ -2468,7 +2480,7 @@ handle_tls_model_attribute (tree *node, tree name, tree args,
id = TREE_VALUE (args);
if (TREE_CODE (id) != STRING_CST)
{
- error ("tls_model argument not a string");
+ error ("%qE argument not a string", name);
return NULL_TREE;
}
@@ -2481,7 +2493,9 @@ handle_tls_model_attribute (tree *node, tree name, tree args,
else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic"))
kind = TLS_MODEL_GLOBAL_DYNAMIC;
else
- error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\"");
+ error ("%qE argument must be one of %qs, %qs, %qs, or %qs",
+ name,
+ "local-exec", "initial-exec", "local-dynamic", "global-dynamic");
set_decl_tls_model (decl, kind);
return NULL_TREE;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f9a2ee4..919c478 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-13 Martin Sebor <msebor@redhat.com>
+
+ PR middle-end/81824
+ * gcc.dg/attr-copy-5.c: New test.
+ * gcc.dg/tls/diag-6.c: Adjust expected diagnostics.
+
2018-11-13 Richard Biener <rguenther@suse.de>
PR tree-optimization/86991
diff --git a/gcc/testsuite/gcc.dg/attr-copy-5.c b/gcc/testsuite/gcc.dg/attr-copy-5.c
new file mode 100644
index 0000000..b085cf96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/attr-copy-5.c
@@ -0,0 +1,57 @@
+/* PR middle-end/81824 - Warn for missing attributes with function aliases
+ Verify that attributes always_inline, gnu_inline, and noinline aren't
+ copied. Also verify that copying attribute tls_model to a non-thread
+ variable triggers a warning.
+ { dg-do compile }
+ { dg-options "-Wall" }
+ { dg-require-effective-target tls } */
+
+#define ATTR(...) __attribute__ ((__VA_ARGS__))
+
+ATTR (always_inline, gnu_inline, noreturn) inline int
+finline_noret (void)
+{
+ __builtin_abort ();
+ /* Expect no -Wreturn-type. */
+}
+
+int call_finline_noret (void)
+{
+ finline_noret ();
+ /* Expect no -Wreturn-type. */
+}
+
+
+ATTR (copy (finline_noret)) int
+fnoret (void);
+
+int call_fnoret (void)
+{
+ fnoret ();
+ /* Expect no -Wreturn-type. */
+}
+
+
+/* Verify that attribute always_inline on an alias target doesn't
+ get copied and interfere with attribute noinline on the alias
+ (trigger a warning due to a conflict). */
+
+ATTR (always_inline) static inline int
+finline (void) { return 0; }
+
+ATTR (alias ("finline"), noinline) int
+fnoinline (void);
+
+ATTR (copy (finline)) int
+fnoinline (void);
+
+
+ATTR (tls_model ("global-dynamic")) __thread int
+ tls_target;
+
+ATTR (alias ("tls_target"), copy (tls_target)) extern __thread int
+ thread_alias;
+
+
+ATTR (alias ("tls_target"), copy (tls_target)) extern int
+ alias; /* { dg-warning ".tls_model. attribute ignored because .alias. does not have thread storage duration" } */
diff --git a/gcc/testsuite/gcc.dg/tls/diag-6.c b/gcc/testsuite/gcc.dg/tls/diag-6.c
index 71b0b95..171bf21 100644
--- a/gcc/testsuite/gcc.dg/tls/diag-6.c
+++ b/gcc/testsuite/gcc.dg/tls/diag-6.c
@@ -4,5 +4,5 @@
int v __attribute__((tls_model("initial-exec"))); /* { dg-warning "attribute ignored" } */
typedef int X __attribute__((tls_model("initial-exec"))); /* { dg-warning "attribute ignored" } */
void f(int x __attribute__((tls_model("initial-exec")))); /* { dg-warning "attribute ignored" } */
-__thread int a __attribute__((tls_model(1))); /* { dg-error "tls_model argument not a string" } */
-__thread int b __attribute__((tls_model("unknown"))); /* { dg-error "tls_model argument must be one of" } */
+__thread int a __attribute__((tls_model(1))); /* { dg-error ".tls_model. argument not a string" } */
+__thread int b __attribute__((tls_model("unknown"))); /* { dg-error ".tls_model. argument must be one of" } */