Index: clang/test/Analysis/PR24184.cpp =================================================================== --- clang/test/Analysis/PR24184.cpp +++ clang/test/Analysis/PR24184.cpp @@ -1,6 +1,8 @@ -// UNSUPPORTED: z3 -// RUN: %clang_analyze_cc1 -w -fcxx-exceptions -analyzer-checker=core -analyzer-checker=alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 64 -verify %s -// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -analyzer-checker=cplusplus -fcxx-exceptions -analyzer-checker alpha.core.PointerArithm,alpha.core.CastToStruct -analyzer-max-loop 63 -verify %s +// RUN: %clang_analyze_cc1_range -w -fcxx-exceptions -analyzer-max-loop 64 -verify %s \ +// RUN: -analyzer-checker=core,alpha.core.PointerArithm,alpha.core.CastToStruct +// +// RUN: %clang_analyze_cc1_range -w -fcxx-exceptions -analyzer-max-loop 63 -verify %s \ +// RUN: -analyzer-checker=core,alpha.core.PointerArithm,alpha.core.CastToStruct,cplusplus // These tests used to hit an assertion in the bug report. Test case from http://llvm.org/PR24184. typedef struct { Index: clang/test/Analysis/analyzer_test.py =================================================================== --- clang/test/Analysis/analyzer_test.py +++ clang/test/Analysis/analyzer_test.py @@ -4,9 +4,9 @@ # Custom format class for static analyzer tests class AnalyzerTest(lit.formats.ShTest): - def __init__(self, execute_external, use_z3_solver=False): + def __init__(self, execute_external, recheck_with_z3_solver=False): super(AnalyzerTest, self).__init__(execute_external) - self.use_z3_solver = use_z3_solver + self.recheck_with_z3_solver = recheck_with_z3_solver def execute(self, test, litConfig): results = [] @@ -15,17 +15,16 @@ saved_test = test lit.TestRunner.parseIntegratedTestScript(test) - if 'z3' not in test.requires: - results.append(self.executeWithAnalyzeSubstitution( - saved_test, litConfig, '-analyzer-constraints=range')) + results.append(self.executeWithConstraintManagerSubstitution( + saved_test, litConfig, '-analyzer-constraints=range')) - if results[-1].code == lit.Test.FAIL: - return results[-1] + if results[-1].code == lit.Test.FAIL: + return results[-1] - # If z3 backend available, add an additional run line for it - if self.use_z3_solver == '1': + # If we want to rerun the test with the Z3 solver, add an additional run line for it + if self.recheck_with_z3_solver == '1': assert(test.config.clang_staticanalyzer_z3 == '1') - results.append(self.executeWithAnalyzeSubstitution( + results.append(self.executeWithConstraintManagerSubstitution( saved_test, litConfig, '-analyzer-constraints=z3 -DANALYZER_CM_Z3')) # Combine all result outputs into the last element @@ -38,9 +37,9 @@ return lit.Test.Result(lit.Test.UNSUPPORTED, "Test requires the following unavailable features: z3") - def executeWithAnalyzeSubstitution(self, test, litConfig, substitution): + def executeWithConstraintManagerSubstitution(self, test, litConfig, substitution): saved_substitutions = list(test.config.substitutions) - test.config.substitutions.append(('%analyze', substitution)) + test.config.substitutions.append(('%constraint_manager', substitution)) result = lit.TestRunner.executeShTest(test, litConfig, self.execute_external) test.config.substitutions = saved_substitutions Index: clang/test/Analysis/constant-folding.c =================================================================== --- clang/test/Analysis/constant-folding.c +++ clang/test/Analysis/constant-folding.c @@ -1,4 +1,5 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1_range -analyzer-config eagerly-assume=false -verify %s \ +// RUN: -analyzer-checker=core,debug.ExprInspection #define UINT_MAX (~0U) #define INT_MAX (int)(UINT_MAX & (UINT_MAX >> 1)) Index: clang/test/Analysis/dump_egraph.c =================================================================== --- clang/test/Analysis/dump_egraph.c +++ clang/test/Analysis/dump_egraph.c @@ -1,12 +1,12 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core \ -// RUN: -analyzer-dump-egraph=%t.dot %s +// RUN: %clang_analyze_cc1_range -analyzer-checker=core \ +// RUN: -analyzer-dump-egraph=%t.dot %s // RUN: cat %t.dot | FileCheck %s - -// RUN: %clang_analyze_cc1 -analyzer-checker=core \ -// RUN: -analyzer-dump-egraph=%t.dot \ -// RUN: -trim-egraph %s +// +// RUN: %clang_analyze_cc1_range -analyzer-checker=core \ +// RUN: -analyzer-dump-egraph=%t.dot \ +// RUN: -trim-egraph %s // RUN: cat %t.dot | FileCheck %s - +// // REQUIRES: asserts int getJ(); Index: clang/test/Analysis/expr-inspection.c =================================================================== --- clang/test/Analysis/expr-inspection.c +++ clang/test/Analysis/expr-inspection.c @@ -1,7 +1,5 @@ -// RUN: %clang_analyze_cc1 \ -// RUN: -analyzer-checker=debug.ExprInspection \ -// RUN: -verify %s 2>&1 | FileCheck %s - +// RUN: %clang_analyze_cc1_range -analyzer-checker=debug.ExprInspection -verify %s 2>&1 | FileCheck %s +// // Self-tests for the debug.ExprInspection checker. void clang_analyzer_dump(int x); Index: clang/test/Analysis/lit.local.cfg =================================================================== --- clang/test/Analysis/lit.local.cfg +++ clang/test/Analysis/lit.local.cfg @@ -7,7 +7,7 @@ site.addsitedir(os.path.dirname(__file__)) import analyzer_test config.test_format = analyzer_test.AnalyzerTest( - config.test_format.execute_external, config.use_z3_solver) + config.test_format.execute_external, config.recheck_with_z3_solver) # Filtering command used by Clang Analyzer tests (when comparing .plist files # with reference output) Index: clang/test/Analysis/loop-unrolling.cpp =================================================================== --- clang/test/Analysis/loop-unrolling.cpp +++ clang/test/Analysis/loop-unrolling.cpp @@ -1,5 +1,10 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify -std=c++11 -analyzer-config exploration_strategy=unexplored_first_queue %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify -std=c++11 -DDFS=1 %s +// RUN: %clang_analyze_cc1_range -verify=expected,ufq -std=c++11 %s \ +// RUN: -analyzer-checker=core,debug.ExprInspection \ +// RUN: -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=unexplored_first_queue +// +// RUN: %clang_analyze_cc1_range -verify=expected,dfs -std=c++11 %s \ +// RUN: -analyzer-checker=core,debug.ExprInspection \ +// RUN: -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs void clang_analyzer_numTimesReached(); void clang_analyzer_warnIfReached(); @@ -346,11 +351,9 @@ int simple_unknown_bound_loop() { for (int i = 2; i < getNum(); i++) { -#ifdef DFS - clang_analyzer_numTimesReached(); // expected-warning {{16}} -#else - clang_analyzer_numTimesReached(); // expected-warning {{8}} -#endif + clang_analyzer_numTimesReached(); + // dfs-warning@-1 {{16}} + // ufq-warning@-2 {{8}} } return 0; } @@ -368,11 +371,9 @@ int nested_inlined_no_unroll1() { int k; for (int i = 0; i < 9; i++) { -#ifdef DFS - clang_analyzer_numTimesReached(); // expected-warning {{18}} -#else - clang_analyzer_numTimesReached(); // expected-warning {{14}} -#endif + clang_analyzer_numTimesReached(); + // dfs-warning@-1 {{18}} + // ufq-warning@-2 {{14}} k = simple_unknown_bound_loop(); // reevaluation without inlining, splits the state as well } int a = 22 / k; // no-warning Index: clang/test/Analysis/plist-macros.cpp =================================================================== --- clang/test/Analysis/plist-macros.cpp +++ clang/test/Analysis/plist-macros.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -verify %s -// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix -analyzer-output=plist-multi-file %s -o %t.plist +// RUN: %clang_analyze_cc1_range -analyzer-checker=core,unix -verify %s +// RUN: %clang_analyze_cc1_range -analyzer-checker=core,unix -analyzer-output=plist-multi-file %s -o %t.plist // RUN: %normalize_plist <%t.plist | diff -ub %S/Inputs/expected-plists/plist-macros.cpp.plist - Index: clang/test/Analysis/trustnonnullchecker_test.m =================================================================== --- clang/test/Analysis/trustnonnullchecker_test.m +++ clang/test/Analysis/trustnonnullchecker_test.m @@ -1,7 +1,4 @@ -// Temporarily disabling the test, it failes the "system is over-constrained" -// assertion in *non* optimized builds. -// REQUIRES: rdar44992170 -// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-checker=core,nullability,apiModeling,debug.ExprInspection -verify %s +// RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-checker=core,nullability,apiModeling,debug.ExprInspection -verify %s #include "Inputs/system-header-simulator-for-nullability.h" Index: clang/test/Analysis/z3/enabled.c =================================================================== --- clang/test/Analysis/z3/enabled.c +++ /dev/null @@ -1,3 +0,0 @@ -// REQUIRES: z3 -// RUN: echo %clang_analyze_cc1 | FileCheck %s -// CHECK: -analyzer-constraints=z3 Index: clang/test/CMakeLists.txt =================================================================== --- clang/test/CMakeLists.txt +++ clang/test/CMakeLists.txt @@ -106,7 +106,7 @@ endif () set(CLANG_TEST_PARAMS - USE_Z3_SOLVER=0 + RECHECK_WITH_Z3_SOLVER=0 ) if( NOT CLANG_BUILT_STANDALONE ) Index: clang/test/lit.site.cfg.py.in =================================================================== --- clang/test/lit.site.cfg.py.in +++ clang/test/lit.site.cfg.py.in @@ -28,7 +28,7 @@ config.enable_threads = @LLVM_ENABLE_THREADS@ config.host_arch = "@HOST_ARCH@" config.python_executable = "@Python3_EXECUTABLE@" -config.use_z3_solver = lit_config.params.get('USE_Z3_SOLVER', "@USE_Z3_SOLVER@") +config.recheck_with_z3_solver = lit_config.params.get('RECHECK_WITH_Z3_SOLVER', "@RECHECK_WITH_Z3_SOLVER@") config.has_plugins = @LLVM_ENABLE_PLUGINS@ config.clang_vendor_uti = "@CLANG_VENDOR_UTI@" Index: clang/www/analyzer/checker_dev_manual.html =================================================================== --- clang/www/analyzer/checker_dev_manual.html +++ clang/www/analyzer/checker_dev_manual.html @@ -533,6 +533,24 @@
     $ bin/llvm-lit -sv ../llvm/tools/clang/test/Analysis
     
