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

Test matrix_free/fe_q_iso_q1_01 segfaults with clang-16 when linked against libc++ in debug mode #15496

Closed
tamiko opened this issue Jun 26, 2023 · 4 comments · Fixed by #15509
Labels

Comments

@tamiko
Copy link
Member

tamiko commented Jun 26, 2023

I have no idea what to make out of this segfault with clang-16 in debug mode:

#0  0x00007ffff5375faf in dealii::Polynomials::PiecewisePolynomial<double>::value (this=0x5555557d96d0, x=0.10566243270259355, n_derivatives=4, values=0x555555887730)
    at /srv/testsuite/dealii/source/base/polynomials_piecewise.cc:143
#1  0x00007fffefbcd32e in dealii::TensorProductPolynomials<2, dealii::Polynomials::PiecewisePolynomial<double> >::compute_derivative<1> (this=0x555555880a70, i=<optimized out>, p=...)
    at /srv/testsuite/dealii/include/deal.II/base/tensor_product_polynomials.h:558
#2  0x00007ffff3db48a4 in dealii::internal::MatrixFreeFunctions::ShapeInfo<dealii::VectorizedArray<double, 2ul> >::reinit<2, 2, 2> (this=0x55555587fac0, quad_in=..., fe_in=..., 
    base_element_number=<optimized out>) at /srv/testsuite/dealii/include/deal.II/matrix_free/shape_info.templates.h:701
#3  0x00007ffff3be68b5 in dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::internal_reinit<double, 2> (this=0x7fffffffc870, mapping=..., dof_handler=..., 
    constraints=..., locally_owned_dofs=..., quad=..., additional_data=...) at /srv/testsuite/dealii/include/deal.II/matrix_free/matrix_free.templates.h:426
#4  0x000055555557e290 in dealii::MatrixFree<2, double, dealii::VectorizedArray<double, 2ul> >::reinit<dealii::QIterated<1>, double, dealii::MappingQ1<2, 2> > (
    this=this@entry=0x7fffffffc870, mapping=..., dof_handler=..., constraints_in=..., quad=..., additional_data=...) at /srv/testsuite/dealii/include/deal.II/matrix_free/matrix_free.h:3167
#5  0x000055555557b115 in test<2> (n_subdivisions=n_subdivisions@entry=2) at /srv/testsuite/dealii/tests/matrix_free/fe_q_iso_q1_01.cc:53
#6  0x000055555557a3f7 in main (argc=1, argv=0x7fffffffdc18) at /srv/testsuite/dealii/tests/matrix_free/fe_q_iso_q1_01.cc:91

The test passes for all other compilers and test configurations. Also, the corresponding release-variant passes on all configurations.

In reference to #15383

@tamiko tamiko added the Bug label Jun 26, 2023
@tamiko tamiko added this to the Release 9.5 milestone Jun 26, 2023
@bangerth
Copy link
Member

For reference, the code is here (line 143):
https://github.com/dealii/dealii/blob/master/source/base/polynomials_piecewise.cc#L143
It's hard to believe what can go wrong in this place. x is a local function argument (passed by-value), offset a local variable, as is step. There aren't any pointer operations in this line.

I think you'll have to run this in a debugger and poke around the various variables to see what's happening here.

@kronbichler
Copy link
Member

kronbichler commented Jun 27, 2023

I investigated the problem and realized the following:

  • The problem fails in the assembly instruction cmpnltpd %xmm3,%xmm2, which corresponds to the comparison x < offset, where x=0.10566243270259355 and offset = 0.0, with %xmm2 mapped to x and %xmm3 mapped to offset.
  • When the violation occurs, I see the register content %xmm2 = v2_double = {0.10566243270259355, 0} and %xmm3 = v2_double = {0, -nan(0xfffffffffffff)}. This means that xmm3 contains a 0 in the lower part of the vector, which is correct, but a nan in the upper part of the 128-bit vector. It is the upper part that creates a floating point exception.
  • I then went through the uses of the %xmm3 register in this function, and apparently it is only used in the instructions cvtsi2sd and mulsd before. These are lower-lane functions, so they do not touch the upper lane. In consequence, the origin must be somewhere else in the call stack.

I tend to believe that this must be a compiler bug, because the compiler cannot make assumptions on the prior content of %xmm3 upon entry of the function in terms of the content in the upper lane. In other words, the compiler should have chosen a cmpnltsd instruction instead of cmpnltpd. I do not see it for clang versions prior to 16.0 and I only see it with -Og and -O1 compile flags. I think it is time to file a bug report to clang/llvm. I try to extract a minimal test case.

@kronbichler
Copy link
Member

Note that the result of the upper lane, which contains nan, will not be used later in the code, and is in fact an artificial leftover from some library call somewhere else. The investigation makes me sure this is not our bug.

@tamiko
Copy link
Member Author

tamiko commented Jun 27, 2023

@kronbichler I will add the flag to the debug variant when compiling with clang.

tamiko added a commit to tamiko/dealii that referenced this issue Jun 27, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-mfp-exceptions`, at least for the level of optimization we have in
debug mode. clang however is more aggressive and assumes that it can
optimize code disregarding precise floating-point exception semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
tamiko added a commit to tamiko/dealii that referenced this issue Jun 27, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-mfp-exceptions`, at least for the level of optimization we have in
debug mode. clang however is more aggressive and assumes that it can
optimize code disregarding precise floating-point exception semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
tamiko added a commit to tamiko/dealii that referenced this issue Jun 27, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-ftrapping-math` per default, at least for the level of optimization we
have in debug mode. clang however is more aggressive and assumes that it
can optimize code disregarding precise floating-point exception
semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
tamiko added a commit to tamiko/dealii that referenced this issue Jun 27, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-ftrapping-math` per default, at least for the level of optimization we
have in debug mode. clang however is more aggressive and assumes that it
can optimize code disregarding precise floating-point exception
semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
@tamiko tamiko removed this from the Release 9.5 milestone Jun 27, 2023
quangx pushed a commit to quangx/dealii that referenced this issue Oct 15, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-ftrapping-math` per default, at least for the level of optimization we
have in debug mode. clang however is more aggressive and assumes that it
can optimize code disregarding precise floating-point exception
semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
quangx pushed a commit to quangx/dealii that referenced this issue Oct 15, 2023
We have to ensure that we emit floating-point instructions in debug mode
that preserve the occurence of floating-point exceptions and don't
introduce new ones. gcc plays nicely in this regard by enabling
`-ftrapping-math` per default, at least for the level of optimization we
have in debug mode. clang however is more aggressive and assumes that it
can optimize code disregarding precise floating-point exception
semantics.

We thus set `-ffp-exceptions-behavior=strict` in debug mode to ensure
that our testsuite doesn't run into false positive floating-point
exceptions. See dealii#15496
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.

3 participants