Analyzer crash initializing field with string literal
| Bugzilla Link | 31592 |
| Resolution | FIXED |
| Resolved on | Jan 16, 2017 10:43 |
| Version | unspecified |
| OS | All |
| CC | @haoNoQ |
Extended Description
As reported by Miklos Vajna on cfe-dev, the following code causes an assertion failure in the static analyzer:
$ cat field_initializer.cpp
struct S;
template <typename T> struct C {
public:
C(const S &left_, const T &right_) : left(left_), right(right_) {}
private:
const S &left;
const T &right;
};
template <typename T, int N>
inline T operator+(const T &left, const char (&right)[N]) {
return C<const char[N]>(left, right);
}
struct S {
template <typename T> S(T &) {}
template <typename T> S(const C<T> &) {}
};
S f() { return S("{") + "}"; }
$ clang -cc1 -analyze -analyzer-checker=core field_initializer.cpp
'Assume' not implemented for this NonLoc
UNREACHABLE executed at /Volumes/Data/Clangs/OpenSourceGit/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:126!
0 clang 0x0000000105995d46 llvm::sys::RunSignalHandlers() + 86
1 clang 0x0000000105997429 SignalHandler(int) + 361
2 libsystem_platform.dylib 0x00007fff8b56ebba _sigtramp + 26
Stack dump:
0. Program arguments: ../build/clang-ninja/bin/clang -cc1 -analyze -analyzer-checker=core field_initializer.cpp
1. <eof> parser at end of file
2. While analyzing stack:
#0 C(const S &left_, char const &right_[2]) : left(left_), right(right_) {}
llvm/llvm-project#373 template<> inline S operator+<S, 2>(const S &left, const char (&right)[2])
llvm/llvm-project#374 S f()
3. field_initializer.cpp:5:52: Error evaluating initializer
Abort trap: 6
changed the description
All fixes landed in 4.0, both crashes should be fixed now.
A more careful attempt in https://reviews.llvm.org/D28602
r291754 avoids the crash, but not the problem. Looking into this further.
Alex: Your test looks like it is crashing from the same root cause -- no need to file a new bug.
Devin, can you confirm that my test case fails due to the same root cause or should it be a separate bug?
Maybe the same issue, this is happening quite frequently in our setup:
$ cat repro-sa.cc
template <typename _Value> struct A {
_Value &_M_value;
A(_Value &p1) : _M_value(p1) {}
};
template <typename _Value> A<_Value> __iter_equals_val(_Value &p1) {
return p1;
}
template <typename _InputIterator, typename _Tp>
void find(_InputIterator, _InputIterator, _Tp &p3) {
__iter_equals_val(p3);
}
int a;
void f() { find(a, 0, ""); }
$ ~/work/llvm.git-build/bin/clang --analyze repro-sa.cc [109/30776]
'Assume' not implemented for this NonLoc
UNREACHABLE executed at tools/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:126!
#​0 0x0000000001aad0b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) lib/Support/Unix/Signals.inc:402:13
#​1 0x0000000001aad716 bool __gnu_cxx::operator!=<std::pair<void (*)(void*), void*>*, std::vector<std::pair<void (*)(void*), void*>, std::allocator<std::pair<vo
id (*)(void*), void*> > > >(__gnu_cxx::__normal_iterator<std::pair<void (*)(void*), void*>*, std::vector<std::pair<void (*)(void*), void*>, std::allocator<std:
:pair<void (*)(void*), void*> > > > const&, __gnu_cxx::__normal_iterator<std::pair<void (*)(void*), void*>*, std::vector<std::pair<void (*)(void*), void*>, std
::allocator<std::pair<void (*)(void*), void*> > > > const&) /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/stl_iterator.h:825:27
#​2 0x0000000001aad716 llvm::sys::RunSignalHandlers() lib/Support/Signals.cpp:44:0
#​3 0x0000000001aad716 SignalHandler(int) lib/Support/Unix/Signals.inc:246:0
#​4 0x00007f1d43cf7330 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#​5 0x00007f1d428eac37 gsignal /build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#​6 0x00007f1d428ee028 abort /build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#​7 0x0000000001a644fd llvm::raw_ostream::operator<<(llvm::StringRef) include/llvm/Support/raw_ostream.h:175:7
#​8 0x0000000001a644fd llvm::raw_ostream::operator<<(char const*) include/llvm/Support/raw_ostream.h:185:0
#​9 0x0000000001a644fd llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) lib/Support/ErrorHandling.cpp:117:0
#​10 0x00000000031bb549 clang::ento::nonloc::ConcreteInt clang::ento::SVal::castAs<clang::ento::nonloc::ConcreteInt>() const tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h:77:5
#​11 0x00000000031bb549 clang::ento::SimpleConstraintManager::assumeAux(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) tools/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:180:0
#​12 0x00000000031baf59 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::swap(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>&) include/llvm/ADT/IntrusiveRefCntPtr.h:172:20
#​13 0x00000000031baf59 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::operator=(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>) include/llvm/ADT/IntrusiveRefCntPtr.h:160:0
#​14 0x00000000031baf59 clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::NonLoc, bool) tools/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:89:0
#​15 0x00000000031bae76 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::release() include/llvm/ADT/IntrusiveRefCntPtr.h:190:9
#​16 0x00000000031bae76 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::~IntrusiveRefCntPtr() include/llvm/ADT/IntrusiveRefCntPtr.h:164:0
#​17 0x00000000031bae76 clang::ento::SimpleConstraintManager::assume(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::DefinedSVal, bool)
tools/clang/lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp:84:0
#​18 0x0000000002f6b523 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::release() include/llvm/ADT/IntrusiveRefCntPtr.h:190:9
#​19 0x0000000002f6b523 llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::~IntrusiveRefCntPtr() include/llvm/ADT/IntrusiveRefCntPtr.h:164:0
#​20 0x0000000002f6b523 clang::ento::ConstraintManager::assumeDual(llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>, clang::ento::DefinedSVal) tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ConstraintManager.h:76:0
#​21 0x0000000002f85f7b llvm::IntrusiveRefCntPtrInfo<clang::ento::ProgramState const>::release(clang::ento::ProgramState const*) tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState_Fwd.h:31:7
#​22 0x0000000002f85f7b llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::release() include/llvm/ADT/IntrusiveRefCntPtr.h:191:0
#​23 0x0000000002f85f7b llvm::IntrusiveRefCntPtr<clang::ento::ProgramState const>::~IntrusiveRefCntPtr() include/llvm/ADT/IntrusiveRefCntPtr.h:164:0
#​24 0x0000000002f85f7b clang::ento::ProgramState::assume(clang::ento::DefinedOrUnknownSVal) const tools/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h:655:0
#​25 0x0000000002f85f7b (anonymous namespace)::DereferenceChecker::checkBind(clang::ento::SVal, clang::ento::SVal, clang::Stmt const*, clang::ento::CheckerContext&) const tools/clang/lib/StaticAnalyzer/Checkers/DereferenceChecker.cpp:259:0
...
Stack dump:
0. Program arguments: ~/work/llvm.git-build/bin/clang-3.8 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -main-file-name repro-sa.cc -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -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 ~/work/llvm.git-build/bin/../lib/clang/4.0.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/x86_64-linux-gnu/c++/4.8 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/backward -internal-isystem /usr/local/include -internal-isystem ~/work/llvm.git-build/bin/../lib/clang/4.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 159 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o repro-sa.plist -x c++ repro-sa.cc
1. <eof> parser at end of file
2. While analyzing stack:
#​0 A(char const &p1[1]) : _M_value(p1) {}
#​1 template<> A<char const[1]> __iter_equals_val<char const[1]>(char const &p1[1])
#​2 template<> void find<int, char const[1]>(int, int, char const &p3[1])
#​3 void f()
3. repro-sa.cc:3:19: Error evaluating initializer
clang-3.8: error: unable to execute command: Aborted (core dumped)
clang-3.8: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 4.0.0 (trunk 290887) (llvm/trunk 290872)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: ~/work/llvm.git-build/bin
clang-3.8: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-3.8: note: diagnostic msg:
This is tracked internally by rdar://problem/29938368
Note: Miklos thinks this was introduced by r289618.
Here is a simplified reproducer:
$ cat field_initializer_reduced.cpp
struct C { C() : f("}") { }
const char(&f)[2]; };
assigned to @devincoughlin