+ Or you can simply use the corresponding ninja target to achieve this: +
+    $ ninja check-clang-analysis
+    
+ + Tests that require the Z3 constraint manager won't run since those would require too much time. + It will require clang to be built with the Z3 though. + You can enable these tests by an explicit llvm-lit parameter: +
+    $ bin/llvm-lit -sv ../llvm/tools/clang/test/Analysis --param RECHECK_WITH_Z3_SOLVER=1
+    
+ + The RECHECK_WITH_Z3_SOLVER parameter lets the testsuite to use both + constraint managers, which are substituted by the %clang_analyze_cc1 + in each RUN line. + Your test can explicitly require a specific constraint manager using either + %clang_analyze_cc1_range or %clang_analyze_cc1_z3 if that won't + work with both of them.

Useful Commands/Debugging Hints

Index: llvm/utils/gn/secondary/clang/test/BUILD.gn =================================================================== --- llvm/utils/gn/secondary/clang/test/BUILD.gn +++ llvm/utils/gn/secondary/clang/test/BUILD.gn @@ -63,7 +63,7 @@ "LLVM_LIT_TOOLS_DIR=", # Intentionally empty, matches cmake build. "LLVM_USE_SANITIZER=", "Python3_EXECUTABLE=$python_path", - "USE_Z3_SOLVER=", + "RECHECK_WITH_Z3_SOLVER=", ] if (clang_enable_arcmt) { Index: llvm/utils/lit/lit/llvm/config.py =================================================================== --- llvm/utils/lit/lit/llvm/config.py +++ llvm/utils/lit/lit/llvm/config.py @@ -409,7 +409,9 @@ builtin_include_dir = self.get_clang_builtin_include_dir(self.config.clang) tool_substitutions = [ ToolSubst('%clang', command=self.config.clang, extra_args=additional_flags), - ToolSubst('%clang_analyze_cc1', command='%clang_cc1', extra_args=['-analyze', '%analyze', '-setup-static-analyzer']+additional_flags), + ToolSubst('%clang_analyze_cc1_range', command='%clang_cc1', extra_args=['-analyze', '-analyzer-constraints=range', '-setup-static-analyzer']+additional_flags), + ToolSubst('%clang_analyze_cc1_z3', command='%clang_cc1', extra_args=['-analyze', '-analyzer-constraints=z3', '-setup-static-analyzer']+additional_flags), + ToolSubst('%clang_analyze_cc1', command='%clang_cc1', extra_args=['-analyze', '%constraint_manager', '-setup-static-analyzer']+additional_flags), ToolSubst('%clang_cc1', command=self.config.clang, extra_args=['-cc1', '-internal-isystem', builtin_include_dir, '-nostdsysteminc']+additional_flags), ToolSubst('%clang_cpp', command=self.config.clang, extra_args=['--driver-mode=cpp']+additional_flags), ToolSubst('%clang_cl', command=self.config.clang, extra_args=['--driver-mode=cl']+additional_flags),