Skip to content

Commit

Permalink
Use CCTK_ATTRIBUTE_UNUSED to mark declared variables as unused
Browse files Browse the repository at this point in the history
In automatically-generated code, it is often convenient to declare variables unconditionally, and let the compiler strip the unused definitions out.  Eventually it would be good to tidy up Kranc so that it only declares variables which are actually needed, but for the moment it is more important to reduce the number of warnings generated during compilation, to encourage users to read the warnings that might actually indicate a problem.
  • Loading branch information
ianhinder committed Nov 19, 2012
1 parent 17deb8b commit b001993
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Tools/CodeGen/CalculationFunction.m
Expand Up @@ -273,7 +273,7 @@ pathalogical enough (e.g. {s1 -> s2, s2 -> s1} would not be
cleanExpr = ReplacePowers[expr, vectorise, noSimplify];

If[SOURCELANGUAGE == "C",
code = If[declare, type <> " ", ""] <> ToString[dest] <> " = " <>
code = If[declare, type <> " CCTK_ATTRIBUTE_UNUSED ", ""] <> ToString[dest] <> " = " <>
ToString[cleanExpr, CForm, PageWidth -> Infinity] <> ";\n",
code = ToString@dest <> ".eq." <> ToString[cleanExpr, FortranForm, PageWidth -> 120]
<> "\n"];
Expand Down
10 changes: 5 additions & 5 deletions Tools/CodeGen/CodeGenC.m
Expand Up @@ -97,19 +97,19 @@
DefFn[
DeclareVariable[name:(_String|_Symbol), type_String] :=
If[SOURCELANGUAGE == "C",
{type, " ", name, " = INITVALUE" <> EOL[]},
{type, " ", name, " CCTK_ATTRIBUTE_UNUSED ", " = INITVALUE" <> EOL[]},
{type, " :: ", name, EOL[]} (* no value init here to avoid implicit SAVE attribute *)]];

DefFn[
DeclareVariableNoInit[name:(_String|_Symbol), type_String] :=
If[SOURCELANGUAGE == "C",
{type, " ", name, EOL[]},
{type, " ", name, " CCTK_ATTRIBUTE_UNUSED ",EOL[]},
{type, " :: ", name, EOL[]} (* no value init here to avoid implicit SAVE attribute *)]];

DefFn[
DeclareVariables[names_?ListQ, type_String] :=
If[SOURCELANGUAGE == "C",
{type, " ", CommaSeparated@names, EOL[]},
{type, " ", CommaSeparated@names, " CCTK_ATTRIBUTE_UNUSED ", EOL[]},
{type, " :: ", CommaSeparated@names, EOL[]} (* no value init avoids implicit SAVE attribute *)]];

DefFn[
Expand Down Expand Up @@ -140,15 +140,15 @@

DefFn[
DefineVariable[name:(_String|_Symbol), type_String, value:CodeGenBlock] :=
{type, " ", name, " = ", value, EOL[]}];
{type, " ", name, " CCTK_ATTRIBUTE_UNUSED ", " = ", value, EOL[]}];

DefFn[
AssignVariable[dest:(_String|_Symbol), src:CodeGenBlock] :=
{dest, " = ", src, EOL[]}];

DefFn[
DeclareAssignVariable[type_String, dest:(_String|_Symbol), src:CodeGenBlock] :=
{type, " const ", dest, " = ", src, EOL[]}];
{type, " const ", dest, " CCTK_ATTRIBUTE_UNUSED ", " = ", src, EOL[]}];

(* comments are always done C-style because they are killed by cpp anyway *)
DefFn[
Expand Down
6 changes: 3 additions & 3 deletions Tools/CodeGen/CodeGenCactus.m
Expand Up @@ -112,7 +112,7 @@

DefFn[
DeclareAssignVariableInLoop[type_String, dest:(_String|_Symbol), src:(_String|_Symbol)] :=
{type, " const ", dest, " = vec_load(", src, ")", EOL[]}];
{type, " const ", dest, " CCTK_ATTRIBUTE_UNUSED = vec_load(", src, ")", EOL[]}];

DefFn[
MaybeAssignVariableInLoop[dest:(_String|_Symbol), src:(_String|_Symbol), cond:Boolean] :=
Expand All @@ -128,8 +128,8 @@
{loader},
loader[x_] := If[vectorise, {"vec_load(", x, ")"}, x];
If[mmaCond,
{type, " ", dest, " = (", codeCond, ") ? ", loader[src], " : ToReal(0.0)", EOL[]},
{type, " ", dest, " = ", loader[src], EOL[]}]]];
{type, " ", dest, " CCTK_ATTRIBUTE_UNUSED = (", codeCond, ") ? ", loader[src], " : ToReal(0.0)", EOL[]},
{type, " ", dest, " CCTK_ATTRIBUTE_UNUSED = ", loader[src], EOL[]}]]];

DefFn[
TestForNaN[expr:CodeGenBlock] :=
Expand Down
6 changes: 3 additions & 3 deletions Tools/CodeGen/Jacobian.m
Expand Up @@ -126,14 +126,14 @@
"if (use_jacobian) GenericFD_GroupDataPointers(cctkGH, jacobian_group,\n",
" 9, jacobian_ptrs);\n",
"\n",
Table[{"CCTK_REAL const *restrict const J",i,j," = use_jacobian ? jacobian_ptrs[",(i-1)*3+j-1,"] : 0;\n"},{i,1,3},{j,1,3}],
Table[{"CCTK_REAL const *restrict const J",i,j," CCTK_ATTRIBUTE_UNUSED = use_jacobian ? jacobian_ptrs[",(i-1)*3+j-1,"] : 0;\n"},{i,1,3},{j,1,3}],
"\n",
"CCTK_REAL const *restrict jacobian_derivative_ptrs[18];\n",
"CCTK_REAL const *restrict jacobian_derivative_ptrs[18] CCTK_ATTRIBUTE_UNUSED;\n",
"if (use_jacobian) GenericFD_GroupDataPointers(cctkGH, jacobian_derivative_group,\n",
" 18, jacobian_derivative_ptrs);\n",
"\n",
Module[{syms = Flatten[Table[{"dJ",i,j,k},{i,1,3},{j,1,3},{k,j,3}],2]},
MapIndexed[{"CCTK_REAL const *restrict const ", #1, " = use_jacobian ? jacobian_derivative_ptrs[", #2-1, "] : 0;\n"} &, syms]]}];
MapIndexed[{"CCTK_REAL const *restrict const ", #1, " CCTK_ATTRIBUTE_UNUSED = use_jacobian ? jacobian_derivative_ptrs[", #2-1, "] : 0;\n"} &, syms]]}];

(* List of symbols which should be allowed in a calculation *)
JacobianSymbols[] :=
Expand Down

0 comments on commit b001993

Please sign in to comment.