nimble-dev / nimble

The base NIMBLE package for R
http://R-nimble.org
BSD 3-Clause "New" or "Revised" License
156 stars 23 forks source link

warnings about set but not used intermediate variables on Apple Silicon (M2) #1399

Closed paciorek closed 8 months ago

paciorek commented 8 months ago

I see this on an M2 Mac but not on Linux.

m <- nimbleModel(
    nimbleCode({
      y ~ dnorm(a, sd = 2)
      a ~ dnorm(mu, sd = 3)
      mu ~ dnorm(0, sd = 5)
    }), data = list(y = 4), inits = list(a = -1, mu = 0),
    buildDerivs = TRUE
  )

  mLaplace <- buildLaplace(model = m)
  mLaplaceNoSplit <- buildLaplace(model = m, control = list(split = FALSE))
  cm <- compileNimble(m)
  cL <- compileNimble(mLaplace, mLaplaceNoSplit, project = m, showCompilerOutput = TRUE)

Warnings are below. Most strangely, if I look at Interm_414 as an example, I see that it is used in the .cpp file:

int Interm_414
<snip>
Interm_414 = Interm_413.dim()[0];
Compiling

  [Note] This may take a minute.

  [Note] On some systems there may be some compiler warnings that can be safely ignored.

clang++ -arch arm64 -std=gnu++17 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DR_NO_REMAP   -DEIGEN_MPL2_ONLY=1 -I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/include" -Wno-misleading-indentation -Wno-ignored-attributes -Wno-deprecated-declarations  -I/opt/R/arm64/include    -fPIC  -falign-functions=64 -Wall -g -O2  -c P_3_AGHQuad.cpp -o P_3_AGHQuad.o

clang++ -arch arm64 -std=gnu++17 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -L/Library/Frameworks/R.framework/Resources/lib -L/opt/R/arm64/lib -o P_3_AGHQuad_01_18_09_40_16.so P_3_AGHQuad.o nimbleCppADbaseClass.o -L/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/nimble/CppCode -lnimble -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

using C++ compiler: ‘Apple clang version 15.0.0 (clang-1500.0.40.1)’

using SDK: ‘MacOSX14.0.sdk’

P_3_AGHQuad.cpp:1588:5: warning: variable 'Interm_414' set but not used [-Wunused-but-set-variable]

int Interm_414;

    ^

P_3_AGHQuad.cpp:1647:5: warning: variable 'Interm_420' set but not used [-Wunused-but-set-variable]

int Interm_420;

    ^

P_3_AGHQuad.cpp:5200:5: warning: variable 'Interm_349' set but not used [-Wunused-but-set-variable]

int Interm_349;

    ^

P_3_AGHQuad.cpp:5201:5: warning: variable 'Interm_350' set but not used [-Wunused-but-set-variable]

int Interm_350;

    ^

P_3_AGHQuad.cpp:5236:5: warning: variable 'Interm_367' set but not used [-Wunused-but-set-variable]

int Interm_367;

    ^

P_3_AGHQuad.cpp:5237:5: warning: variable 'Interm_368' set but not used [-Wunused-but-set-variable]

int Interm_368;

    ^

P_3_AGHQuad.cpp:5243:5: warning: variable 'Interm_373' set but not used [-Wunused-but-set-variable]

int Interm_373;

    ^

P_3_AGHQuad.cpp:5244:5: warning: variable 'Interm_374' set but not used [-Wunused-but-set-variable]

int Interm_374;

    ^
perrydv commented 8 months ago

I get these warnings on my Intel Mac also.

The issue is code like x[,1]. We end up generating a harmless but unnecessary bit of extra code. I am submitting a PR to clean this up.