llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.13k stars 12.01k forks source link

AddressSanitizer::instrumentFunction runs out of memory (LLVM error: Out of memory) #55063

Open vikrant0786 opened 2 years ago

vikrant0786 commented 2 years ago

LEETCODE problem 1423. Maximum Points You Can Obtain from Cards

CODE:

class Solution {
public:
    int dp[100005][100005];
    int  fun(vector<int>&a,int k,int i, int j){
        if(k==0||i>j){
            return 0;
        }
        if(dp[i][j]!=-1)
            return dp[i][j];
        int ch1=a[i]+fun(a,k-1,i+1,j);
        int ch2=a[j]+fun(a,k-1,i,j-1);
        return dp[i][j]=max(ch1,ch2);
    }
    int maxScore(vector<int>& a, int k) {
        memset(dp,-1,sizeof(dp));
        int i=0,j=a.size()-1;
        return fun(a,k,i,j);
    }
};

error message:

LLVM ERROR: out of memory
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.  Program arguments: /install/bin/clang-11.bolt -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name prog_joined.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /install/lib/clang/11.0.0 -include-pch precompiled/headers.pch -D asm=error -D JSMN_PARENT_LINKS -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward -internal-isystem /usr/local/include -internal-isystem /install/lib/clang/11.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-deprecated -Werror=return-type -Wno-write-strings -std=c++17 -fno-gnu-keywords -fdebug-compilation-dir /leetcode/user_code/runcode_1650805445.0268347_wFziB3s2A4_interpret_task -ftemplate-depth 128 -ferror-limit 1 -fsanitize=address,alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,object-size,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound,vptr -fsanitize-system-blacklist=/install/lib/clang/11.0.0/share/asan_blacklist.txt -fsanitize-address-use-after-scope -fno-assume-sane-operator-new -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -fno-validate-pch -faddrsig -o /tmp/prog_joined-365c37.o -x c++ prog_joined.cpp
1.  <eof> parser at end of file
2.  Per-module optimization passes
3.  Running pass 'Function Pass Manager' on module 'prog_joined.cpp'.
4.  Running pass 'AddressSanitizerFunctionPass' on function '@main'
 #0 0x0000000007180b59 PrintStackTraceSignalHandler(void*) (/install/bin/clang-11.bolt+0x7180b59)
 #1 0x0000000007180178 llvm::sys::RunSignalHandlers() (/install/bin/clang-11.bolt+0x7180178)
 #2 0x000000000718054b SignalHandler(int) (/install/bin/clang-11.bolt+0x718054b)
 #3 0x00007f6253ffe3c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
 #4 0x00007f6253adf18b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4618b)
 #5 0x00007f6253abe859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x25859)
 #6 0x00000000071209cc llvm::report_bad_alloc_error(char const*, bool) (/install/bin/clang-11.bolt+0x71209cc)
 #7 0x0000000006296dea llvm::SmallVectorBase<unsigned long>::grow_pod(void*, unsigned long, unsigned long) (.cold.0) (/install/bin/clang-11.bolt+0x6296dea)
 #8 0x0000000007627da4 llvm::GetShadowBytes(llvm::SmallVectorImpl<llvm::ASanStackVariableDescription> const&, llvm::ASanStackFrameLayout const&) (/install/bin/clang-11.bolt+0x7627da4)
 #9 0x000000000761c244 (anonymous namespace)::FunctionStackPoisoner::runOnFunction() (/install/bin/clang-11.bolt+0x761c244)
#10 0x0000000007616d70 (anonymous namespace)::AddressSanitizer::instrumentFunction(llvm::Function&, llvm::TargetLibraryInfo const*) (/install/bin/clang-11.bolt+0x7616d70)
#11 0x00000000076255bf (anonymous namespace)::AddressSanitizerLegacyPass::runOnFunction(llvm::Function&) (/install/bin/clang-11.bolt+0x76255bf)
#12 0x000000000560b183 llvm::FPPassManager::runOnFunction(llvm::Function&) (/install/bin/clang-11.bolt+0x560b183)
#13 0x000000000560aaef llvm::FPPassManager::runOnModule(llvm::Module&) (/install/bin/clang-11.bolt+0x560aaef)
#14 0x0000000005ace172 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/install/bin/clang-11.bolt+0x5ace172)
#15 0x0000000005a68104 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/install/bin/clang-11.bolt+0x5a68104)
#16 0x0000000005a668a8 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/install/bin/clang-11.bolt+0x5a668a8)
#17 0x000000000593dec1 clang::ParseAST(clang::Sema&, bool, bool) (/install/bin/clang-11.bolt+0x593dec1)
#18 0x0000000005c53e71 clang::FrontendAction::Execute() (/install/bin/clang-11.bolt+0x5c53e71)
#19 0x0000000005c53d7b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/install/bin/clang-11.bolt+0x5c53d7b)
#20 0x0000000005bf899b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/install/bin/clang-11.bolt+0x5bf899b)
#21 0x0000000005bf825b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/install/bin/clang-11.bolt+0x5bf825b)
#22 0x0000000005bf7665 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/install/bin/clang-11.bolt+0x5bf7665)
#23 0x00000000067536e6 main.cold.0 (/install/bin/clang-11.bolt+0x67536e6)
#24 0x00007f6253ac00b3 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b3)
#25 0x0000000005bc6dee _start (/install/bin/clang-11.bolt+0x5bc6dee)
clang-11: error: unable to execute command: Aborted (core dumped)
clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-11: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-11: note: diagnostic msg: /tmp/prog_joined-c43241.cpp
clang-11: note: diagnostic msg: /tmp/prog_joined-c43241.sh
clang-11: note: diagnostic msg:
********************
nunoplopes commented 2 years ago

