Changing ACLiC compilation flags


ROOT Version: 6.19/01
Platform: Ubuntu
Compiler: g++ 5.4


I’m trying to suppress some warnings during the compilation of a macro inside rootlogon.C:

gSystem->CompileMacro("macro.C", "kgO-", "macro", ".");

First I tried with:

gSystem->SetFlagsDebug("-g -Wno-narrowing");

but nothing changed.

Then I tried with:

TString o = gSystem->GetMakeSharedLib();
o.ReplaceAll("$Opt", "$Opt -Wno-narrowing");
gSystem->SetMakeSharedLib(o.Data());
cout << gSystem->GetMakeSharedLib() << endl;

and again nothing changed, even if GetMakeSharedLib returns the correct result.
If I try to compile manually the macro from command line, using exactly the same instruction from GetMakeSharedLib, then the compilation is successful and the warnings disappear.

I also tried:

gIntepreter->ProcessLine(Form("gSystem->SetMakeSharedLib(\"%s\");", o.Data());

but again no luck.

Indeed, it looks like ACLiC doesn’t really care about SetMakeSharedLib: if I set it to an empy string, CompileMacro will still try to compile the macro as before…

Any thoughts?

Try: o.ReplaceAll(" -W ", " -W -Wno-narrowing ");

Hi Wile, here’s the result:

root [0] TString o = gSystem->GetMakeSharedLib();
root [1] o.ReplaceAll(" -W ", " -W -Wno-narrowing ");
root [2] gSystem->SetMakeSharedLib(o.Data());
root [3] cout << gSystem->GetMakeSharedLib() << endl;
cd $BuildDir ; c++ -fPIC -c $Opt -std=c++14 -pipe -W -Wno-narrowing -Woverloaded-virtual -fsigned-char -pthread -DR__HAVE_CONFIG -fabi-version=0 -march=native $IncludePath $SourceFiles ; c++ $Opt $ObjectFiles -shared  $LinkedLibs -o $SharedLib
root [4] .L narrow.C++g
Info in <TUnixSystem::ACLiC>: creating shared library ~/Downloads/./narrow_C.so
In file included from input_line_12:6:
././narrow.C:7:29: error: non-constant-expression cannot be narrowed from type 'int' to 'unsigned short' in
      initializer list [-Wc++11-narrowing]
   unsigned short arr[] = { i+1 };
                            ^~~
././narrow.C:7:29: note: insert an explicit cast to silence this issue
   unsigned short arr[] = { i+1 };
                            ^~~
                            static_cast<unsigned short>( )
Error in <ACLiC>: Dictionary generation failed!

@Axel As I said before, it doesn’t really matter how I change SetMakeSharedLibs, ACLiC will not use the changed version, even if GetMakeSharedLibs returns the changed string:

root [0] gSystem->SetMakeSharedLib("echo THIS SHOULD NOT EVEN TRY TO COMPILE");
root [1] cout << gSystem->GetMakeSharedLib() << endl;
echo THIS SHOULD NOT EVEN TRY TO COMPILE
root [2] .L narrow.C++g
Info in <TUnixSystem::ACLiC>: creating shared library ~/Downloads/./narrow_C.so
In file included from input_line_12:6:
././narrow.C:7:29: error: non-constant-expression cannot be narrowed from type 'int' to 'unsigned short' in
      initializer list [-Wc++11-narrowing]
   unsigned short arr[] = { i+1 };
                            ^~~
././narrow.C:7:29: note: insert an explicit cast to silence this issue
   unsigned short arr[] = { i+1 };
                            ^~~
                            static_cast<unsigned short>( )
Error in <ACLiC>: Dictionary generation failed!

Try fixing your code by casting, as suggested by the compiler. It’s usually not safe to make narrowing conversions, but if you know your value will be in range, casting will get rid of the warning.

Yes, that’s a solution, but I have tens of these warnings in arrays with multiple items, so manually adding a cast to all instances is very tiresome…
I now that all these narrowing conversions are safe, so that’s not the issue here, the issue it’s that ACLiC doesn’t respect the modified compilation flags.

Try to add:

o = TString(gSystem->GetMakeExe());
o.ReplaceAll(" -W ", " -W -Wno-narrowing ");
gSystem->SetMakeExe(o.Data());

Actually, it seems that the ACLiC output tells you that it comes from the “-Wc++11-narrowing” flag so, maybe you need “-Wno-c++11-narrowing”.

Already tried, it doesn’t help.
Also, as far as I understand, .L should use fMakeSharedLibs, not fMakeExe.

That’s a clang flag: -Wnarrowing is an alias to -Wc++11-narrowing: https://clang.llvm.org/docs/DiagnosticsReference.html#wnarrowing
However, my compiler is g++, and for g++ the flag is -Wnarrowing.

Indeed … the error message comes from clang through the rootcling invocation (one of the 3 steps in ACLiC) and that steps is not influence by SetMakeShared.

One way to influence that invocation is to update the ACLiC.IncludePaths entry in a rootrc file (eg ${HOME}/.rootrc … see $ROOTSYS/etc/system.rootrc for an example and some documentation).
[Another more risky is to use gSystem->AddIncludePath)

I’m confused, the documentation for CompileMacro says:

It uses the directive fMakeSharedLibs to create a shared library.
[…]
Through the function TSystem::SetMakeSharedLib(), the user will be able to indicate, with shell commands, how to build a shared library […]

but from your sentence (and from my tests) it looks like fMakeSharedLibs is ignored.
Indeed, on my system fMakeSharedLibs contains c++, which is a link to g++, not clang.

One way to influence that invocation is to update the ACLiC.IncludePaths entry in a rootrc file

I added this line to my ~/.rootrc:

ACLiC.IncludePaths: -Wno-narrowing

but it didn’t have any effects: was this your idea?
Same negative result by using gSystem->AddIncludePath.
By the way, why do you say it’s more risky?
I would think that it’s better to change IncludePath only for one macro, instead of changing it globally in ~/.rootrc.

AddIncludePath is ‘more’ risky as it is intended for -I and some operation may be rely on that.

but from your sentence (and from my tests) it looks like fMakeSharedLibs is ignored.

it is not, it is used as indicated only for the “create the share library part”.

There is several part to CompileMacro/ACLiC.

a. Generate a LinkDef file
b. Generate a dictionary source file (.cxx) by invoking rootcling passing the input file and LinkDef file
c. Generate the object file (.o) by compiling the dictionary source file with the compiler and option -c
d. Generate the shared library (.so) by using the compiler with the option -shared

Step c. and d. uses the pattern given by gSystem->GetMakeSharedLib()

Step b. does not use that pattern (and this is step the issue your warning).

It is plausible that newer version of rootcling are ignoring the -W flag (if this is the case, you should file a JIRA ticket).

Note that you can see the commands actually used by ACLiC by use the ‘v’ suffix and then you can reproduce some of the steps by also keeping the files by using the ‘k’ suffix. See the output and files left by:

.L macro.C+kv
or
gSystem->CompileMacro("macro.C", "vkgO-", "macro", ".");

Cheers,
Philippe.

PS. It may also be ‘simpler’ to hide the implementation from rootcling by judicious use of #ifndef __ROOTCLING__

Now it’s more clear, thanks!

It is plausible that newer version of rootcling are ignoring the -W flag (if this is the case, you should file a JIRA ticket).

Apparently it’s passed to rootcling, at least that’s what it looks like from using the ‘v’ suffix, but it still gives error (I highlighted the occurrences of -Wno-narrowing):

root [0] gSystem->AddIncludePath(“-Wno-narrowing”);
root [1] .L narrow.C+gkv
Info in TUnixSystem::ACLiC: creating shared library ./narrow_C.so
Info in TUnixSystem::ACLiC: looking for header in: .:~/programs/root6/install/include/root -Wno-narrowing:“~/programs/root6/install/etc/root”:“~/programs/root6/install/etc/root/cling”:“~/programs/root6/install/include/root”:“~/programs/root6/install/include”:“/usr/local/lib/cmake/VecCore/…/…/…/include”:
Info in : creating the dictionary files
Info in : ~/programs/root6/install/bin/rootcling -v0 “–lib-list-prefix=narrow_C_ACLiC_map” -f “narrow_C_ACLiC_dict.cxx” -I~/programs/root6/install/include/root -Wno-narrowing -I"~/programs/root6/install/etc/root" -I"~/programs/root6/install/etc/root/cling" -I"~/programs/root6/install/include/root" -I"~/programs/root6/install/include" -I"/usr/local/lib/cmake/VecCore/…/…/…/include" -D__ACLIC__ “./narrow.C” “narrow_C_ACLiC_linkdef.h”
Info in : compiling the dictionary and script files
Info in : cd “~/Downloads” ; c++ -fPIC -c -g -std=c++14 -pipe -W -Woverloaded-virtual -fsigned-char -pthread -DR__HAVE_CONFIG -fabi-version=0 -march=native -I~/programs/root6/install/include/root -Wno-narrowing -I"~/programs/root6/install/etc/root" -I"~/programs/root6/install/etc/root/cling" -I"~/programs/root6/install/include/root" -I"~/programs/root6/install/include" -I"/usr/local/lib/cmake/VecCore/…/…/…/include" -D__ACLIC__ “narrow_C_ACLiC_dict.cxx” ; c++ -g “narrow_C_ACLiC_dict.o” -shared “~/programs/root6/install/lib/root/libRint.so” “~/programs/root6/install/lib/root/libCore.so” “~/programs/root6/install/lib/root/libRIO.so” “~/programs/root6/install/lib/root/libThread.so” “~/programs/root6/install/lib/root/libCling.so” “~/programs/root6/install/lib/root/libMathCore.so” “~/programs/root6/install/lib/root/libImt.so” “~/programs/root6/install/lib/root/libtbb.so.2” -o “./narrow_C.so”
Info in : loading the shared library
In file included from narrow_C_ACLiC_dict dictionary payload:8:
././narrow.C:7:29: error: non-constant-expression cannot be narrowed from type ‘int’ to ‘unsigned short’ in initializer list [-Wc++11-narrowing]
unsigned short arr = { i+1 };
^~~
././narrow.C:7:29: note: insert an explicit cast to silence this issue
unsigned short arr = { i+1 };
^~~
static_cast( )
Warning in TInterpreter::TCling::RegisterModule: Problems declaring payload for module narrow_C_ACLiC_dict.
~/programs/root6/install/bin/rootcling -v0 --lib-list-prefix=narrow_C_ACLiC_map -f narrow_C_ACLiC_dict.cxx -I~/programs/root6/install/include/root -Wno-narrowing -I~/programs/root6/install/etc/root -I~/programs/root6/install/etc/root/cling -I~/programs/root6/install/include/root -I~/programs/root6/install/include -I/usr/local/lib/cmake/VecCore/…/…/…/include -D__ACLIC__ ./narrow.C narrow_C_ACLiC_linkdef.h
cd ~/Downloads ; c++ -fPIC -c -g -std=c++14 -pipe -W -Woverloaded-virtual -fsigned-char -pthread -DR__HAVE_CONFIG -fabi-version=0 -march=native -I~/programs/root6/install/include/root -Wno-narrowing -I~/programs/root6/install/etc/root -I~/programs/root6/install/etc/root/cling -I~/programs/root6/install/include/root -I~/programs/root6/install/include -I/usr/local/lib/cmake/VecCore/…/…/…/include -D__ACLIC__ narrow_C_ACLiC_dict.cxx ; c++ -g narrow_C_ACLiC_dict.o -shared ~/programs/root6/install/lib/root/libRint.so ~/programs/root6/install/lib/root/libCore.so ~/programs/root6/install/lib/root/libRIO.so ~/programs/root6/install/lib/root/libThread.so ~/programs/root6/install/lib/root/libCling.so ~/programs/root6/install/lib/root/libMathCore.so ~/programs/root6/install/lib/root/libImt.so ~/programs/root6/install/lib/root/libtbb.so.2 -o ./narrow_C.so
cd ~/Downloads ; c++ -c -std=c++14 -pipe -W -Woverloaded-virtual -fsigned-char -pthread -DR__HAVE_CONFIG -fabi-version=0 -march=native -I~/programs/root6/install/include/root -Wno-narrowing -I~/programs/root6/install/etc/root -I~/programs/root6/install/etc/root/cling -I~/programs/root6/install/include/root -I~/programs/root6/install/include -I/usr/local/lib/cmake/VecCore/…/…/…/include -D__ACLIC__ narrow_C_ACLiC_dict.cxx; c++ narrow_C_ACLiC_dict.o -o narrow_C_ACLiC_exec ~/programs/root6/install/lib/root/libRint.so ~/programs/root6/install/lib/root/libCore.so ~/programs/root6/install/lib/root/libRIO.so ~/programs/root6/install/lib/root/libThread.so ~/programs/root6/install/lib/root/libCling.so ~/programs/root6/install/lib/root/libMathCore.so ~/programs/root6/install/lib/root/libImt.so ~/programs/root6/install/lib/root/libtbb.so.2

I’ll open a ticket.

Meanwhile, a quick workaround is to disable specific clang diagnostics with a pragma directive at the beginning of the macro:

#pragma clang diagnostic ignored "-Wnarrowing"

It would be useful also if there was an additional gSystem function to modify the compilation flags for cling.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.