[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / cert / env31-c.c
blobfeaa2baefea7c721da97bd830aeaadc872ad28f6
1 // RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s \
2 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
3 // RUN: -verify=putenv,common \
4 // RUN: -DENV_INVALIDATING_CALL="putenv(\"X=Y\")"
5 //
6 // RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s \
7 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
8 // RUN: -verify=putenvs,common \
9 // RUN: -DENV_INVALIDATING_CALL="_putenv_s(\"X\", \"Y\")"
11 // RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s \
12 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
13 // RUN: -verify=wputenvs,common \
14 // RUN: -DENV_INVALIDATING_CALL="_wputenv_s(\"X\", \"Y\")"
16 // RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s \
17 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
18 // RUN: -verify=setenv,common \
19 // RUN: -DENV_INVALIDATING_CALL="setenv(\"X\", \"Y\", 0)"
21 // RUN: %clang_analyze_cc1 -analyzer-output=text -Wno-unused %s \
22 // RUN: -analyzer-checker=core,alpha.security.cert.env.InvalidPtr \
23 // RUN: -verify=unsetenv,common \
24 // RUN: -DENV_INVALIDATING_CALL="unsetenv(\"X\")"
26 typedef int errno_t;
27 typedef char wchar_t;
29 int putenv(char *string);
30 errno_t _putenv_s(const char *varname, const char *value_string);
31 errno_t _wputenv_s(const wchar_t *varname, const wchar_t *value_string);
32 int setenv(const char *name, const char *value, int overwrite);
33 int unsetenv(const char *name);
35 void fn_without_body(char **e);
36 void fn_with_body(char **e) {}
38 void call_env_invalidating_fn(char **e) {
39 ENV_INVALIDATING_CALL;
40 // putenv-note@-1 5 {{'putenv' call may invalidate the environment parameter of 'main'}}
41 // putenvs-note@-2 5 {{'_putenv_s' call may invalidate the environment parameter of 'main'}}
42 // wputenvs-note@-3 5 {{'_wputenv_s' call may invalidate the environment parameter of 'main'}}
43 // setenv-note@-4 5 {{'setenv' call may invalidate the environment parameter of 'main'}}
44 // unsetenv-note@-5 5 {{'unsetenv' call may invalidate the environment parameter of 'main'}}
46 *e;
47 // common-warning@-1 {{dereferencing an invalid pointer}}
48 // common-note@-2 {{dereferencing an invalid pointer}}
51 int main(int argc, char *argv[], char *envp[]) {
52 char **e = envp;
53 *e; // no-warning
54 e[0]; // no-warning
55 *envp; // no-warning
56 call_env_invalidating_fn(e);
57 // common-note@-1 5 {{Calling 'call_env_invalidating_fn'}}
58 // common-note@-2 4 {{Returning from 'call_env_invalidating_fn'}}
60 *e;
61 // common-warning@-1 {{dereferencing an invalid pointer}}
62 // common-note@-2 {{dereferencing an invalid pointer}}
64 *envp;
65 // common-warning@-1 2 {{dereferencing an invalid pointer}}
66 // common-note@-2 2 {{dereferencing an invalid pointer}}
68 fn_without_body(e);
69 // common-warning@-1 {{use of invalidated pointer 'e' in a function call}}
70 // common-note@-2 {{use of invalidated pointer 'e' in a function call}}
72 fn_with_body(e); // no-warning