Dup of https://github.com/llvm/llvm-project/issues/54825

llvmbot commented 2 years ago

@llvm/issue-subscribers-clang-frontend

efriedma-quic commented 2 years ago

Not a dup. (Not all big arrays are the same; we have to look at the stack trace.)

Reduced: build the following with -fsanitize=address.

void z(int*);
void zz() { 
    int dp[100005][100005];
    z(&dp[0][0]);
}

This is almost certainly going to overflow the stack at runtime, but that doesn't mean the compiler should crash.

fhahn commented 2 years ago

IR reproducer with -passes=asan-module: https://llvm.godbolt.org/z/qEGxTxT1M

; ModuleID = '<source>'
source_filename = "<source>"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress noinline optnone sanitize_address uwtable
define dso_local void @_Z2zzv() #0 !dbg !10 {
entry:
  %dp = alloca [100005 x [100005 x i32]], align 16
  call void @llvm.lifetime.start.p0(i64 40004000100, ptr %dp) #4, !dbg !15
  call void @llvm.dbg.declare(metadata ptr %dp, metadata !16, metadata !DIExpression()), !dbg !21
  %arrayidx = getelementptr inbounds [100005 x [100005 x i32]], ptr %dp, i64 0, i64 0, !dbg !22
  %arrayidx1 = getelementptr inbounds [100005 x i32], ptr %arrayidx, i64 0, i64 0, !dbg !22
  call void @_Z1zPi(ptr noundef %arrayidx1), !dbg !23
  call void @llvm.lifetime.end.p0(i64 40004000100, ptr %dp) #4, !dbg !24
  ret void, !dbg !24
}

; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #2

declare void @_Z1zPi(ptr noundef) #3

; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress noinline optnone sanitize_address uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { argmemonly nocallback nofree nosync nounwind willreturn }
attributes #2 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
attributes #3 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 15.0.0 (https://github.com/llvm/llvm-project.git c261f78d05deee305166e5f8c91e347b8401dfa4)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "<source>", directory: "/app", checksumkind: CSK_MD5, checksum: "639fdf3394c480ff23b62f52ecc69cc2")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !{i32 7, !"PIC Level", i32 2}
!6 = !{i32 7, !"PIE Level", i32 2}
!7 = !{i32 7, !"uwtable", i32 2}
!8 = !{i32 7, !"frame-pointer", i32 2}
!9 = !{!"clang version 15.0.0 (https://github.com/llvm/llvm-project.git c261f78d05deee305166e5f8c91e347b8401dfa4)"}
!10 = distinct !DISubprogram(name: "zz", linkageName: "_Z2zzv", scope: !11, file: !11, line: 2, type: !12, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
!11 = !DIFile(filename: "example.cpp", directory: "/app", checksumkind: CSK_MD5, checksum: "639fdf3394c480ff23b62f52ecc69cc2")
!12 = !DISubroutineType(types: !13)
!13 = !{null}
!14 = !{}
!15 = !DILocation(line: 3, column: 5, scope: !10)
!16 = !DILocalVariable(name: "dp", scope: !10, file: !11, line: 3, type: !17)
!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, size: 320032000800, elements: !19)
!18 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!19 = !{!20, !20}
!20 = !DISubrange(count: 100005)
!21 = !DILocation(line: 3, column: 9, scope: !10)
!22 = !DILocation(line: 4, column: 8, scope: !10)
!23 = !DILocation(line: 4, column: 5, scope: !10)
!24 = !DILocation(line: 5, column: 1, scope: !10)