-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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"), function ConstructorHelper, file /usr/src/contrib/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp, line 165. #63542
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
Comments
I confirmed this behavior with the system compiler on FreeBSD 14.0-CURRENT on amd64 and aarch64 as well. The ports build of llvm16 does not crash, despite being based on a very similar version of llvm. |
LLVM in ports has assertions disabled, which is probably the reason. |
I think you are right about that. I also reproduced the crash on amd64 Linux using a build with assertions enabled. |
The reproducer provided here is not related to 65cf77d, because it causes compiler crash with that commit reverted. The problem reported here is fixed by the patch https://reviews.llvm.org/D154359. |
This is recommit of 98390cc, reverted in 82a3969, because it caused #63542. Although the problem described in the issue is independent of the reverted patch, fail of PCH/late-parsed-instantiations.cpp indeed obseved on PowerPC and is likely to be caused by wrong serialization of `LateParsedTemplate` objects. In this patch the serialization is fixed. Original commit message is below. Previously function template instantiations occurred with FP options that were in effect at the end of translation unit. It was a problem for late template parsing as these FP options were used as attributes of AST nodes and may result in crash. To fix it FP options are set to the state of the point of template definition. Differential Revision: https://reviews.llvm.org/D143241
@llvm/issue-subscribers-clang-frontend |
Would it be possible to merge it to 16? |
@DimitryAndric |
[clang] Reset FP options before template instantiation AST nodes that may depend on FP options keep them as a difference relative to the options outside the AST node. At the moment of instantiation the FP options may be different from the default values, defined by command-line option. In such case FP attributes would have unexpected values. For example, the code: template <class C> void func_01(int last, C) { func_01(last, int()); } void func_02() { func_01(0, 1); } #pragma STDC FENV_ACCESS ON caused compiler crash, because template instantiation takes place at the end of translation unit, where pragma STDC FENV_ACCESS is in effect. As a result, code in the template instantiation would use constrained intrinsics while the function does not have StrictFP attribute. To solve this problem, FP attributes in Sema must be set to default values, defined by command line options. This change resolves llvm/llvm-project#63542. Differential Revision: https://reviews.llvm.org/D154359 Requested by: pkubaj PR: 265755, 265758 MFC after: 1 month
I think clang 17 is going to be branched soon, so 16 is a bit "old" already... In any case I have merged it into FreeBSD in freebsd/freebsd-src@1cd9788. |
The upstream commit fde5924dcc69 has been merged to llvm in the FreeBSD main branch so merge it here as well. Issue: llvm/llvm-project#63542
The upstream commit fde5924dcc69 has been merged to llvm in the FreeBSD main branch so merge it here as well. Issue: llvm/llvm-project#63542 (cherry picked from commit 2a9d785)
[clang] Reset FP options before template instantiation AST nodes that may depend on FP options keep them as a difference relative to the options outside the AST node. At the moment of instantiation the FP options may be different from the default values, defined by command-line option. In such case FP attributes would have unexpected values. For example, the code: template <class C> void func_01(int last, C) { func_01(last, int()); } void func_02() { func_01(0, 1); } #pragma STDC FENV_ACCESS ON caused compiler crash, because template instantiation takes place at the end of translation unit, where pragma STDC FENV_ACCESS is in effect. As a result, code in the template instantiation would use constrained intrinsics while the function does not have StrictFP attribute. To solve this problem, FP attributes in Sema must be set to default values, defined by command line options. This change resolves llvm/llvm-project#63542. Differential Revision: https://reviews.llvm.org/D154359 Requested by: pkubaj PR: 265755, 265758 MFC after: 1 month (cherry picked from commit 1cd9788)
The bad codegen reported in #63063 (comment) still occurs with this fix. |
@spavloff, I have opened a regression defect against the fix: #64605 |
@llvm/issue-subscribers-clang-codegen |
I opened #64823 for a different case that hits the same assertion. |
[clang] Reset FP options before template instantiation AST nodes that may depend on FP options keep them as a difference relative to the options outside the AST node. At the moment of instantiation the FP options may be different from the default values, defined by command-line option. In such case FP attributes would have unexpected values. For example, the code: template <class C> void func_01(int last, C) { func_01(last, int()); } void func_02() { func_01(0, 1); } #pragma STDC FENV_ACCESS ON caused compiler crash, because template instantiation takes place at the end of translation unit, where pragma STDC FENV_ACCESS is in effect. As a result, code in the template instantiation would use constrained intrinsics while the function does not have StrictFP attribute. To solve this problem, FP attributes in Sema must be set to default values, defined by command line options. This change resolves llvm/llvm-project#63542. Differential Revision: https://reviews.llvm.org/D154359 Requested by: pkubaj PR: 265755, 265758 MFC after: 1 month
This is recommit of 98390cc, reverted in 82a3969, because it caused llvm/llvm-project#63542. Although the problem described in the issue is independent of the reverted patch, fail of PCH/late-parsed-instantiations.cpp indeed obseved on PowerPC and is likely to be caused by wrong serialization of `LateParsedTemplate` objects. In this patch the serialization is fixed. Original commit message is below. Previously function template instantiations occurred with FP options that were in effect at the end of translation unit. It was a problem for late template parsing as these FP options were used as attributes of AST nodes and may result in crash. To fix it FP options are set to the state of the point of template definition. Differential Revision: https://reviews.llvm.org/D143241
AST nodes that may depend on FP options keep them as a difference relative to the options outside the AST node. At the moment of instantiation the FP options may be different from the default values, defined by command-line option. In such case FP attributes would have unexpected values. For example, the code: template <class C> void func_01(int last, C) { func_01(last, int()); } void func_02() { func_01(0, 1); } #pragma STDC FENV_ACCESS ON caused compiler crash, because template instantiation takes place at the end of translation unit, where pragma STDC FENV_ACCESS is in effect. As a result, code in the template instantiation would use constrained intrinsics while the function does not have StrictFP attribute. To solve this problem, FP attributes in Sema must be set to default values, defined by command line options. This change resolves llvm/llvm-project#63542. Differential Revision: https://reviews.llvm.org/D154359
FreeBSD 14.0-CURRENT
LLVM 16.0.6
powerpc64le, powerpc64, powerpc
Reproducer:
Build with:
Output:
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"), function ConstructorHelper, file /usr/src/contrib/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp, line 165.
The text was updated successfully, but these errors were encountered: