-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[clang code-gen] #pragma FENV_ACCESS leaking across template declarations/definitions #63063
Comments
@llvm/issue-subscribers-clang-codegen |
@llvm/issue-subscribers-bug |
It isn't just the warning. As https://godbolt.org/z/xoTa7zWeM shows, the possibility that the rounding mode causes the comparison to succeed is not reflected in the generated code. |
I think it is more accurate to say that the value of the pragma at instantiation is used for some purposes but not others. For example, with #include <float.h>
#pragma STDC FENV_ACCESS ON
template <class> float b(float x) { return (float)(x*FLT_MAX)/FLT_MAX; }
#pragma STDC FENV_ACCESS OFF
void d(float x) { b<char>(x); } we see the |
CC @zahiraam and @rjmccall because this is currently being worked on in https://reviews.llvm.org/D152818 The currently final comment on that is:
but it sounds like there may be more complexity based on what @hubert-reinterpretcast found. |
There's more complexity, but it's consistent with my diagnosis; it just means that some of our representations preserve information separately from the original context while others rely on the pragmas being set. |
#64605 (comment) describes the possible mechanism of the leaking. |
Resolved by fde5924. |
We have encountered an assertion being hit in codegen relating to
FENV_ACCESS
:Assertion failed: (CGF.CurFuncDecl == nullptr || CGF.Builder.getIsFPConstrained() || isa<CXXConstructorDecl>(CGF.CurFuncDecl) || isa<CXXDestructorDecl>(CGF.CurFuncDecl) || (NewExceptionBehavior == llvm::fp::ebIgnore && NewRoundingBehavior == llvm::RoundingMode::NearestTiesToEven)) && "FPConstrained should be enabled on entire function", file clang/lib/CodeGen/CodeGenFunction.cpp, line 163, void clang::CodeGen::CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(clang::FPOptions)()
This is reproducible with:
Basically, as it stands, it looks like when a template is declared under the scope of this pragma being set to one value, and then instantiated under the scope of this pragma being set to another, the value of the pragma at instantiation is taking precedence, which can cause this assertion as well as undefined behaviour when you flip the values. For example,
exposes the same issue without the assertion being tripped. With
Wuninitialized
on, this shows as "uninitialized". As the definition is under the scope of this pragma being turned on,FENV_ACCESS
should have the rounding mode set to dynamic, which would lead this expected warning to be "sometimes uninitialized". This proves that the pragma being set above the instantiation is taking precedence rather than the pragma above the definition being preserved.FYI @hubert-reinterpretcast
The text was updated successfully, but these errors were encountered: