Skip to content
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 runs OOM when checking for constant initialization of array #51054

Closed
kadircet opened this issue Sep 2, 2021 · 7 comments
Closed

Clang runs OOM when checking for constant initialization of array #51054

kadircet opened this issue Sep 2, 2021 · 7 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@kadircet
Copy link
Member

kadircet commented Sep 2, 2021

Bugzilla Link 51712
Version trunk
OS All
CC @gislan,@zygoloid,@HighCommander4

Extended Description

cat > a.cc <<EOF
struct {
  int a, b, c, d;
} arr[50][6000000];
EOF
clang -fsyntax-only -xc++ a.cc

Results in clang consuming huge memory (tried with ~190GiB) and OOMing in the end. A sample backtrace looks like:

#&#8203;0  getDefaultInitValue () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:4733
#&#8203;1  0x0000000004e75412 in getDefaultInitValue () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:4726
#&#8203;2  0x0000000004ed80ae in VisitCXXConstructExpr () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:10484
#&#8203;3  0x0000000004ed8283 in VisitCXXConstructExpr () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:10471
#&#8203;4  0x0000000004ed8283 in VisitCXXConstructExpr () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:10471
#&#8203;5  0x0000000004e7259b in EvaluateArray () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:10298
#&#8203;6  EvaluateInPlace () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:14463
#&#8203;7  0x0000000004e74596 in EvaluateAsInitializer () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:14725
#&#8203;8  0x0000000004ddf0ef in evaluateValueImpl () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2389
#&#8203;9  0x0000000004ddf287 in checkForConstantInitialization () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2460
#&#8203;10 0x0000000004507705 in CheckCompleteVariableDeclaration () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:13007
#&#8203;11 0x00000000044ea30b in ActOnUninitializedDecl () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:12704
#&#8203;12 0x00000000042ec53d in ParseDeclarationAfterDeclaratorAndAttributes () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2387
#&#8203;13 0x00000000042eaa9d in ParseDeclGroup () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2038
#&#8203;14 0x00000000042caa9c in ParseDeclOrFunctionDefInternal () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1135
#&#8203;15 0x00000000042ca4e5 in ParseDeclarationOrFunctionDefinition () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1151
#&#8203;16 0x00000000042c91ee in ParseExternalDeclaration () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:971
#&#8203;17 0x00000000042c6e34 in ParseTopLevelDecl () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:716
#&#8203;18 0x00000000042c65b7 in ParseFirstTopLevelDecl () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:588
#&#8203;19 0x00000000042c1321 in ParseAST () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:157
#&#8203;20 0x000000000312399d in Execute () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:949
#&#8203;21 0x00000000030b35e2 in ExecuteAction () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:989
#&#8203;22 0x00000000031d6a62 in ExecuteCompilerInvocation () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:278
#&#8203;23 0x00000000009e8703 in cc1_main () at /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:240
#&#8203;24 0x00000000009e66fc in ExecuteCC1Tool () at /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:330
#&#8203;25 0x0000000002f5cb32 in operator() () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:404
#&#8203;26 callback_fn<(lambda at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:404:22)>(void) () at /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLExtras.h:185
#&#8203;27 0x0000000002870041 in operator() () at /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/ADT/STLExtras.h:209
#&#8203;28 RunSafely () at /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:424
#&#8203;29 0x0000000002f5c1f7 in Execute () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Job.cpp:404
#&#8203;30 0x0000000002f272c8 in ExecuteCommand () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:195
#&#8203;31 0x0000000002f27817 in ExecuteJobs () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Compilation.cpp:246
#&#8203;32 0x0000000002f41c88 in ExecuteCompilation () at /usr/local/google/home/kadircet/repos/llvm/clang/lib/Driver/Driver.cpp:1510
#&#8203;33 0x00000000009e5df4 in main () at /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:502

All of the backtrace samples I grabbed had checkForConstantInitialization as LCA.

@gislan
Copy link
Contributor

gislan commented Nov 10, 2021

Should be fixed with 48bb5f4

@kadircet
Copy link
Member Author

*** Bug llvm/llvm-bugzilla-archive#52530 has been marked as a duplicate of this bug. ***

@kadircet
Copy link
Member Author

reopening as the fix was reverted due to test failures on some platforms.

@kadircet
Copy link
Member Author

mentioned in issue llvm/llvm-bugzilla-archive#51843

@kadircet
Copy link
Member Author

mentioned in issue llvm/llvm-bugzilla-archive#52530

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 11, 2021
@sam-mccall
Copy link
Collaborator

IIUC this only got reverted due to some mechanical problems with the test. I've relanded it, running the test only on linux.

@john-carter
Copy link

This bug still exists with unions in clang-18.1.3

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

4 participants