Issue 107516
Summary Clang runs OOM when checking for constant initialization of array of unions.
Labels clang
Assignees
Reporter john-carter
    Closely related to https://github.com/llvm/llvm-project/issues/51054 which has been fixed.

This case is very similar, but with union instead of struct.

echo '

   union elements {
      char charValue;
 void * pointer;
   };
elements foo[1<<30];
' | /usr/bin/time -v clang -c -x c++ -std=c++23 -

LLVM ERROR: out of memory
Allocation 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 -c -x c++ -std=c++23 -
1.	<stdin>:7:20: current parser token ';'
 #0 0x0000753c707a63bf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x0000753c707a44f9 llvm::sys::RunSignalHandlers() build-llvm/tools/clang/stage2-bins/llvm/lib/Support/Signals.cpp:106:18
 #2 0x0000753c706f0227 HandleCrash build-llvm/tools/clang/stage2-bins/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x0000753c706f0227 CrashRecoverySignalHandler build-llvm/tools/clang/stage2-bins/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #4 0x0000753c6f245320 (/lib/x86_64-linux-gnu/libc.so.6+0x45320)
 #5 0x0000753c6f29eb1c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x0000753c6f29eb1c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x0000753c6f29eb1c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x0000753c6f24526e raise ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x0000753c6f2288ff abort ./stdlib/abort.c:81:7
#10 0x0000753c706fe22d lock /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_mutex.h:117:2
#11 0x0000753c706fe22d lock_guard /usr/lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/bits/std_mutex.h:249:19
#12 0x0000753c706fe22d llvm::report_bad_alloc_error(char const*, bool) build-llvm/tools/clang/stage2-bins/llvm/lib/Support/ErrorHandling.cpp:153:33
#13 0x0000753c706fe289 (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xcfe289)
#14 0x0000753c6f6bb5f3 operator new(unsigned long) /build/gcc-14-OQFzmN/gcc-14-14-20240412/build/x86_64-linux-gnu/libstdc++-v3/libsupc++/../../../../src/libstdc++-v3/libsupc++/new_op.cc:55:15
#15 0x0000753c77e6b024 clang::APValue::Arr::Arr(unsigned int, unsigned int) build-llvm/tools/clang/stage2-bins/clang/lib/AST/APValue.cpp:295:8
#16 0x0000753c77e6bff6 clang::APValue::MakeArray(unsigned int, unsigned int) build-llvm/tools/clang/stage2-bins/clang/lib/AST/APValue.cpp:1084:8
#17 0x0000753c780d6732 VisitCXXConstructExpr build-llvm/tools/clang/stage2-bins/clang/lib/AST/ExprConstant.cpp:11195:30
#18 0x0000753c780a106b EvaluateArray build-llvm/tools/clang/stage2-bins/clang/lib/AST/ExprConstant.cpp:0:49
#19 0x0000753c780a106b EvaluateInPlace build-llvm/tools/clang/stage2-bins/clang/lib/AST/ExprConstant.cpp:15419:14
#20 0x0000753c780a1a92 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/AST/ExprConstant.cpp:0:12
#21 0x0000753c78014c15 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/AST/Decl.cpp:2578:32
#22 0x0000753c78014d78 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const build-llvm/tools/clang/stage2-bins/clang/lib/AST/Decl.cpp:2642:35
#23 0x0000753c7879600e clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) build-llvm/tools/clang/stage2-bins/clang/lib/Sema/SemaDecl.cpp:0:27
#24 0x0000753c7877b6b4 clang::Sema::ActOnUninitializedDecl(clang::Decl*) build-llvm/tools/clang/stage2-bins/clang/lib/Sema/SemaDecl.cpp:0:5
#25 0x0000753c77dae7ff clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseDecl.cpp:0:13
#26 0x0000753c77dac512 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseDecl.cpp:2337:21
#27 0x0000753c77e6307f clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/Parser.cpp:0:10
#28 0x0000753c77e62a39 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/Parser.cpp:1266:12
#29 0x0000753c77e61c65 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/Parser.cpp:0:14
#30 0x0000753c77e5ff7b clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/Parser.cpp:760:10
#31 0x0000753c77d9747e clang::ParseAST(clang::Sema&, bool, bool) build-llvm/tools/clang/stage2-bins/clang/lib/Parse/ParseAST.cpp:162:5
#32 0x0000753c79c0662c clang::FrontendAction::Execute() build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/FrontendAction.cpp:1073:10
#33 0x0000753c79b830b4 getPtr build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:279:12
#34 0x0000753c79b830b4 operator bool build-llvm/tools/clang/stage2-bins/llvm/include/llvm/Support/Error.h:239:16
#35 0x0000753c79b830b4 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) build-llvm/tools/clang/stage2-bins/clang/lib/Frontend/CompilerInstance.cpp:1057:23
#36 0x0000753c79c8263d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) build-llvm/tools/clang/stage2-bins/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:272:25
#37 0x0000560e5339942e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) build-llvm/tools/clang/stage2-bins/clang/tools/driver/cc1_main.cpp:294:15
#38 0x0000560e53396894 ExecuteCC1Tool build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:365:12
#39 0x0000753c79833972 operator() build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:30
#40 0x0000753c79833972 callback_fn<(lambda at clang/lib/Driver/Job.cpp:440:22)> build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/STLFunctionalExtras.h:45:12
#41 0x0000753c706eff77 operator() build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#42 0x0000753c706eff77 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) build-llvm/tools/clang/stage2-bins/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
#43 0x0000753c79833237 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Job.cpp:440:7
#44 0x0000753c797fb518 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:199:15
#45 0x0000753c797fb77f clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Compilation.cpp:253:13
#46 0x0000753c79817c20 empty build-llvm/tools/clang/stage2-bins/llvm/include/llvm/ADT/SmallVector.h:94:46
#47 0x0000753c79817c20 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) build-llvm/tools/clang/stage2-bins/clang/lib/Driver/Driver.cpp:1921:23
#48 0x0000560e533961ec clang_main(int, char**, llvm::ToolContext const&) build-llvm/tools/clang/stage2-bins/clang/tools/driver/driver.cpp:540:21
#49 0x0000560e533a3383 main build-llvm/tools/clang/stage2-bins/build-llvm/tools/clang/stage2-bins/tools/clang/tools/driver/clang-driver.cpp:17:10
#50 0x0000753c6f22a1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#51 0x0000753c6f22a28b call_init ./csu/../csu/libc-start.c:128:20
#52 0x0000753c6f22a28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#53 0x0000560e53393255 _start (/usr/lib/llvm-18/bin/clang+0xe255)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg: Error generating preprocessed source(s) - ignoring input from stdin.
clang: note: diagnostic msg: Error generating preprocessed source(s) - no preprocessable inputs.
Command exited with non-zero status 1
	Command being timed: "clang -c -x c++ -std=c++23 -"
	User time (seconds): 1.28
	System time (seconds): 0.15
	Percent of CPU this job got: 99%
	Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.44
	Average shared text size (kbytes): 0
	Average unshared data size (kbytes): 0
	Average stack size (kbytes): 0
	Average total size (kbytes): 0
	Maximum resident set size (kbytes): 622000
	Average resident set size (kbytes): 0
	Major (requiring I/O) page faults: 0
	Minor (reclaiming a frame) page faults: 120228
	Voluntary context switches: 4
	Involuntary context switches: 20
	Swaps: 0
	File system inputs: 0
	File system outputs: 24
	Socket messages sent: 0
	Socket messages received: 0
	Signals delivered: 0
	Page size (bytes): 4096
	Exit status: 1
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to