[PATCH] Warn for ignored ASM labels on typdef declarations
Will Hawkins
whh8b@virginia.edu
Wed Apr 18 21:51:00 GMT 2018
Hello everyone!
First, let me ask for your patience -- this is the first patch I am
submitting to gcc. I tried very hard to follow the proper procedure,
but I am sure that I've missed something.
According to https://gcc.gnu.org/onlinedocs/gcc/Asm-Labels.html#Asm-Labels
asm labels have no effect on anything other than variable and function
declarations. When an asm label is included on a typedef, the compiler
happily goes along but does not indicate anything to the user.
For instance, when parsing
typedef struct {} x asm ("X");
the compiler silently discards the asm label. This patch will generate
a warning (at -Wpedantic) for such a situation. This is in Bugzilla as
85444.
Again, I hope that I have done all the proper formatting so that it is
inline with all the contribution guidelines. Thank you for your
patience!
Will
2018-04-18 Will Hawkins <whh8b@virginia.edu>
* gcc/c/c-decl.c: Warn about ignored asm label for
typedef declaration
* gcc/cp/decl.c: Warn about ignored asm label for
typedef declaration
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index f0198ec..e9c0a72 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -5166,7 +5166,11 @@ finish_decl (tree decl, location_t init_loc, tree init,
if (!DECL_FILE_SCOPE_P (decl)
&& variably_modified_type_p (TREE_TYPE (decl), NULL_TREE))
add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl));
-
+ if (asmspec_tree != NULL_TREE)
+ {
+ warning (OPT_Wpedantic, "asm-specifier is ignored in "
+ "typedef declaration");
+ }
rest_of_decl_compilation (decl, DECL_FILE_SCOPE_P (decl), 0);
}
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 44a152b..88b4b94 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7069,6 +7069,11 @@ cp_finish_decl (tree decl, tree init, bool
init_const_expr_p,
/* Take care of TYPE_DECLs up front. */
if (TREE_CODE (decl) == TYPE_DECL)
{
+ if (asmspec_tree != NULL_TREE)
+ {
+ warning (OPT_Wpedantic, "asm-specifier is ignored for "
+ "typedef declarations");
+ }
if (type != error_mark_node
&& MAYBE_CLASS_TYPE_P (type) && DECL_NAME (decl))
{
More information about the Gcc-patches
mailing list