Skip to content

Commit

Permalink
iASL: Add new warnings for method LocalX and ArgX variables.
Browse files Browse the repository at this point in the history
1) Warn if a Local is set but never used
2) Warn if a ArgX is never used (for non-predefined method names)
3) Warn if a ArgX that is used as a local is never used
  • Loading branch information
acpibob committed Jun 25, 2015
1 parent 03c66d2 commit eb9f8cb
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 156 deletions.
65 changes: 65 additions & 0 deletions source/compiler/asllookup.c
Expand Up @@ -191,8 +191,73 @@ LkIsObjectUsed (
{
ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
ACPI_NAMESPACE_NODE *Next;
ASL_METHOD_LOCAL *MethodLocals;
ASL_METHOD_LOCAL *MethodArgs;
UINT32 i;


if (Node->Type == ACPI_TYPE_METHOD)
{
if (!Node->Op || !Node->MethodLocals)
{
return (AE_OK);
}

MethodLocals = (ASL_METHOD_LOCAL *) Node->MethodLocals;
MethodArgs = (ASL_METHOD_LOCAL *) Node->MethodArgs;

/*
* Analysis of LocalX variables
*/
for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
{
/* Warn for Locals that are set but never referenced */

if ((MethodLocals[i].Flags & ASL_LOCAL_INITIALIZED) &&
(!(MethodLocals[i].Flags & ASL_LOCAL_REFERENCED)))
{
sprintf (MsgBuffer, "Local%u", i);
AslError (ASL_WARNING, ASL_MSG_LOCAL_NOT_USED,
MethodLocals[i].Op, MsgBuffer);
}
}

/*
* Analysis of ArgX variables (standard method arguments,
* and remaining unused ArgX can also be used as locals)
*/
for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
{
if (MethodArgs[i].Flags & ASL_ARG_IS_LOCAL)
{
/* Warn if ArgX is being used as a local, but not referenced */

if ((MethodArgs[i].Flags & ASL_ARG_INITIALIZED) &&
(!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
{
sprintf (MsgBuffer, "Arg%u", i);
AslError (ASL_WARNING, ASL_MSG_ARG_AS_LOCAL_NOT_USED,
MethodArgs[i].Op, MsgBuffer);
}
}
else
{
/*
* Remark if a normal method ArgX is not referenced.
* We ignore the predefined methods since often, not
* all arguments are needed or used.
*/
if ((Node->Name.Ascii[0] != '_') &&
(!(MethodArgs[i].Flags & ASL_ARG_REFERENCED)))
{
sprintf (MsgBuffer, "Arg%u", i);
AslError (ASL_REMARK, ASL_MSG_ARG_NOT_USED,
MethodArgs[i].Op, MsgBuffer);
}
}
}
}

/* Referenced flag is set during the namespace xref */

if (Node->Flags & ANOBJ_IS_REFERENCED)
Expand Down
6 changes: 5 additions & 1 deletion source/compiler/aslmessages.c
Expand Up @@ -307,7 +307,11 @@ const char *AslCompilerMsgs [] =
/* ASL_MSG_BUFFER_ALLOCATION */ "Could not allocate line buffer",
/* ASL_MSG_MISSING_DEPENDENCY */ "Missing dependency",
/* ASL_MSG_ILLEGAL_FORWARD_REF */ "Illegal forward reference within a method",
/* ASL_MSG_ILLEGAL_METHOD_REF */ "Illegal reference across two methods"
/* ASL_MSG_ILLEGAL_METHOD_REF */ "Illegal reference across two methods",
/* ASL_MSG_LOCAL_NOT_USED */ "Method Local is set but never used",
/* ASL_MSG_ARG_AS_LOCAL_NOT_USED */ "Method Argument (as a local) is set but never used",
/* ASL_MSG_ARG_NOT_USED */ "Method Argument is never used"

};

/* Table compiler */
Expand Down
3 changes: 3 additions & 0 deletions source/compiler/aslmessages.h
Expand Up @@ -310,6 +310,9 @@ typedef enum
ASL_MSG_MISSING_DEPENDENCY,
ASL_MSG_ILLEGAL_FORWARD_REF,
ASL_MSG_ILLEGAL_METHOD_REF,
ASL_MSG_LOCAL_NOT_USED,
ASL_MSG_ARG_AS_LOCAL_NOT_USED,
ASL_MSG_ARG_NOT_USED,

/* These messages are used by the Data Table compiler only */

Expand Down
2 changes: 1 addition & 1 deletion source/compiler/aslmethod.c
Expand Up @@ -327,7 +327,7 @@ MtMethodAnalysisWalkBegin (
return (AE_ERROR);
}

RegisterNumber = (Op->Asl.AmlOpcode & 0x000F);
RegisterNumber = (Op->Asl.AmlOpcode & 0x0007);

/*
* If the local is being used as a target, mark the local
Expand Down
14 changes: 14 additions & 0 deletions source/compiler/asltypes.h
Expand Up @@ -374,5 +374,19 @@ typedef struct acpi_serial_info

} ACPI_SERIAL_INFO;

typedef struct asl_method_local
{
ACPI_PARSE_OBJECT *Op;
UINT8 Flags;

} ASL_METHOD_LOCAL;

/* Values for Flags field above */

#define ASL_LOCAL_INITIALIZED (1)
#define ASL_LOCAL_REFERENCED (1<<1)
#define ASL_ARG_IS_LOCAL (1<<2)
#define ASL_ARG_INITIALIZED (1<<3)
#define ASL_ARG_REFERENCED (1<<4)

#endif /* __ASLTYPES_H */

0 comments on commit eb9f8cb

Please sign in to comment.