diff options
-rw-r--r-- | lib/StaticAnalyzer/Core/CheckerContext.cpp | 8 | ||||
-rw-r--r-- | test/Analysis/cstring-syntax-cxx.cpp | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/StaticAnalyzer/Core/CheckerContext.cpp b/lib/StaticAnalyzer/Core/CheckerContext.cpp index ccf415f0c7..6ad4162b8f 100644 --- a/lib/StaticAnalyzer/Core/CheckerContext.cpp +++ b/lib/StaticAnalyzer/Core/CheckerContext.cpp @@ -53,7 +53,13 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD, return true; } - StringRef FName = FD->getIdentifier()->getName(); + const IdentifierInfo *II = FD->getIdentifier(); + // If this is a special C++ name without IdentifierInfo, it can't be a + // C library function. + if (!II) + return false; + + StringRef FName = II->getName(); if (FName.startswith("__inline")) return (FName.find(Name) != StringRef::npos); diff --git a/test/Analysis/cstring-syntax-cxx.cpp b/test/Analysis/cstring-syntax-cxx.cpp new file mode 100644 index 0000000000..af8b4d7824 --- /dev/null +++ b/test/Analysis/cstring-syntax-cxx.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=experimental.unix.cstring.BadSizeArg -analyzer-store=region -verify %s + +// Ensure we don't crash on C++ declarations with special names. +struct X { + X(int i): i(i) {} + int i; +}; + +X operator+(X a, X b) { + return X(a.i + b.i); +} + +void test(X a, X b) { + X c = a + b; +} + |