[clang] [Sema] Add check for bitfield assignments to integral types (PR #69049)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 23 09:09:36 PDT 2023
kadircet wrote:
hi folks!
this seems to be triggering crashes on some valid code, e.g:
a.cc:
```
template <class a, class... b>
bool c = __is_constructible(a, b...);
struct d {
int q : 1;
};
struct i {
virtual void g() { (void)c<d, int>; }
};
i n;
```
```
clang -xc++ -std=c++20 -fsyntax-only a.cc
clang: /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:662: decltype(auto) llvm::dyn_cast(From *) [To = clang::ParenExpr, From = clang::Expr]: Assertion `detail::isPresent(Val) && "dyn_cast on a non-existent value"' 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: ./clang -xc++ a.cc -fsyntax-only -std=c++20
1. <eof> parser at end of file
2. a.cc:3:6: instantiating variable definition 'c<d, int>'
3. a.cc:3:6: instantiating variable definition 'c<d, int>'
#0 0x0000560886f8bd57 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13
#1 0x0000560886f8993e llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18
#2 0x0000560886ef3698 HandleCrash /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
#3 0x0000560886ef3698 CrashRecoverySignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
#4 0x00007f1b0b05a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
#5 0x00007f1b0b0a80fc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
#6 0x00007f1b0b05a472 raise ./signal/../sysdeps/posix/raise.c:27:6
#7 0x00007f1b0b0444b2 abort ./stdlib/./stdlib/abort.c:81:7
#8 0x00007f1b0b0443d5 _nl_load_domain ./intl/./intl/loadmsgcat.c:1177:9
#9 0x00007f1b0b0533a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
#10 0x0000560889b511f5 clang::IgnoreParensSingleStep(clang::Expr*) /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/IgnoreExpr.h:0:0
#11 0x000056088a369e5b IgnoreExprNodes<clang::Expr *(&)(clang::Expr *)> /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/IgnoreExpr.h:36:12
#12 0x000056088a369e5b clang::Expr::IgnoreParens() /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Expr.cpp:3012:10
#13 0x00005608895e4285 IgnoreParens /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/Expr.h:892:38
#14 0x00005608895e4285 GetExprRange(clang::ASTContext&, clang::Expr const*, unsigned int, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaChecking.cpp:13498:10
#15 0x00005608895e4341 GetExprRange(clang::ASTContext&, clang::Expr const*, unsigned int, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaChecking.cpp:0:0
#16 0x00005608895e4341 GetExprRange(clang::ASTContext&, clang::Expr const*, unsigned int, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaChecking.cpp:0:0
#17 0x00005608895d5970 AnalyzeBitFieldAssignment(clang::Sema&, clang::FieldDecl*, clang::Expr*, clang::SourceLocation) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaChecking.cpp:14337:11
#18 0x0000560889b37c84 getKind /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Sema/Initialization.h:441:39
#19 0x0000560889b37c84 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaInit.cpp:9424:34
#20 0x0000560889b4ee9b TryOrBuildParenListInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::ArrayRef<clang::Expr*>, clang::InitializationSequence&, bool, clang::ActionResult<clang::Expr*, true>*)::$_12::operator()(clang::InitializedEntity const&, clang::InitializationKind const&, clang::Expr*, clang::Expr**) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaInit.cpp:0:0
#21 0x0000560889b3078b TryOrBuildParenListInitialization(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::ArrayRef<clang::Expr*>, clang::InitializationSequence&, bool, clang::ActionResult<clang::Expr*, true>*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaInit.cpp:0:14
#22 0x0000560889b35de0 clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, clang::QualType*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaInit.cpp:9395:7
#23 0x0000560889a6787c EvaluateBooleanTypeTrait /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaExprCXX.cpp:5505:30
#24 0x0000560889a6787c clang::Sema::BuildTypeTrait(clang::TypeTrait, clang::SourceLocation, llvm::ArrayRef<clang::TypeSourceInfo*>, clang::SourceLocation) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaExprCXX.cpp:5634:19
#25 0x0000560889eac70e RebuildTypeTrait /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/TreeTransform.h:3393:22
#26 0x0000560889eac70e clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformTypeTraitExpr(clang::TypeTraitExpr*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/TreeTransform.h:12923:23
#27 0x0000560889e96bee clang::Sema::SubstInitializer(clang::Expr*, clang::MultiLevelTemplateArgumentList const&, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateInstantiate.cpp:4085:23
#28 0x0000560889eef9e7 clang::Sema::InstantiateVariableInitializer(clang::VarDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5417:14
#29 0x0000560889ef5079 getLangOpts /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/Sema/Sema.h:1676:51
#30 0x0000560889ef5079 clang::Sema::CompleteVarTemplateSpecializationDecl(clang::VarTemplateSpecializationDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:5254:7
#31 0x0000560889ef5703 clang::Sema::InstantiateVariableDefinition(clang::SourceLocation, clang::VarDecl*, bool, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:0:11
#32 0x0000560889ef65f9 clang::Sema::PerformPendingInstantiations(bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp:6466:3
#33 0x000056088950e895 ~TimeTraceScope /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/TimeProfiler.h:155:9
#34 0x000056088950e895 clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/Sema.cpp:1082:3
#35 0x000056088950f03c clang::Sema::ActOnEndOfTranslationUnit() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/Sema.cpp:1123:9
#36 0x00005608893d236c clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:13
#37 0x00005608893cce2e clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:162:5
#38 0x0000560887b57360 clang::FrontendAction::Execute() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:1074:10
#39 0x0000560887ac4d8f getPtr /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:276:42
#40 0x0000560887ac4d8f operator bool /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:239:16
#41 0x0000560887ac4d8f clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:1045:23
#42 0x0000560887c3f8d7 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#43 0x00005608849d9d99 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:294:15
#44 0x00005608849d60b1 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:0:12
#45 0x0000560887922da9 operator() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:440:30
#46 0x0000560887922da9 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::$_1>(long) /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#47 0x0000560886ef33db operator() /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#48 0x0000560886ef33db llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
#49 0x0000560887922490 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:440:7
#50 0x00005608878df438 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:199:15
#51 0x00005608878df6f7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:253:13
#52 0x00005608878ffd87 empty /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/SmallVector.h:94:46
#53 0x00005608878ffd87 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Driver.cpp:1884:23
#54 0x00005608849d534e clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:542:21
#55 0x00005608849e6b41 main /usr/local/google/home/kadircet/repos/llvm/build/tools/clang/tools/driver/clang-driver.cpp:15:3
#56 0x00007f1b0b0456ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#57 0x00007f1b0b045785 call_init ./csu/../csu/libc-start.c:128:20
#58 0x00007f1b0b045785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#59 0x00005608849d24a1 _start (./clang+0x58ca4a1)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 18.0.0 (git at github.com:llvm/llvm-project.git 01263c6c6fb495a94fe0ccbb1420bb1ec8460748)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/google/home/kadircet/repos/tmp/clang_crash/.
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/a-7923c9.cpp
clang: note: diagnostic msg: /tmp/a-7923c9.sh
clang: note: diagnostic msg:
********************
```
https://github.com/llvm/llvm-project/pull/69049
More information about the cfe-commits
mailing list