Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Floating point exception in TPad (version 2) #6428

Closed
andriish opened this issue Sep 23, 2020 · 11 comments · Fixed by #6440
Closed

Floating point exception in TPad (version 2) #6428

andriish opened this issue Sep 23, 2020 · 11 comments · Fixed by #6440
Assignees
Labels

Comments

@andriish
Copy link
Contributor

Describe the bug

Crash.

[averbyts@lxplus701 test]$ ./pad2.exe
Warning in <UnknownClass::SetDisplay>: DISPLAY not set, setting it to 91.114.73.210:0.0

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fe989ecb46c in waitpid () from /lib64/libc.so.6
#1  0x00007fe989e48f62 in do_system () from /lib64/libc.so.6
#2  0x00007fe98ba740bc in TUnixSystem::StackTrace() () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libCore.so
#3  0x00007fe98ba716d5 in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libCore.so
#4  <signal handler called>
#5  0x00007fe98b1ddee9 in TPad::FillCollideGrid(TObject*) () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libGpad.so
#6  0x00007fe98b1de2eb in TPad::PlaceBox(TObject*, double, double, double&, double&) () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libGpad.so
#7  0x0000000000401293 in main (argc=<optimized out>, argv=<optimized out>) at /afs/cern.ch/user/a/averbyts/Projects/zevis/test/pad2.cxx:84
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007fe98b1ddee9 in TPad::FillCollideGrid(TObject*) () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libGpad.so
#6  0x00007fe98b1de2eb in TPad::PlaceBox(TObject*, double, double, double&, double&) () from /cvmfs/sft-nightlies.cern.ch/lcg/views/dev3python3/Wed/x86_64-centos7-gcc10-opt/lib/libGpad.so
#7  0x0000000000401293 in main (argc=<optimized out>, argv=<optimized out>) at /afs/cern.ch/user/a/averbyts/Projects/zevis/test/pad2.cxx:84
===========================================================


[averbyts@lxplus701 test]$ 

Expected behavior

No FPE.

To Reproduce

Code:

#include <TCanvas.h>
#include <TPad.h>
#include <TH1D.h>
#include <fenv.h>

#ifndef HAVE_FEENABLEEXCEPT
#if defined(__APPLE__) && defined(__MACH__)

// Public domain polyfill for feenableexcept on OS X
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c

inline int feenableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // unmask
    fenv.__control &= ~new_excepts;
    fenv.__mxcsr   &= ~(new_excepts << 7);

    return fesetenv(&fenv) ? -1 : old_excepts;
}

inline int fedisableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // all previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // mask
    fenv.__control |= new_excepts;
    fenv.__mxcsr   |= new_excepts << 7;

    return fesetenv(&fenv) ? -1 : old_excepts;
}

#else
inline int feenableexcept(unsigned int excepts)
{
#pragma STDC FENV_ACCESS ON
    fexcept_t flags;
    /* Save current exception flags. */
    fegetexceptflag(&flags, FE_ALL_EXCEPT);

    feclearexcept(FE_ALL_EXCEPT);   /* clear all fp exception conditions */
    return fesetexceptflag(&flags, excepts) != 0 ? -1 : flags; /* set new flags */

}

inline int fedisableexcept(unsigned int excepts)
{
#pragma STDC FENV_ACCESS ON
    fexcept_t flags;
    /* Save current exception flags. */
    fegetexceptflag(&flags, FE_ALL_EXCEPT);

    feclearexcept(FE_ALL_EXCEPT);   /* clear all fp exception conditions */
    return fesetexceptflag(&flags, ~excepts) != 0 ? -1 : flags; /* set new flags */
}

#endif
#endif

int main(int argc, char **argv) {
    feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
    TCanvas* C= new TCanvas("canvas","canvas",1024,768);
    C->cd();
    Double_t w=0, h=0, xl=0, yb=0;
    TH1D* o=new TH1D();
    TPad* c= new TPad();
    c->PlaceBox(o,w,h,xl,yb);
    delete c;
    delete C;
    return 0;
}

compile

g++ pad2.cxx $(root-config --glibs --cflags --libs) -o pad2  -g

run

./pad2

Setup

ROOT 6.22.02 CentOS7 gcc4.8.5
and
lxplus with

source /cvmfs/sft.cern.ch/lcg/views/dev3python3/latest/x86_64-centos7-gcc10-opt/setup.sh

Should also work with mac (not tested).

Additional context

Hopefully this will be the last one.

@andriish andriish added the bug label Sep 23, 2020
@andriish
Copy link
Contributor Author

Hi @couet ,

The previous fix for TPad works in tests.

Thanks!

Best regards,

Andrii

@couet couet self-assigned this Sep 24, 2020
@couet
Copy link
Member

couet commented Sep 24, 2020

Well .... "PlaceBox" is not supposed to be called by end users. Any way I will look.

@couet
Copy link
Member

couet commented Sep 24, 2020

And you call it with a TH1 as object ... it was never meant to be use that way. :-(

@andriish
Copy link
Contributor Author

. it was never meant to be use that way.

I know, I needed a dummy argument. The crash appears before any operations with this argument.

Best regards,
Andrii

@couet
Copy link
Member

couet commented Sep 24, 2020

I will try to protect

@couet
Copy link
Member

couet commented Sep 24, 2020

fixed by #6440

@andriish
Copy link
Contributor Author

Hi @couet ,

my fault! You've fixed a bug that I was not trying to report (zero pointer dereference).
Thanks a lot!
Will try to reproduce the FPE... If I will succeed (hopefully not), will open a new issue.

Best regards,

Andrii

@andriish
Copy link
Contributor Author

andriish commented Sep 24, 2020

I'm sorry,

here is the code to reproduce FPE (not segmentation violation)


#include <TCanvas.h>
#include <TPad.h>
#include <TBox.h>
#include <fenv.h>

#ifndef HAVE_FEENABLEEXCEPT
#if defined(__APPLE__) && defined(__MACH__)

// Public domain polyfill for feenableexcept on OS X
// http://www-personal.umich.edu/~williams/archive/computation/fe-handling-example.c

inline int feenableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // unmask
    fenv.__control &= ~new_excepts;
    fenv.__mxcsr   &= ~(new_excepts << 7);

    return fesetenv(&fenv) ? -1 : old_excepts;
}

inline int fedisableexcept(unsigned int excepts)
{
    static fenv_t fenv;
    unsigned int new_excepts = excepts & FE_ALL_EXCEPT;
    // all previous masks
    unsigned int old_excepts;

    if (fegetenv(&fenv)) {
        return -1;
    }
    old_excepts = fenv.__control & FE_ALL_EXCEPT;

    // mask
    fenv.__control |= new_excepts;
    fenv.__mxcsr   |= new_excepts << 7;

    return fesetenv(&fenv) ? -1 : old_excepts;
}

#else
inline int feenableexcept(unsigned int excepts)
{
#pragma STDC FENV_ACCESS ON
    fexcept_t flags;
    /* Save current exception flags. */
    fegetexceptflag(&flags, FE_ALL_EXCEPT);

    feclearexcept(FE_ALL_EXCEPT);   /* clear all fp exception conditions */
    return fesetexceptflag(&flags, excepts) != 0 ? -1 : flags; /* set new flags */

}

inline int fedisableexcept(unsigned int excepts)
{
#pragma STDC FENV_ACCESS ON
    fexcept_t flags;
    /* Save current exception flags. */
    fegetexceptflag(&flags, FE_ALL_EXCEPT);

    feclearexcept(FE_ALL_EXCEPT);   /* clear all fp exception conditions */
    return fesetexceptflag(&flags, ~excepts) != 0 ? -1 : flags; /* set new flags */
}

#endif
#endif

int main(int argc, char **argv) {
    feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
    TCanvas* C= new TCanvas("canvas","canvas",5,5);//fails
    // TCanvas* C= new TCanvas("canvas","canvas",50,50);//works
    C->cd();
    Double_t w=20, h=20, xl=0, yb=20;
    TBox* o=new TBox();
    TPad* c= new TPad();
    c->SetPad(0,0,1,1);
    c->cd(1);
    c->PlaceBox(o,w,h,xl,yb);
    return 0;
}

I see

[@test]$ ./pad5.exe 

 *** Break *** floating point exception



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
    gdb.printing.register_pretty_printer(gdb.current_objfile(),
#0  0x00007f16b818a46c in __libc_waitpid (pid=29363, stat_loc=stat_loc
entry=0x7ffeea3c7360, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:31
#1  0x00007f16b8107f62 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007f16bb30b5dc in TUnixSystem::StackTrace (this=0x19fb980) at /usr/src/debug/root-6.22.02/core/unix/src/TUnixSystem.cxx:2408
#3  0x00007f16bb30e06a in TUnixSystem::DispatchSignals (this=0x19fb980, sig=kSigFloatingException) at /usr/src/debug/root-6.22.02/core/unix/src/TUnixSystem.cxx:3646
#4  <signal handler called>
#5  0x00007f16ba505719 in TPad::PlaceBox (this=0x237b240, o=<optimized out>, w=20, h=20, xl=
0x7ffeea3c9dc0: 0, yb=
0x7ffeea3c9dc8: 20) at /usr/src/debug/root-6.22.02/graf2d/gpad/src/TPad.cxx:3108
#6  0x0000000000400c65 in main (argc=<optimized out>, argv=<optimized out>) at test/pad5.cxx:87
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5  0x00007f16ba505719 in TPad::PlaceBox (this=0x237b240, o=<optimized out>, w=20, h=20, xl=
0x7ffeea3c9dc0: 0, yb=
0x7ffeea3c9dc8: 20) at /usr/src/debug/root-6.22.02/graf2d/gpad/src/TPad.cxx:3108
#6  0x0000000000400c65 in main (argc=<optimized out>, argv=<optimized out>) at test/pad5.cxx:87
===========================================================



This result is seen on CentOS7/EPEL/root6220/gcc485 as well as on

lxplus with

source /cvmfs/sft.cern.ch/lcg/views/dev3python3/latest/x86_64-centos7-gcc10-opt/setup.sh

@andriish
Copy link
Contributor Author

Hi @couet,

should I open a new issue?

Best regards,

Andrii

@couet
Copy link
Member

couet commented Sep 25, 2020

Yes open a new one. This one is closed.

@andriish
Copy link
Contributor Author

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants