From: Artem Dergachev Date: Wed, 28 Aug 2019 18:44:35 +0000 (+0000) Subject: [analyzer] pr43036: Fix support for operator 'sizeof...'. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c07bc247e69b4603aed46156ad2b4744c16ad90b;p=clang [analyzer] pr43036: Fix support for operator 'sizeof...'. It was known to be a compile-time constant so it wasn't evaluated during symbolic execution, but it wasn't evaluated as a compile-time constant either. Differential Revision: https://reviews.llvm.org/D66565 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370245 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/StaticAnalyzer/Core/Environment.cpp b/lib/StaticAnalyzer/Core/Environment.cpp index 551c89b04d..1ccf4c6104 100644 --- a/lib/StaticAnalyzer/Core/Environment.cpp +++ b/lib/StaticAnalyzer/Core/Environment.cpp @@ -108,6 +108,7 @@ SVal Environment::getSVal(const EnvironmentEntry &Entry, case Stmt::ObjCStringLiteralClass: case Stmt::StringLiteralClass: case Stmt::TypeTraitExprClass: + case Stmt::SizeOfPackExprClass: // Known constants; defer to SValBuilder. return svalBuilder.getConstantVal(cast(S)).getValue(); diff --git a/test/Analysis/sizeofpack.cpp b/test/Analysis/sizeofpack.cpp new file mode 100644 index 0000000000..44c3bba3a8 --- /dev/null +++ b/test/Analysis/sizeofpack.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection \ +// RUN: -verify %s + +typedef __typeof(sizeof(int)) size_t; + +void clang_analyzer_eval(bool); + +template size_t foo() { + return sizeof...(N); +} + +void bar() { + clang_analyzer_eval(foo<>() == 0); // expected-warning{{TRUE}} + clang_analyzer_eval(foo<1, 2, 3>() == 3); // expected-warning{{TRUE}} +}