From 26fb0e81aa7b3d31410b1311033c568070cecd7d Mon Sep 17 00:00:00 2001 From: Artem Dergachev <artem.dergachev@gmail.com> Date: Wed, 7 Dec 2016 16:12:26 +0000 Subject: [PATCH] [analyzer] pr31226: Disable CastSizeChecker in C++ because it's not quite ready. Avoids a crash and a related false positive. Investigation by Daniel Krupp! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288914 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Checkers/CastSizeChecker.cpp | 7 +++++- test/Analysis/malloc.cpp | 23 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp b/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp index 2337400750c..3e178152d92 100644 --- a/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/CastSizeChecker.cpp @@ -140,5 +140,10 @@ void CastSizeChecker::checkPreStmt(const CastExpr *CE,CheckerContext &C) const { } void ento::registerCastSizeChecker(CheckerManager &mgr) { - mgr.registerChecker<CastSizeChecker>(); + // PR31226: C++ is more complicated than what this checker currently supports. + // There are derived-to-base casts, there are different rules for 0-size + // structures, no flexible arrays, etc. + // FIXME: Disabled on C++ for now. + if (!mgr.getLangOpts().CPlusPlus) + mgr.registerChecker<CastSizeChecker>(); } diff --git a/test/Analysis/malloc.cpp b/test/Analysis/malloc.cpp index 75d06d66c2c..f24ccf58dc3 100644 --- a/test/Analysis/malloc.cpp +++ b/test/Analysis/malloc.cpp @@ -1,4 +1,5 @@ -// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc -analyzer-store=region -verify %s +// RUN: %clang_cc1 -w -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -verify %s +// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -w -analyze -analyzer-checker=core,alpha.deadcode.UnreachableCode,alpha.core.CastSize,unix.Malloc,cplusplus.NewDelete -analyzer-store=region -verify %s typedef __typeof(sizeof(int)) size_t; void *malloc(size_t); @@ -105,4 +106,22 @@ void appendWrapperNested(char *getterName) { void fooNested(const char* name) { char* getterName = strdup(name); appendWrapperNested(getterName); // no-warning -} \ No newline at end of file +} + +namespace PR31226 { + struct b2 { + int f; + }; + + struct b1 : virtual b2 { + void m(); + }; + + struct d : b1, b2 { + }; + + void f() { + d *p = new d(); + p->m(); // no-crash // no-warning + } +} -- GitLab