| Issue |
183643
|
| Summary |
Assertion "FPConstrained should be enabled on entire function" failed if -ftrapping-math differs from PCH
|
| Labels |
crash-on-valid,
clang:PCH
|
| Assignees |
|
| Reporter |
hvdijk
|
This is reduced from an error I saw on Windows while building LLVM itself with Clang. The reduced test can also demonstrate the issue on other platforms when cross-compiling.
```console
$ cat cmake_pch.hxx
template <typename To, typename From>
To *cast_convert_val(From Val);
template <typename To, typename From>
To *doCast(From f) {
return cast_convert_val<To>(const_cast<const From &>(f));
}
template <typename To, typename From>
To *cast(From Val) {
return doCast<To, From>(Val);
}
class Value {
};
class Constant : public Value {
};
class ConstantExpr : public Constant {
};
$ cat cmake_pch.hxx.cxx
$ cat ConstantFolding.cpp
ConstantExpr *Foo(Constant *C) {
return cast<ConstantExpr>(C);
}
$ /home/harald/source/llvm-project/build/bin/clang++ --target=x86_64-pc-windows-msvc -Xclang -emit-pch -Xclang -include -Xclang cmake_pch.hxx -x c++-header -o cmake_pch.hxx.pch -c cmake_pch.hxx.cxx
$ /home/harald/source/llvm-project/build/bin/clang++ --target=x86_64-pc-windows-msvc -ftrapping-math -include-pch cmake_pch.hxx.pch -include cmake_pch.hxx -o ConstantFolding.cpp.obj -c ConstantFolding.cpp
clang++: /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:168: void clang::CodeGen::CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(clang::FPOptions): Assertion `(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"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /home/harald/source/llvm-project/build/bin/clang++ --target=x86_64-pc-windows-msvc -ftrapping-math -include-pch cmake_pch.hxx.pch -include cmake_pch.hxx -o ConstantFolding.cpp.obj -c ConstantFolding.cpp
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. /home/harald/bug/cmake_pch.hxx:4:7: Generating code for declaration 'doCast'
#0 0x00007f6a9306e988 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/harald/source/llvm-project/llvm/lib/Support/Unix/Signals.inc:884:3
#1 0x00007f6a9306bba4 llvm::sys::RunSignalHandlers() /home/harald/source/llvm-project/llvm/lib/Support/Signals.cpp:108:20
#2 0x00007f6a92f6f460 HandleCrash /home/harald/source/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
#3 0x00007f6a92f6f460 CrashRecoverySignalHandler(int) /home/harald/source/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:393:62
#4 0x00007f6a91c4aa70 (/usr/lib/x86_64-linux-gnu/libc.so.6+0x40a70)
#5 0x00007f6a91ca13bc (/usr/lib/x86_64-linux-gnu/libc.so.6+0x973bc)
#6 0x00007f6a91c4a942 raise (/usr/lib/x86_64-linux-gnu/libc.so.6+0x40942)
#7 0x00007f6a91c324ac abort (/usr/lib/x86_64-linux-gnu/libc.so.6+0x284ac)
#8 0x00007f6a91c32420 __assert_perror_fail (/usr/lib/x86_64-linux-gnu/libc.so.6+0x28420)
#9 0x00007f6a9e036b4b llvm::IRBuilderBase::setDefaultConstrainedExcept(llvm::fp::ExceptionBehavior) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:168:3
#10 0x00007f6a9e036b4b clang::CodeGen::CodeGenFunction::CGFPOptionsRAII::ConstructorHelper(clang::FPOptions) (.cold) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:164:42
#11 0x00007f6a9fb76d32 clang::CastExpr::getCastKind() const /home/harald/source/llvm-project/clang/include/clang/AST/Expr.h:3723:65
#12 0x00007f6a9fb76d32 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2589:34
#13 0x00007f6a9fb74bf7 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:491:3
#14 0x00007f6a9fb76e57 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:2893:17
#15 0x00007f6a9fb74c7f Visit /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:491:3
#16 0x00007f6a9fb74c7f clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:6099:13
#17 0x00007f6a9fae93ef clang::CodeGen::RValue::get(llvm::Value*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGValue.h:103:19
#18 0x00007f6a9fae93ef clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExpr.cpp:278:23
#19 0x00007f6a9fae9847 clang::CodeGen::CodeGenFunction::EmitAnyExprToTemp(clang::Expr const*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExpr.cpp:298:1
#20 0x00007f6a9fa36603 clang::CodeGen::CodeGenFunction::EmitCallArg(clang::CodeGen::CallArgList&, clang::Expr const*, clang::QualType) /home/harald/source/llvm-project/clang/lib/CodeGen/CGCall.cpp:5074:11
#21 0x00007f6a9fa37b30 clang::CodeGen::CodeGenFunction::EmitCallArgs(clang::CodeGen::CallArgList&, clang::CodeGen::CodeGenFunction::PrototypeWrapper, llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, clang::Expr const* const, clang::Stmt const* const>>, clang::CodeGen::CodeGenFunction::AbstractCallee, unsigned int, clang::CodeGen::CodeGenFunction::EvaluationOrder) /home/harald/source/llvm-project/clang/lib/CodeGen/CGCall.cpp:4917:5
#22 0x00007f6a9fb1b2bd std::__uniq_ptr_impl<clang::CodeGen::CodeGenTypes, std::default_delete<clang::CodeGen::CodeGenTypes>>::_M_ptr() const /usr/include/c++/15/bits/unique_ptr.h:192:67
#23 0x00007f6a9fb1b2bd std::unique_ptr<clang::CodeGen::CodeGenTypes, std::default_delete<clang::CodeGen::CodeGenTypes>>::get() const /usr/include/c++/15/bits/unique_ptr.h:472:27
#24 0x00007f6a9fb1b2bd std::unique_ptr<clang::CodeGen::CodeGenTypes, std::default_delete<clang::CodeGen::CodeGenTypes>>::operator*() const /usr/include/c++/15/bits/unique_ptr.h:455:2
#25 0x00007f6a9fb1b2bd clang::CodeGen::CodeGenModule::getTypes() /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.h:878:38
#26 0x00007f6a9fb1b2bd clang::CodeGen::CodeGenFunction::EmitCall(clang::QualType, clang::CodeGen::CGCallee const&, clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::Value*, llvm::CallBase**, clang::CodeGen::CGFunctionInfo const**) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExpr.cpp:7011:46
#27 0x00007f6a9fb1c87d clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExpr.cpp:6413:50
#28 0x00007f6a9fb7ab20 clang::CodeGen::RValue::getScalarVal() const /home/harald/source/llvm-project/clang/lib/CodeGen/CGValue.h:73:5
#29 0x00007f6a9fb7ab20 VisitCallExpr /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:679:48
#30 0x00007f6a9fb7ab20 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:675:10
#31 0x00007f6a9fb74c7f Visit /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:491:3
#32 0x00007f6a9fb74c7f clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) /home/harald/source/llvm-project/clang/lib/CodeGen/CGExprScalar.cpp:6099:13
#33 0x00007f6a9fce5df3 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) /home/harald/source/llvm-project/clang/lib/CodeGen/CGStmt.cpp:1658:40
#34 0x00007f6a9fcf6963 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) /home/harald/source/llvm-project/clang/lib/CodeGen/CGStmt.cpp:587:10
#35 0x00007f6a9fd64057 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1376:1
#36 0x00007f6a9fd78ab4 clang::CodeGen::CodeGenModule::getLangOpts() const /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.h:851:51
#37 0x00007f6a9fd78ab4 clang::CodeGen::CodeGenFunction::getLangOpts() const /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.h:2192:66
#38 0x00007f6a9fd78ab4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:1632:18
#39 0x00007f6a9fdcb66e clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:6707:3
#40 0x00007f6a9fdc64c5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4727:47
#41 0x00007f6a9fdd136a clang::CodeGen::CodeGenModule::EmitDeferred() /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3770:34
#42 0x00007f6a9fdd1386 clang::CodeGen::CodeGenModule::EmitDeferred() /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:3772:7
#43 0x00007f6a9fdd350b clang::CodeGen::CodeGenModule::Release() /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:977:29
#44 0x00007f6a9fe50e9c (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) /home/harald/source/llvm-project/clang/lib/CodeGen/ModuleBuilder.cpp:297:11
#45 0x00007f6a9fd5e353 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/harald/source/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:238:31
#46 0x00007f6a9e3b6744 clang::ParseAST(clang::Sema&, bool, bool) /home/harald/source/llvm-project/clang/lib/Parse/ParseAST.cpp:183:34
#47 0x00007f6aa068dee1 clang::FrontendAction::Execute() /home/harald/source/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1326:38
#48 0x00007f6aa0618192 llvm::Error::getPtr() const /home/harald/source/llvm-project/llvm/include/llvm/Support/Error.h:278:51
#49 0x00007f6aa0618192 llvm::Error::operator bool() /home/harald/source/llvm-project/llvm/include/llvm/Support/Error.h:241:22
#50 0x00007f6aa0618192 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/harald/source/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1007:42
#51 0x00007f6aa072765a std::__shared_ptr<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2>::get() const /usr/include/c++/15/bits/shared_ptr_base.h:1673:16
#52 0x00007f6aa072765a std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::_M_get() const /usr/include/c++/15/bits/shared_ptr_base.h:1370:69
#53 0x00007f6aa072765a std::__shared_ptr_access<clang::FrontendOptions, (__gnu_cxx::_Lock_policy)2, false, false>::operator*() const /usr/include/c++/15/bits/shared_ptr_base.h:1358:40
#54 0x00007f6aa072765a clang::CompilerInvocation::getFrontendOpts() /home/harald/source/llvm-project/clang/include/clang/Frontend/CompilerInvocation.h:277:48
#55 0x00007f6aa072765a clang::CompilerInstance::getFrontendOpts() /home/harald/source/llvm-project/clang/include/clang/Frontend/CompilerInstance.h:301:39
#56 0x00007f6aa072765a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/harald/source/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:311:29
#57 0x000055f14e2a57f7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/harald/source/llvm-project/clang/tools/driver/cc1_main.cpp:304:40
#58 0x000055f14e29ddc8 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) /home/harald/source/llvm-project/clang/tools/driver/driver.cpp:229:20
#59 0x000055f14e29e07a std::__atomic_base<int>::fetch_sub(int, std::memory_order) /usr/include/c++/15/bits/atomic_base.h:641:34
#60 0x000055f14e29e07a llvm::ThreadSafeRefCountedBase<llvm::vfs::FileSystem>::Release() const /home/harald/source/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:134:41
#61 0x000055f14e29e07a llvm::IntrusiveRefCntPtrInfo<llvm::vfs::FileSystem>::release(llvm::vfs::FileSystem*) /home/harald/source/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:164:45
#62 0x000055f14e29e07a llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>::release() /home/harald/source/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:233:41
#63 0x000055f14e29e07a llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>::~IntrusiveRefCntPtr() /home/harald/source/llvm-project/llvm/include/llvm/ADT/IntrusiveRefCntPtr.h:196:34
#64 0x000055f14e29e07a operator() /home/harald/source/llvm-project/clang/tools/driver/driver.cpp:379:26
#65 0x000055f14e29e07a int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) /home/harald/source/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:52
#66 0x00007f6aa023fa89 operator() /home/harald/source/llvm-project/clang/lib/Driver/Job.cpp:442:32
#67 0x00007f6aa023fa89 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) /home/harald/source/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:52
#68 0x00007f6a92f6f5c1 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /home/harald/source/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:438:10
#69 0x00007f6aa0240354 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) /home/harald/source/llvm-project/clang/lib/Driver/Job.cpp:446:10
#70 0x00007f6aa01f9819 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /home/harald/source/llvm-project/clang/lib/Driver/Compilation.cpp:196:22
#71 0x00007f6aa01f9e67 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /home/harald/source/llvm-project/clang/lib/Driver/Compilation.cpp:246:5
#72 0x00007f6aa020ec85 llvm::SmallVectorBase<unsigned int>::empty() const /home/harald/source/llvm-project/llvm/include/llvm/ADT/SmallVector.h:83:46
#73 0x00007f6aa020ec85 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /home/harald/source/llvm-project/clang/lib/Driver/Driver.cpp:2330:28
#74 0x000055f14e2a1437 llvm::SmallVectorBase<unsigned int>::size() const /home/harald/source/llvm-project/llvm/include/llvm/ADT/SmallVector.h:80:32
#75 0x000055f14e2a1437 llvm::SmallVectorTemplateCommon<std::pair<int, clang::driver::Command const*><truncated>Please see the issue for the entire body.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs