Skip to content

Commit

Permalink
Avoid compiler warning in rootcling and rootcling_stage1
Browse files Browse the repository at this point in the history
Warning:
root/core/rootcling_stage1/src/rootcling_stage1.cxx(38):
	warning root-project#69: integer conversion resulted in truncation

   auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym;
                    ^^^

The method above uses a cast to long, followed by a cast to int,
which results in a truncation. That is harmless, since the value
is never used, but generates a compiler warning with ICC 17. This
commit avoids the warning by storing the address of the same symbol
in a static variable instead.
  • Loading branch information
amadio committed Jul 12, 2017
1 parent edee437 commit 95d9fb5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 3 additions & 6 deletions core/rootcling_stage1/src/rootcling_stage1.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extern "C" {
R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {}
}

// force compiler to emit symbol for function above
static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym;

ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter;

Expand All @@ -32,12 +34,7 @@ static const char *GetEtcDir() {

int main(int argc, char **argv)
{
// Force the emission of the symbol - the compiler cannot know that argv
// is always set.
if (!argv) {
auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym;
return dummyVal;
}
(void) dlsymaddr; // avoid unused variable warning

ROOT::Internal::RootCling::DriverConfig config{};

Expand Down
10 changes: 4 additions & 6 deletions main/src/rootcling.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ extern "C" {
R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {}
}

// force compiler to emit symbol for function above
static void (*dlsymaddr)() = &usedToIdentifyRootClingByDlSym;

int main(int argc, char **argv)
{
// Force the emission of the symbol - the compiler cannot know that argv
// is always set.
if (!argv) {
auto dummyVal = (int)(long)&usedToIdentifyRootClingByDlSym;
return dummyVal;
}
(void) dlsymaddr; // avoid unused variable warning

ROOT::Internal::RootCling::DriverConfig config{};

Expand Down

0 comments on commit 95d9fb5

Please sign in to comment.