aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorImmad Mir <mirimmad@outlook.com>2022-07-27 19:16:36 +0530
committerImmad Mir <mirimmad@outlook.com>2022-07-27 19:16:43 +0530
commit0f82c0ea8d86ee3bb404c460a04ff2ccfb56d2a0 (patch)
tree9b3ff23609408512da617ee3bb23e5311f788298 /gcc/testsuite
parentc2481a6bb70a23a9e279c4f23cf76671afca2145 (diff)
downloadgcc-0f82c0ea8d86ee3bb404c460a04ff2ccfb56d2a0.zip
gcc-0f82c0ea8d86ee3bb404c460a04ff2ccfb56d2a0.tar.gz
gcc-0f82c0ea8d86ee3bb404c460a04ff2ccfb56d2a0.tar.bz2
analyzer: add get_meaning_for_state_change vfunc to fd_diagnostic in sm-fd.cc [PR106286]
This patch adds get_meaning_for_state_change vfunc to fd_diagnostic in sm-fd.cc which could be used by SARIF output. Lightly tested on x86_64 Linux. gcc/analyzer/ChangeLog: PR analyzer/106286 * sm-fd.cc: (fd_diagnostic::get_meaning_for_state_change): New. gcc/testsuite/ChangeLog: PR analyzer/106286 * gcc.dg/analyzer/fd-meaning.c: New test. Signed-off-by: Immad Mir <mirimmad@outlook.com>
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/gcc.dg/analyzer/fd-meaning.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/analyzer/fd-meaning.c b/gcc/testsuite/gcc.dg/analyzer/fd-meaning.c
new file mode 100644
index 0000000..6a9ec92
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/fd-meaning.c
@@ -0,0 +1,37 @@
+ /* { dg-additional-options "-fanalyzer-verbose-state-changes" } */
+int open(const char *, int mode);
+void close(int fd);
+
+#define O_RDONLY 0
+#define O_WRONLY 1
+#define O_RDWR 2
+
+void test_1 (const char* path)
+{
+ int fd = open (path, O_RDWR); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */
+ if (fd != -1)
+ {
+ close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */
+ close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */
+ }
+}
+
+void test_2 (const char* path)
+{
+ int fd = open (path, O_RDONLY); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */
+ if (fd != -1)
+ {
+ close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */
+ close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */
+ }
+}
+
+void test_3 (const char* path)
+{
+ int fd = open (path, O_WRONLY); /* { dg-message "meaning: \\{verb: 'acquire', noun: 'resource'\\}" } */
+ if (fd != -1)
+ {
+ close(fd); /* { dg-message "meaning: \\{verb: 'release', noun: 'resource'\\}" } */
+ close(fd); /* { dg-warning "double 'close' of file descriptor 'fd' \\\[CWE-1341\\\]" } */
+ }
+} \ No newline at end of file