From: uz Date: Thu, 15 Oct 2009 19:18:34 +0000 (+0000) Subject: Warn when structs are passed by value to a function. X-Git-Tag: V2.13.1~155 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f92d6bfa22a4fa7ff9d059e80d722e66bcf989e;p=cc65 Warn when structs are passed by value to a function. git-svn-id: svn://svn.cc65.org/cc65/trunk@4369 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/cc65/declare.c b/src/cc65/declare.c index fbbe5529d..40235ea84 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1167,6 +1167,13 @@ static void ParseAnsiParamList (FuncDesc* F) /* Create a symbol table entry */ AddLocalSym (Decl.Ident, ParamTypeCvt (Decl.Type), Decl.StorageClass, 0); + /* If the parameter is a struct or union, emit a warning */ + if (IsClassStruct (Decl.Type)) { + if (IS_Get (&WarnStructParam)) { + Warning ("Passing struct by value for parameter `%s'", Decl.Ident); + } + } + /* Count arguments */ ++F->ParamCount; diff --git a/src/cc65/error.c b/src/cc65/error.c index 95549216b..f73f0a4a0 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -63,6 +63,7 @@ unsigned WarningCount = 0; /* Warning and error options */ IntStack WarnEnable = INTSTACK(1); /* Enable warnings */ IntStack WarningsAreErrors = INTSTACK(0); /* Treat warnings as errors */ +IntStack WarnStructParam = INTSTACK(1); /* Warn about structs passed by val */ IntStack WarnUnusedLabel = INTSTACK(1); /* Warn about unused labels */ IntStack WarnUnusedParam = INTSTACK(1); /* Warn about unused parameters */ IntStack WarnUnusedVar = INTSTACK(1); /* Warn about unused variables */ @@ -77,6 +78,7 @@ struct WarnMapEntry { static WarnMapEntry WarnMap[] = { /* Keep sorted, even if this isn't used for now */ { &WarningsAreErrors, "error" }, + { &WarnStructParam, "struct-param" }, { &WarnUnknownPragma, "unknown-pragma" }, { &WarnUnusedLabel, "unused-label" }, { &WarnUnusedParam, "unused-param" }, diff --git a/src/cc65/error.h b/src/cc65/error.h index d51b9093b..ad66a1506 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -60,6 +60,7 @@ extern unsigned WarningCount; /* Warning and error options */ extern IntStack WarnEnable; /* Enable warnings */ extern IntStack WarningsAreErrors; /* Treat warnings as errors */ +extern IntStack WarnStructParam; /* Warn about structs passed by val */ extern IntStack WarnUnusedLabel; /* Warn about unused labels */ extern IntStack WarnUnusedParam; /* Warn about unused parameters */ extern IntStack WarnUnusedVar; /* Warn about unused variables */