1 // RUN: %clang_analyze_cc1 -triple x86_64-apple-darwin10 -disable-free -verify %s \
2 // RUN: -analyzer-checker=core,deadcode,alpha.security.taint,debug.TaintTest,debug.ExprInspection
4 void clang_analyzer_eval(int);
6 // Note, we do need to include headers here, since the analyzer checks if the function declaration is located in a system header.
7 #include "Inputs/system-header-simulator.h"
9 // Test that system header does not invalidate the internal global.
10 int size_rdar9373039
= 1;
11 int rdar9373039(void) {
15 for (int i
= 0 ; i
< size_rdar9373039
; ++i
)
18 // strlen doesn't invalidate the value of 'size_rdar9373039'.
19 int extra
= (2 + strlen ("Clang") + ((4 - ((unsigned int) (2 + strlen ("Clang")) % 4)) % 4)) + (2 + strlen ("1.0") + ((4 - ((unsigned int) (2 + strlen ("1.0")) % 4)) % 4));
21 for (int i
= 0 ; i
< size_rdar9373039
; ++i
)
27 // Test stdin does not get invalidated by a system call nor by an internal call.
31 fscanf(stdin
, "%d", &i
);
33 int m
= i
; // expected-warning + {{tainted}}
34 fscanf(stdin
, "%d", &i
);
35 int j
= i
; // expected-warning + {{tainted}}
36 return m
+ j
; // expected-warning + {{tainted}}
39 // Test that const integer does not get invalidated.
41 int constIntGlob(void) {
44 return 3 / *m
; // expected-warning {{Division by zero}}
48 int constIntGlobExtern(void) {
51 return 5 / y
; // expected-warning {{Division by zero}}
56 static void * const ptr
= 0;
57 void constPtrGlob(void) {
58 clang_analyzer_eval(ptr
== 0); // expected-warning{{TRUE}}
60 clang_analyzer_eval(ptr
== 0); // expected-warning{{TRUE}}
63 static const int x2
= x
;
64 void constIntGlob2(void) {
65 clang_analyzer_eval(x2
== 0); // expected-warning{{TRUE}}
67 clang_analyzer_eval(x2
== 0); // expected-warning{{TRUE}}
70 void testAnalyzerEvalIsPure(void) {
71 extern int someGlobal
;
72 if (someGlobal
== 0) {
73 clang_analyzer_eval(someGlobal
== 0); // expected-warning{{TRUE}}
74 clang_analyzer_eval(someGlobal
== 0); // expected-warning{{TRUE}}
78 // Test that static variables with initializers do not get reinitialized on
82 void Function1(void) {
89 int m
= *p
; // no-warning: p is never null.
93 void Function2(void) {
97 void SetToNonZero(void) {
99 clang_analyzer_eval(g
== 5); // expected-warning{{TRUE}}