llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang: clang/AST/Expr.h: Assertion `Arg < NumArgs && "Arg access out of range!"' failed.

Open markus-oberhumer opened this issue 10 years ago • 6 comments

Bugzilla Link 30616
Resolution FIXED
Resolved on Oct 16, 2016 12:29
Version 3.9
OS Linux
CC @devincoughlin

Extended Description

The following simple C program triggers an assertion with scan-build-3.9:

char alloca(); int main(int ac, char *av[]) { alloca(); if (ac > 1000) { return *av[0]; } return 0; }

Assertion failed:

clang-3.9: /home/hosts/cc-i386-linux/build/llvm/llvm-3.9-git/src/llvm/tools/clang/include/clang/AST/Expr.h:2222: const clang::Expr *clang::CallExpr::getArg(unsigned int) const: Assertion `Arg < NumArgs && "Arg access out of range!"' failed.

Command line:

  1.  Program arguments: /opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name scan_build_crash.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/../lib/clang/3.9.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/mfx/pp/bugs/llvm-bugs/scan-build-crash -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-display-progress -analyzer-output=html -o /tmp/scan-build-2016-10-05-103146-24994-1 -x c scan_build_crash.c 
    

Stack trace:

[...] #​5 0x00002b2a9bf9b227 __assert_fail_base (/lib64/libc.so.6+0x2d227) #​6 0x00002b2a9bf9b2d2 (/lib64/libc.so.6+0x2d2d2) #​7 0x0000000001308a6a void clang::ento::check::PostStmtclang::CallExpr::_checkStmt<(anonymous namespace)::MallocChecker>(void*, clang::Stmt const*, clang::ento::CheckerContext&) (/opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/clang-3.9+0x1308a6a) #​8 0x00000000013d8528 clang::ento::CheckerManager::runCheckersForStmt(bool, clang::ento::ExplodedNodeSet&, clang::ento::ExplodedNodeSet const&, clang::Stmt const*, clang::ento::ExprEngine&, bool) (/opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/clang-3.9+0x13d8528) #​9 0x000000000140afa4 clang::ento::ExprEngine::VisitCallExpr(clang::CallExpr const*, clang::ento::ExplodedNode*, clang::ento::ExplodedNodeSet&) (/opt/cc-i386-linux/llvm/llvm-3.9/clang-3.9.0-20160902-pristine/bin/clang-3.9+0x140afa4 [...]

markus-oberhumer avatar Oct 05 '16 10:10 markus-oberhumer

Fixed this (and a similar issue with kmalloc()) in r284335.

devincoughlin avatar Oct 16 '16 19:10 devincoughlin

FYI, the above code was generated by CMake during one of its tests - of course no sane person would write something like this ;-)

markus-oberhumer avatar Oct 05 '16 18:10 markus-oberhumer

This is tracked internally as rdar://problem/28631974

devincoughlin avatar Oct 05 '16 17:10 devincoughlin

Although this does trigger a warning:

test_alloca.c:1:6: warning: incompatible redeclaration of library function 'alloca' [-Wincompatible-library-redeclaration]

devincoughlin avatar Oct 05 '16 17:10 devincoughlin

Thanks for the report! It looks like the MallocChecker isn't robust against declarations of alloca() that don't match the arity of the standard alloca.

devincoughlin avatar Oct 05 '16 17:10 devincoughlin

assigned to @tkremenek

markus-oberhumer avatar Oct 05 '16 10:10 markus-oberhumer