aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2015-04-29 20:32:41 +0000
committerJeff Law <law@gcc.gnu.org>2015-04-29 14:32:41 -0600
commit0373796b4d886711d59f19dcffb6e0cbe19969cd (patch)
tree3aa351241ff8ef05858111d20e1931f9627bd2cb
parent8d92d2743c400d2b0bf14954e14bc343e1953168 (diff)
downloadgcc-0373796b4d886711d59f19dcffb6e0cbe19969cd.zip
gcc-0373796b4d886711d59f19dcffb6e0cbe19969cd.tar.gz
gcc-0373796b4d886711d59f19dcffb6e0cbe19969cd.tar.bz2
c-common.c (handle_section_attribute): Refactor to reduce nesting and distinguish between error cases.
* c-common.c (handle_section_attribute): Refactor to reduce nesting and distinguish between error cases. From-SVN: r222590
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-common.c91
2 files changed, 51 insertions, 45 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index 44e21f3..c17ea5f 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2015-04-29 Josh Triplett <josh@joshtriplett.org>
+
+ * c-common.c (handle_section_attribute): Refactor to reduce
+ nesting and distinguish between error cases.
+
2015-04-29 Marek Polacek <polacek@redhat.com>
PR c/64610
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index eecbe41..7d314f8 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -7602,58 +7602,59 @@ handle_section_attribute (tree *node, tree ARG_UNUSED (name), tree args,
{
tree decl = *node;
- if (targetm_common.have_named_sections)
+ if (!targetm_common.have_named_sections)
{
- user_defined_section_attribute = true;
+ error_at (DECL_SOURCE_LOCATION (*node),
+ "section attributes are not supported for this target");
+ goto fail;
+ }
- if ((TREE_CODE (decl) == FUNCTION_DECL
- || TREE_CODE (decl) == VAR_DECL)
- && TREE_CODE (TREE_VALUE (args)) == STRING_CST)
- {
- if (TREE_CODE (decl) == VAR_DECL
- && current_function_decl != NULL_TREE
- && !TREE_STATIC (decl))
- {
- error_at (DECL_SOURCE_LOCATION (decl),
- "section attribute cannot be specified for "
- "local variables");
- *no_add_attrs = true;
- }
+ user_defined_section_attribute = true;
- /* The decl may have already been given a section attribute
- from a previous declaration. Ensure they match. */
- else if (DECL_SECTION_NAME (decl) != NULL
- && strcmp (DECL_SECTION_NAME (decl),
- TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
- {
- error ("section of %q+D conflicts with previous declaration",
- *node);
- *no_add_attrs = true;
- }
- else if (TREE_CODE (decl) == VAR_DECL
- && !targetm.have_tls && targetm.emutls.tmpl_section
- && DECL_THREAD_LOCAL_P (decl))
- {
- error ("section of %q+D cannot be overridden", *node);
- *no_add_attrs = true;
- }
- else
- set_decl_section_name (decl,
- TREE_STRING_POINTER (TREE_VALUE (args)));
- }
- else
- {
- error ("section attribute not allowed for %q+D", *node);
- *no_add_attrs = true;
- }
+ if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
+ {
+ error ("section attribute not allowed for %q+D", *node);
+ goto fail;
}
- else
+
+ if (TREE_CODE (TREE_VALUE (args)) != STRING_CST)
{
- error_at (DECL_SOURCE_LOCATION (*node),
- "section attributes are not supported for this target");
- *no_add_attrs = true;
+ error ("section attribute argument not a string constant");
+ goto fail;
+ }
+
+ if (TREE_CODE (decl) == VAR_DECL
+ && current_function_decl != NULL_TREE
+ && !TREE_STATIC (decl))
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "section attribute cannot be specified for local variables");
+ goto fail;
}
+ /* The decl may have already been given a section attribute
+ from a previous declaration. Ensure they match. */
+ if (DECL_SECTION_NAME (decl) != NULL
+ && strcmp (DECL_SECTION_NAME (decl),
+ TREE_STRING_POINTER (TREE_VALUE (args))) != 0)
+ {
+ error ("section of %q+D conflicts with previous declaration", *node);
+ goto fail;
+ }
+
+ if (TREE_CODE (decl) == VAR_DECL
+ && !targetm.have_tls && targetm.emutls.tmpl_section
+ && DECL_THREAD_LOCAL_P (decl))
+ {
+ error ("section of %q+D cannot be overridden", *node);
+ goto fail;
+ }
+
+ set_decl_section_name (decl, TREE_STRING_POINTER (TREE_VALUE (args)));
+ return NULL_TREE;
+
+fail:
+ *no_add_attrs = true;
return NULL_TREE;
}